使用CMake构建测试,而不使用CTest [英] Building tests with CMake while not using CTest
问题描述
这里是我想做的:
- 键入
make all
- 键入
make test
将构建我的lib(如果需要),gtest然后我的测试 - 如果需要,键入
make check 运行
make test
,然后运行可执行文件
现在我只能成为第一个工作。
我遇到的问题是gtest的条件包含。
Gtest使用CMake是很好的,在理论上我需要做的是包括gt;
现在的结构是:
CMakeLists.txt(这里我添加doc和库的目标)
doc(my doxygen docs)
include )
lib(其中我的编译库去)
src(我的.cpp文件去)
test
CMakeLists.txt(这里我添加了gest和我的测试的目标)
bin(测试可执行文件的位置)
contrib(where gtest is)
src(my tests)
我试图找出如何添加gtest作为 test
-target的依赖项,但不是每次都创建gtest。
我真的很讨厌,并且一点点没有信息有关于学习CMake所以如果有人知道任何深入的教程(免费在网络上),将是真棒。
$ b $窍门是做 add_subdirectory(test EXCLUDE_FROM_ALL)
,然后CMakeList中没有目标.txt将添加到所有目标。 Here is what I want to do:
- Typing
make all
will build my library and the docs for it. - Typing
make test
will build my lib (if necessary), gtest and then my tests - Typing
make check
runsmake test
if needed and then runs the executable
Right now I've only managed to get the first to work. The problem I'm having is the conditional include of gtest.
Gtest uses CMake which is nice, in theory all I need to do is to include the gtest directory with add_subdirectory
but then gtest will always be built.
My structure right now is:
CMakeLists.txt (Here I add targets for doc and the library) doc (my doxygen docs) include (my headers) lib (where my compiled libraries go) src (where my .cpp files go) test CMakeLists.txt (Here I add targets for gest and my tests) bin (where the test executable will go) contrib (where gtest is) src (my tests)
I'm trying to figure out how to add gtest as a dependency to the test
-target but not build gtest every time.
I'm really annoyed and the little to none information there is about learning CMake so if anyone know any in depth tutorials (available freely on the interwebs) that would be awesome.
The trick is to do add_subdirectory(test EXCLUDE_FROM_ALL)
and then none of the targets in that CMakeList.txt will added to the ALL target.
这篇关于使用CMake构建测试,而不使用CTest的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!