在不使用CTest的情况下使用CMake构建测试

时间:2011-04-10 04:03:04

标签: cmake googletest

这是我想要做的:

  • 键入make all将构建我的库及其文档。
  • 键入make test将构建我的lib(如果需要),gtest然后我的测试
  • 如果需要,键入make check会运行make test,然后运行可执行文件

现在我只是设法让第一个工作。 我遇到的问题是条件包括gtest。

Gtest使用CMake这很好,理论上我需要做的就是将gtest目录包含在add_subdirectory中,但是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 - 目标但不是每次都构建gtest。

我真的很生气,关于学习CMake的信息几乎没有,所以如果有人知道任何深入的教程(可以在互联网上免费获得)那将是非常棒的。

1 个答案:

答案 0 :(得分:6)

诀窍是add_subdirectory(test EXCLUDE_FROM_ALL),然后CMakeList.txt中的任何目标都不会添加到ALL目标。