向 CMake 添加命令行选项 [英] Adding command line options to CMake
问题描述
我正在使用 CMake 构建一个大型库,我希望用户能够有选择地启用/禁用我的构建过程的某些部分.
I'm building a large library using CMake, and I would like users to be able to selectively enable/disable certain parts of my build process.
如何将命令行选项添加到我的 CMake 构建中,例如以便用户可以输入类似 cmake --build-partone --nobuild-parttwo --dothis=true --dothat=false ..
?
How can I add command-line options to my CMake build, e.g. so that users may type something like cmake --build-partone --nobuild-parttwo --dothis=true --dothat=false ..
?
显然 OPTION 关键字将创建可以从 CMake GUI 设置的变量,但我不知道如何从命令行执行此操作.
Apparently the OPTION keyword will create variables that can be set from the CMake GUI, but I can't figure out how to do this from the command line.
推荐答案
是的,您应该使用 option
命令.您可以通过以下方式从命令行设置选项:
Yeah, you should use the option
command. You can set options from the command line this way:
//CMakeLists.txt
option(MyOption "MyOption" OFF)
//Command line
cmake -DMyOption=ON MyProjectFolder
注意 -DMyOption
必须在路径之前.
Note that -DMyOption
must come before the path.
这篇关于向 CMake 添加命令行选项的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!