0

I'm developing a c++ application and I use googletest for its tests. My project is built with CMake and project tree is like below.

root
 - CMakeLists.txt
 - src/*.cc
 - include/*.h
 - test/
   - CMakeLists.txt # this file is refered by add_subdirectory command in CmakeLists.txt 
   - *.cc # test files with googletest 

In such a case, how do I support 'test' options like below? 'test/*.cc' should be built only 'test' option is available.

mkdir build
cd build/
cmake ..
make
make test

root/test/CMakeLists.txt

 set (CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
 set(GTEST_ROOT ${PROJECT_SOURCE_DIR}/googletest/googletest)
 include_directories(${GTEST_ROOT}/include/)
 link_directories(${GTEST_ROOT}/build/)
 add_executable(mytest ${CMAKE_CURRENT_SOURCE_DIR}/test.cc
 target_link_libraries(mytest gtest pthread)
jef
  • 3,890
  • 10
  • 42
  • 76
  • `include( CTest )` This module will automatically call ` enable_testing()` so you no longer have to do so in your CMake files. It will also add several new targets to your build. look at [CMake/Testing With CTest](https://cmake.org/Wiki/CMake/Testing_With_CTest) and [ctest(1) options](https://cmake.org/cmake/help/v3.0/manual/ctest.1.html) – Mara Black Jun 13 '16 at 10:06
  • Thank you. enable_testing() and add_test(..) are good. – jef Jun 14 '16 at 07:52

0 Answers0