带有不需要的引号的cmake包装命令add_custom_command

时间:2017-08-10 18:01:41

标签: cmake

使用cmake 2.8.12.1,我有以下几行:

set(LCOV ~/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/check/root/usr/local/bin/lcov)
separate_arguments(LCOV_PARAMS UNIX_COMMAND "--capture --directory ./CMakeFiles/mylib.dir --output-file coverage.info")
add_custom_command(
    OUTPUT coverage.info
    COMMAND ${LCOV} ${LCOV_PARAMS}
    DEPENDS tests)

当我使用VERBOSE = 1运行make时,我可以看到命令被双引号括起来,当然shell说“没有这样的文件或目录”:

[100%] Generating coverage.info
"~/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/check/root/usr/local/bin/lcov" --capture --directory ./CMakeFiles/mylib.dir --output-file coverage.info
/bin/sh: ~/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/check/root/usr/local/bin/lcov: No such file or directory

当我从命令中删除波浪号时,cmake决定它不再需要再引用它。 CMakeLists.txt中的新行:

#set(LCOV ${JENKINS_TOOL_DIR}/check/root/usr/local/bin/lcov)
set(LCOV /tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/check/root/usr/local/bin/lcov)
separate_arguments(LCOV_PARAMS UNIX_COMMAND "--capture --directory ./CMakeFiles/mylib.dir --output-file coverage.info")
add_custom_command(
    OUTPUT coverage.info
    COMMAND ${LCOV} ${LCOV_PARAMS}
    DEPENDS tests)

结果运行VERBOSE = 1:

[100%] Generating coverage.info
/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/check/root/usr/local/bin/lcov --capture --directory ./CMakeFiles/mylib.dir --output-file coverage.info
make[3]: /tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/check/root/usr/local/bin/lcov: Command not found

我无法弄清楚为什么cmake决定为我添加引号。我试过VERBOSE。我已经尝试将命令字符串放入add_custom_command(避免set()调用)。只要代字号存在,cmake就会更聪明,并用不需要的双引号括起我的整个命令。

如何在不引用字符串的情况下执行包含代字号的命令?

1 个答案:

答案 0 :(得分:2)

现在我已经发布了问题,我找到了解决方案。

The tilde can be replaced with $ENV{HOME}

所以我的命令变为:

set(LCOV $ENV{HOME}/tools/com.cloudbees.jenkins.plugins.customtools.CustomTool/check/root/usr/local/bin/lcov)

这解决了我的问题。