cmake add_compile_definitions for xcode的特定拱门
当我使用 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"
但是我想知道如何解决此问题,请避免两次运行命令。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好问题!我认为您使用 目标属性。文档说它接受发电机的表达方式,所以也许您可以做这样的事情?
这里的想法是,您会得到通常的编译定义(通过生成器表达式),以及添加到 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?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
.回答我的问题。
我放弃了寻找一种纯粹的方法来解决此问题,然后在Arch宏中使用编译器(LLVM或GCC)来找出它是哪个拱门。
我在一个通用的标头文件中定义了此功能,它将包含在我想使用宏的任何文件中。
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.
I defined this in a common header file and it will be included by any files I want to use the macro.