简体   繁体   English

如何在CMake命令行中从CMakeLists.txt覆盖默认变量?

[英]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.

相关问题 如何在CMakeLists.txt中忽略单个CMake命令的错误? - How can I ignore errors on an individual CMake command in my CMakeLists.txt? 通过命令行在CMakeLists.txt中设置的CMAKE覆盖变量 - CMAKE override variable set in CMakeLists.txt via commandline 从父 CMakeLists.txt 覆盖 CMake 中的默认选项(...)值 - Overriding a default option(...) value in CMake from a parent CMakeLists.txt 从命令行将CMake选项移动到顶层CMakeLists.txt中 - moving CMake options from the command line into the top-level CMakeLists.txt CMake:如何在 CMakeLists.txt 中使用 bash 命令 - CMake : how to use bash command in CMakeLists.txt CMake如何将CMakeLists.txt中的shell命令传输到Makefile中 - CMake how to transfer shell command in CMakeLists.txt into Makefile 我如何知道 CMakeLists.txt 中需要哪个最低 CMake 版本? - How can I tell which minimum CMake version to require in CMakeLists.txt? 如何在不更改 CMakeLists.txt 的情况下将 CFLAGS 和 CXXFLAGS 传递给 cmake(也许通过 CLI?) - how can I pass CFLAGS and CXXFLAGS to cmake without altering the CMakeLists.txt (through CLI perhaps?) 如何在 CMakeLists.txt 中分配 cmake 变量 - How to assign cmake variables in the CMakeLists.txt 我们如何从主 CMakeLists.txt 文件中引用外部 cmake 文件? - How can we refer external cmake file from main CMakeLists.txt file?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM