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)