Unit test files don't get included in the CMake project

Viewed 15

I am struggling with figuring out why some files don't get included in the CMake.

So basically the files I have under Project/test/inc doesn't seem to be included in the CMake; I tested by adding random characters and it didn't error out.

Later I realized that even src/unitTest.cpp doesn't get included apparently hence Project/test/inc

The folder hierarchy looks something like:

> Project
  > inc
  > src
  > test
    > inc
    > src
    CMakeLists.txt 
> CMakeLists.txt     

The test/CMakeLists.txt contains:

set(THIS unitTests)
string(TOUPPER DO_BUILD_${THIS} THIS_FLAG)

if (${THIS_FLAG})
  add_executable(
    ${THIS}
    src/unitTest.cpp
  )
  target_include_directories(${THIS} PUBLIC include)
  target_link_libraries(${THIS} PRIVATE Project)
endif()

The Project/CMakeLists.txt contains:

set(THIS Project)

add_library(${THIS}-headers INTERFACE)

target_include_directories(${THIS}-headers INTERFACE include)

add_library(
   ${THIS}
   STATIC
   src/projectFile.cpp
)

target_compile_options(${THIS} PRIVATE -fPIC)

target_include_directories(${THIS} PUBLIC include)

add_subdirectory(test)
0 Answers
Related