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:
How could I use add_definitions or add_compile_definitions for specific arch, like this:
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.
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.
2
Answers
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.
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
.