I have been looking at examples of CMake to help me build my project with its test folder. The main issue is that I have to include all the test/.cpp* files in my test folder into tests/main.cpp for the tests to run. I think I should include my tests with the add_test
call in my test/CMakeLists.txt. Below is my current CMakeLists file:
enable_testing()
find_package(GTest REQUIRED)
add_executable(test main.cpp)
target_include_directories(test PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/../include)
target_link_libraries(test MainProjectLib ${GTEST_LIBRARIES})
And my main.cpp is the following.
#include "file_in_test1.cpp"
#include "file_in_test2.cpp"
#include <gtest/gtest.h>
int main(int argc, char **argv) {
::testing::InitGoogleTest(&argc, argv);
return RUN_ALL_TESTS();
}
I read some examples that use the standard CTest library for unit testing, but I am using Google Test. I would like to be able to run cmake
, make
, and then ./test
to run all test methods found in file_in_test1.cpp and file_in_test2.cpp without having to directly import those files into test/main.cpp. What additions to CMakeLists.txt do I have to make?