如何使用 CMake 仅在一种模式下使用变量

发布于 2024-10-02 17:12:49 字数 352 浏览 0 评论 0原文

我想在我的项目中创建一种新模式(调试、发布和新模式)。之后,我将需要一个仅在该新模式下使用的变量,因此我可以为所有模式创建一个变量,并为调试/发布(即 0)和新模式(1)设置不同的值。

我该如何解决这个问题?

我有什么:

set (CMAKE_CONFIGURATION_TYPES "Release;Debug;NewConfig" CACHE STRING "Configurations" FORCE)

SET (VARIABLEX 1)

if (VARIABLEX )
   add_definitions (-DVARIABLEX )
endif (VARIABLEX )

I Want to create a new mode (Debug, Release and a new one) in my project. After that I will need a variable that is only used in that new mode, so I can create a variable for all and set different value for Debug/Release (i.e. 0) and for the new one (1).

How can I solve this?

What i have:

set (CMAKE_CONFIGURATION_TYPES "Release;Debug;NewConfig" CACHE STRING "Configurations" FORCE)

SET (VARIABLEX 1)

if (VARIABLEX )
   add_definitions (-DVARIABLEX )
endif (VARIABLEX )

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

香草可樂 2024-10-09 17:12:49

首先,CMake 还没有很好地支持添加新的配置类型。

尽管有 CMake 常见问题解答,但此功能请求似乎仍有一些未实现的地方。甚至还有一个未解决的问题:

在 CMake 错误跟踪器中监视该错误,以便在更新时收到通知。

但是,鉴于您希望对不同的配置有不同的定义,您应该查看 CMake 目标属性 COMPILE_DEFINITIONS 和 COMPILE_DEFINITIONS_DEBUG 的帮助(例如):

First of all, adding new configuration types is not yet well supported in CMake.

Despite the CMake FAQ, looks like there is something still a bit unimplemented for this feature request. There is even an open issue for it:

Monitor that bug in the CMake bug tracker to be notified as things are updated.

However, given that you would like to have different definitions for different configurations, you should see the help for the CMake target property COMPILE_DEFINITIONS and COMPILE_DEFINITIONS_DEBUG (for example):

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文