通过命令提示符将参数传递给CMAKE [英] Passing the argument to CMAKE via command prompt
问题描述
我有一个makefile为我的项目,并且我传递一些参数,基于这个参数,我设置一些标志。我能做到这一点。但现在我想使用cmake做同样的事情。我创建了 cmakelist.txt
,但我不知道如何传递参数,并检查 cmakelist.txt $ c中的参数值$ c>。
我的makefile示例:
ifeq $(FAB)po
pre>
//设置一些标志
else
//设置一些标志
endif
从命令提示符接受参数的方法是什么,并根据该参数设置标志?
解决方案在CMakeLists.txt文件中,创建一个缓存变量,如下所示:
SET (FABpoCACHE STRING一些用户指定的选项)
源: http://cmake.org/cmake/help/v2.8.8/cmake.html#command:set
然后,使用GUI(ccmake或cmake-gui)设置缓存变量,或者在cmake命令行上指定变量的值:
cmake -DFAB:STRING = po
资料来源: http:// cmake .org / cmake / help / v2.8.8 / cmake.html#opt:-Dvar:typevalue
将缓存变量修改为布尔值if,in事实上,您的选项是布尔值。
I have a makefile for my project and also I am passing some argument and based on that argument i am seting some flag. I am able to do this . but now I want to do the same using cmake. I have created
cmakelist.txt
but I don't know how to pass the argument and check for the argument value incmakelist.txt
.Sample of my makefile:
ifeq "$(FAB)" "po" //setting some flags else //setting some iother flag endif
What is the way to take the argument from command prompt and set flags based on that?
解决方案In the CMakeLists.txt file, create a cache variable, as documented here:
SET(FAB "po" CACHE STRING "Some user-specified option")
Source: http://cmake.org/cmake/help/v2.8.8/cmake.html#command:set
Then, either use the GUI (ccmake or cmake-gui) to set the cache variable, or specify the value of the variable on the cmake command line:
cmake -DFAB:STRING=po
Source: http://cmake.org/cmake/help/v2.8.8/cmake.html#opt:-Dvar:typevalue
Modify your cache variable to a boolean if, in fact, your option is boolean.
这篇关于通过命令提示符将参数传递给CMAKE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!