【问题标题】:Run ctest from different directory than build directory used by cmake?从与cmake使用的构建目录不同的目录运行ctest?
【发布时间】:2016-07-28 19:03:12
【问题描述】:

我希望能够以与我可以运行 cmake 类似的方式类似

cmake --build <bld_directory>

运行ctest 喜欢

ctest --build &lt;bld_directory&gt;

显然从&lt;bld-directory&gt; 运行ctest 会起作用, 但如果我能告诉ctest 在哪里查找其配置文件以及测试可执行文件的位置,那就太好了。

从文档来看,这不是很清楚(或者我可能没有在正确的地方查看)这是否可能。

如果有人能阐明这是否可能,那就太好了? 非常感谢, 吉里

【问题讨论】:

  • 您可以通过指定命令行选项告诉ctest 在自定义目录中查找测试:ctest --test-dir /path/to/tests。请注意,您必须使用 CMake 3.20 或更高版本才能获得此 CLI 功能。
  • @squareskittles 谢谢,请将其作为答案提交。

标签: cmake ctest


【解决方案1】:

由于 CMake 3.20 ctest 有选项 --test-dir 来实现这一点。

--test-dir <dir> Specify the directory in which to look for tests.

对于早于 3.20 的 CMake:

我无法通过ctest 选项找到方法,但使用链接到 ctest 的规则 make test 是可行的。

在你的build文件夹中cmake生成的Makefile中你可以找到规则:

#Special rule for the target test
test:
    @$(CMAKE_COMMAND) -E cmake_echo_color --switch=$(COLOR) --cyan "Running tests..."
    /usr/bin/ctest --force-new-ctest-process $(ARGS)
.PHONY : test

make 使用-C /path/to/build_directory/ 提供您想要的选项,您可以使用ARGS='your ctest options here' 添加任何ctest 选项

例如,您可以从系统中的任何目录写入:

make test -C /path/to/build_folder ARGS='-R SpecificTestIWantToRun -VV'

cmake --build &lt;bld_directory&gt; --target test -- ARGS="&lt;ctest_args&gt;"

没有make 的另一种方法是在终端中使用括号来创建子shell。这将在不更改当前 shell 的文件夹的情况下执行命令。

(cd $build_folder; ctest -V)

【讨论】:

    猜你喜欢
    • 2013-02-13
    • 2011-08-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-08-02
    • 1970-01-01
    相关资源
    最近更新 更多