我的项目中有一个目录树:
/project
/build
/src
main.cpp
student.cpp
/include
student.hpp
/test
main_test.cpp
CMakeLists.txt
CMakeLists.txt
我还有我的 gtest 和 gmock 库:
/home/karol/Google
/gtest
/gmock
/lib
我想知道是否应该将 project/CMakeLists.txt
移动到 src/
目录?
我的目标是在编译二进制文件或单元测试之间做出选择。我想知道 CMakeLists 将如何实现这一目标。
最佳答案
在你的project/CMakeLists.txt
添加:
add_subdirectory (test)
add_custom_target (testing)
add_dependencies (testing main_test)
在你的project/test/CMakeList.txt
添加:
add_executable (main_test EXCLUDE_FROM_ALL main_test.cpp)
现在,如果您只键入 make
将构建二进制文件,但如果您键入 make testing
将构建单元测试。
关于c++ - CMakeLists + gtest,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25563336/