cmake add_compile_definitions for xcode的特定拱门

发布于 2025-01-30 02:03:01 字数 993 浏览 4 评论 0 原文

当我使用 add_definitions(-denable_something) add_compile_definitions(-denable_something_something)在cmake中生成Xcode项目,它将适用于构建设置中的所有拱门。

我如何使用add_definitions或add_compile_definitions作为特定拱门,例如:

因为我想为ARM64和ARMV7定义不同的宏。

我试图附加或设置Xcode属性Xcode_attribute_gcc_preprocessor_definitions [Arch = Arm64],但它将覆盖之前和仅保留新的宏所生成的值。

我知道有一种简单的方法可以通过使用不同的拱门生成两次XCode项目来解决此问题,

cmake . -G Xcode -DARCHS="armv7"
cmake . -G Xcode -DARCHS="arm64"

但是我想知道如何解决此问题,请避免两次运行命令。

When I use add_definitions(-DENABLE_SOMETHING) or add_compile_definitions(-DENABLE_SOMETHING) in CMake to generate a Xcode Project, it will work for all archs in build setting.Just like below:enter image description here

How could I use add_definitions or add_compile_definitions for specific arch, like this:
enter image description here

Because I want to define different macros for arm64 and armv7.

I tried to append or set xcode property XCODE_ATTRIBUTE_GCC_PREPROCESSOR_DEFINITIONS[arch=arm64], but it will override the value generated before and only the new macro remained.
enter image description here

I know there is a simple way to solve this by generating xcode project for two times with different arch, like this

cmake . -G Xcode -DARCHS="armv7"
cmake . -G Xcode -DARCHS="arm64"

but I wanna to know How to fix this avoid running the command two times.

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

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

发布评论

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

评论(2

还给你自由 2025-02-06 02:03:01

好问题!我认为您使用 目标属性。文档说它接受发电机的表达方式,所以也许您可以做这样的事情?

# early on:
set_property(
  TARGET MyApp
  PROPERTY XCODE_ATTRIBUTE_GCC_PREPROCESSOR_DEFINITIONS[arch=arm64]
  "
lt;JOIN:
lt;TARGET_PROPERTY:MyApp,COMPILE_DEFINITIONS>;
lt;TARGET_PROPERTY:MyApp,ARM64_COMPILE_DEFINITIONS>, >"
)

# later on:
if (CMAKE_GENERATOR MATCHES "Xcode")
  set_property(TARGET MyApp APPEND PROPERTY ARM64_COMPILE_DEFINITIONS ENABLE_SOMETHING)
elseif (ARCHS MATCHES "arm64")
  target_compile_definitions(MyApp PRIVATE ENABLE_SOMETHING)
endif ()

这里的想法是,您会得到通常的编译定义(通过生成器表达式),以及添加到 custom property arm64_compile_definitions 的定义。

Nice question! I think you're on the right track with using the XCODE_ATTRIBUTE_<an-attribute> target property. The documentation says it accepts generator expressions, so maybe you can do something like this?

# early on:
set_property(
  TARGET MyApp
  PROPERTY XCODE_ATTRIBUTE_GCC_PREPROCESSOR_DEFINITIONS[arch=arm64]
  "
lt;JOIN:
lt;TARGET_PROPERTY:MyApp,COMPILE_DEFINITIONS>;
lt;TARGET_PROPERTY:MyApp,ARM64_COMPILE_DEFINITIONS>, >"
)

# later on:
if (CMAKE_GENERATOR MATCHES "Xcode")
  set_property(TARGET MyApp APPEND PROPERTY ARM64_COMPILE_DEFINITIONS ENABLE_SOMETHING)
elseif (ARCHS MATCHES "arm64")
  target_compile_definitions(MyApp PRIVATE ENABLE_SOMETHING)
endif ()

The idea here being that you get what the usual compile definitions would be (via the generator expression), plus the definitions added to the custom property ARM64_COMPILE_DEFINITIONS.

沒落の蓅哖 2025-02-06 02:03:01

回答我的问题。
我放弃了寻找一种纯粹的方法来解决此问题,然后在Arch宏中使用编译器(LLVM或GCC)来找出它是哪个拱门。

    #if defined(__aarch64__) // arm64
    #define MACRO_FOR_ARM64
    #elif defined(__arm__) // armv7
    #define MACRO_FOR_ARMV7
    #endif

我在一个通用的标头文件中定义了此功能,它将包含在我想使用宏的任何文件中。

Answer my question.
I gave up looking for a pure-cmake way to solve this, and using compiler(llvm or gcc) inside arch macro to figure out which arch it is.

    #if defined(__aarch64__) // arm64
    #define MACRO_FOR_ARM64
    #elif defined(__arm__) // armv7
    #define MACRO_FOR_ARMV7
    #endif

I defined this in a common header file and it will be included by any files I want to use the macro.

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