My folder structure:
Project
|--Component1
|------src/
|----file.c
|------hdr/
|----file.h
|------test/
|---unittests.cpp (tests file.h)
|---CMakeLists.txt (builds Component1UnitTests.a)
CMakeLists.txt (builds Component1.a, includes test/CMakeLists.txt)
|--Component 2
...
CMakeLists.txt
|--Test
|--ProjectTests.cpp (only contains main-function with RUN_ALL_TESTS)
CMakeLists.txt (builds executable "Project" and links Component1.a, Component2.a, builds executable "ProjectTest" and links "Component1UnitTests.a", "Component2UnitTest.a")
The ProjectTests.cpp
looks like this
#include <gtest/gtest.h>
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
The root-level CMakeLists.txt section about ProjectTest
looks like this:
add_executable(ProjectTest ${CMAKE_CURRENT_SOURCE_DIR}/Test/ProjectTests.cpp)
target_link_libraries (ProjecTest PUBLIC "Component1UnitTests" GTest::gtest_main)
The CMakeLists.txt in Project/Component1/
looks like this:
add_library(Component1UnitTests ${CMAKE_CURRENT_SOURCE_DIR}/unittests.cpp)
target_sources(Component1UnitTests PUBLIC ${PROJECT_SOURCES})
target_include_directories(Component1UnitTests PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../hdr)
Unfortunately this doesn’t work. If the resulting ProjectTest
is executed, I get this console output:
[==========] Running 0 tests from 0 test suites.
[==========] 0 tests from 0 test suites ran. (0 ms total)
[ PASSED ] 0 tests.
What am I doing wrong?