2

I am attempting to use CMake to convert a generic wrapper into a specific one, via token replacement. I hope that all the user would have to do is input a specific set of strings, have CMake do configure_file, and the wrapper would read in the values and work as intended.

I am aware of the possibility to use set to set the token that needs to be replaced:

set(FAV_FOOD "Sushi" CACHE STRING "What is your favorite food?")

As well as the option to have the user select from a set of answers like so:

set(MY_SELECTION "Option A" CACHE STRING "Help message for this variable")
set_property(
    CACHE MY_SELECTION
    PROPERTY STRINGS
    "Option A" "Option B" "Option C"
)

The problem with this is that I can't enumerate all valid answers. Is there any way for CMake to have a GUI pop up and allow the user to answer with any string? I could just have the user fill out these values in a file before calling make, but I'd like to avoid the users doing anything by hand in the files, and I want to take advance of the CMake cache and avoid assuming that the user has already filled out the variables in a file.

Any advice would be most helpful. Thanks.

4

1 回答 1

2

您的第一个示例是向 CMake 提供用户指定选项的标准方式,通常包括一些合适的默认值,正如您所演示的那样。

您可以省略默认值(传递空字符串),然后检查是否已指定该值,以便在用户尝试配置时生成错误。

为了自动提供这些值,用户可以使用 -D= 语法在命令行上指定它们:

cmake -DSOME_VAR=some_val <path_to_CMakeLists.txt>

我通常使用 cmake/ccmake,我假设您使用的是 windows cmake-gui,它与 ccmake 非常相似。我知道没有任何方法可以使用 cmake-gui 弹出一些额外的窗口。但是,使用上述选项调用 cmake-gui 似乎是可能的,如此处所述。使用此方法,您可以提供用户可以编辑的 .bat 文件,以便输入您希望他们指定的设置。

在我看来,只要您已经让他们运行 cmake-gui,那么简单地利用您提出的第一个解决方案并让他们以“老式方式”更改 gui 中的值确实是最合适的选择。

于 2015-06-19T19:49:03.310 回答