2017-08-10 112 views
0

使用cmake 2.8.12.1,我有以下行:cmake的包裝命令

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) 

當我運行make具有詳細= 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 
/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就更聰明瞭,並且用不需要的雙引號括住了我的整個命令。

如何在不引用字符串的情況下執行包括代字號在內的命令?

回答

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) 

這解決了這個問題對我來說。