使用 CMake 构建测试而不使用 CTest
这就是我想要做的:
- 输入
make all
将构建我的库及其文档。 - 输入
make test
将构建我的 lib(如果需要)、gtest,然后是我的测试 - 输入
make check
运行make test
如果需要,然后运行可执行
现在我只设法让第一个工作。 我遇到的问题是 gtest 的条件包含。
Gtest 使用 CMake,这很好,理论上我需要做的就是使用 add_subdirectory
包含 gtest 目录,但随后 gtest 将始终被构建。
我现在的结构是:
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)
我试图弄清楚如何将 gtest 添加为 test
-target 的依赖项,但不是每次都构建 gtest。
我真的很恼火,关于学习 CMake 的信息很少甚至没有,所以如果有人知道任何深入的教程(可以在互联网上免费获得)那就太棒了。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
诀窍是执行
add_subdirectory(test EXCLUDE_FROM_ALL)
,然后 CMakeList.txt 中的任何目标都不会添加到 ALL 目标中。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.