gpt4 book ai didi

build - CMake多选项设置

转载 作者:行者123 更新时间:2023-12-03 02:14:42 34 4
gpt4 key购买 nike

我正在开发一个使用 CMake 构建的项目,因此我正在为其编写一个 CMakeLists.txt 。在这个文件中,我想要一个(缓存的)CMake 变量,它只能采用几个选项之一(我会以某种方式指定),而不是任何任意字符串。为简单起见,我们将其视为一个可以采用“红色”、“绿色”或“蓝色”的字符串 - 但不能采用其他值。

除了设置任意字符串然后检查其有效性之外,我可以使用最新的 CMake 版本来实现此目的吗?

最佳答案

答案可以在 Kitware 的一篇博客文章 "Constraining Values with ComboBoxes in CMake (cmake-gui)" 中找到。 :

So here’s how it works: for each cache entry that you want to constrain to some set of values, define it as usual with a default value as a STRING cache variable, for example:

set(BaseName "binary" CACHE STRING "BaseName chosen by the user at CMake configure time")

Now, after defining the cache entry with its initial default value, define the set of strings to which its value should be constrained:

set_property(CACHE BaseName PROPERTY STRINGS binary octal decimal hexadecimal)

After the set_property call, cmake-gui knows to present a drop-down combo box for editing the “BaseName” cache entry, and it knows that the four valid choices for this entry that it should present are binary, octal, decimal and hexadecimal.

关于build - CMake多选项设置,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47611209/

34 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com