首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >用bash变量参数调用cmake

用bash变量参数调用cmake
EN

Stack Overflow用户
提问于 2013-12-13 15:25:48
回答 1查看 1.3K关注 0票数 3

我正在努力解决一个奇怪的问题。我试图使用shell变量作为参数运行cmake命令行,但失败了。这就是我所做的:

代码语言:javascript
复制
#1. Basic. works fine
cmake -G 'Sublime Text 2 - Ninja'

#2. Argument into variable. error
CMAKE_CONFIG="-G 'Sublime Text 2 - Ninja'"
cmake $CMAKE_CONFIG ../..
> CMake Error: Could not create named generator  'Sublime Text 2 - Ninja'

#3. Adding -v before variable. 'compile' but ignore the argument (generate a Makefile). Hacky and senseless?
CMAKE_CONFIG="-G 'Sublime Text 2 - Ninja'"
cmake -v$CMAKE_CONFIG ../..

#4. Quoting argument. error (same as #2)
CMAKE_CONFIG="-G 'Sublime Text 2 - Ninja'"
cmake "$CMAKE_CONFIG" ../..

处理--跟踪和--调试输出变量会给出以下结果:

代码语言:javascript
复制
#5. Working command
cmake ../.. --trace --debug-output -G "Sublime Text 2 - Ninja"

#6. Non existing generator. 
#Expected result (witness purpose only)
cmake ../.. --trace --debug-output -G 'random test'     
[...]
CMake Error: Could not create named generator random test

#7. Testing with variable. 
#Output error quotes the generator's name and there is an extra space before it
cmake ../.. --trace --debug-output $CMAKE_CONFIG     
[...]
CMake Error: Could not create named generator  'Sublime Text 2 - Ninja'

#8. Removing the quote within the variable. 
#Still error, but the only difference with #6 is the extra space after 'generator'
CMAKE_CONFIG="-G Sublime Text 2 - Ninja"
cmake ../.. --trace --debug-output $CMAKE_CONFIG     
[...]
CMake Error: Could not create named generator  Sublime Text 2 - Ninja

我也试图改变IFS变量,但没有成功实现我的目标。

有什么暗示吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-12-13 15:41:55

在这种情况下,您需要调试外壳,而不是cmake。诀窍是在命令中将"cmake“替换为printf '%q\n',让bash向您展示如何解释您的参数。

我认为使用这样的数组是可行的:

代码语言:javascript
复制
CMAKE_CONFIG=(-G 'Sublime Text 2 - Ninja')
cmake "${CMAKE_CONFIG[@]}" ../..
票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20570042

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档