gpt4 book ai didi

cmake - 通过命令提示符将参数传递给 CMAKE

转载 作者:行者123 更新时间:2023-12-02 05:07:31 30 4
gpt4 key购买 nike

我的项目有一个 makefile,我可以用它传递一个控制某些构建标志的参数。现在我想使用 CMake 做同样的事情。我已经创建了 CMakeLists.txt,但我不知道如何传递参数并检查 CMakeLists.txt 中的参数值。

我的 Makefile 示例:

ifeq "$(MY_VARIABLE)" "option_value"
//setting some flags
else
//setting some other flag
endif

然后,我使用 make MY_VARIABLE=option_value 调用 make。CMake 中从命令提示符获取参数并据此设置标志的方法是什么?

最佳答案

在 CMakeLists.txt 文件中,创建一个缓存变量,如下所述:

SET(MY_VARIABLE "option_value" CACHE STRING "Some user-specified option")

来源:https://cmake.org/cmake/help/latest/command/set.html#set-cache-entry

然后,使用 GUI(ccmake 或 cmake-gui)设置缓存变量,或者指定变量的值 on the cmake command line with -D :

cmake -DMY_VARIABLE:STRING=option_value2

如果您的选项实际上是 bool 值,请将您的缓存变量修改为 bool 值。

关于cmake - 通过命令提示符将参数传递给 CMAKE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12896988/

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