[英]How can i override a default variable from CMakeLists.txt on CMake command line?
I have a .cmake file containing default values for variables. 我有一个.cmake文件,其中包含变量的默认值。 The .cmake file is called from CMakeLists.txt using 'include'. .cmake文件使用'include'从CMakeLists.txt中调用。 One of the variables is a version number. 变量之一是版本号。 What is the best practice or setup to overrule that variable version number from CMake command line? 什么是从CMake命令行否决该可变版本号的最佳实践或设置?
In gnu make you could use var ?= value where you can set var value on make command line. 在gnu make中,您可以使用var?= value,您可以在make命令行上设置var值。 I do not see something similar in C-Make. 我在C-Make中看不到类似的东西。
For boolean values, you can use option
: 对于布尔值,可以使用option
:
option(CUSTOMIZABLE_VAR "This variable do stuff" "default-value")
Also GUI apps exposing options such as CMake GUI or QtCreator you'll get a the description and a field to edit it. 此外,GUI应用程序还公开了诸如CMake GUI或QtCreator之类的选项,您将获得说明和可对其进行编辑的字段。
For value of type string, you can set a cache value with a help string: 对于字符串类型的值,可以使用帮助字符串设置缓存值:
set(CUSTOMIZABLE_VAR "8" CACHE STRING "This option is a string")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.