如何在CMake中启用测试构建选项?

时间:2016-06-13 09:39:18

标签: c++ testing makefile cmake

我正在开发一个c ++应用程序,我使用googletest进行测试。我的项目是用CMake构建的,项目树如下所示。

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 

在这种情况下,我如何支持下面的“测试”选项? 'test / * .cc'应该只构建'test'选项。

mkdir build
cd build/
cmake ..
make
make 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)

0 个答案:

没有答案