CMake Top Level Xcode Project Properties CMake Top Level Xcode Project Properties xcode xcode

CMake Top Level Xcode Project Properties


I recently needed the same thing so I had to look into the source code of CMake.

Currently, you can set attributes only for the targets and there is no way to set them on the project level.

However, it is possible to change ONLY_ACTIVE_ARCH on the project level in a slightly different way. The implemented logic in cmake is the following (for version 2.8.12):

  1. If CMAKE_OSX_ARCHITECTURES is not set, then cmake sets ONLY_ACTIVE_ARCH to YES on the project level, and depending on xcode version it sets default architectures to either $(ARCHS_STANDARD_32_64_BIT) or $(ARCHS_STANDARD_32_BIT)
  2. If CMAKE_OSX_ARCHITECTURES is defined, then ONLY_ACTIVE_ARCH becomes NO

I prefer to set CMAKE_OSX_ARCHITECTURES, so that XCode builds fat libraries and for the biggest libraries I just manually set ONLY_ACTIVE_ARCH to YES for Debug configuration only. This looks like that:

set(CMAKE_OSX_ARCHITECTURES "$(ARCHS_STANDARD_32_64_BIT)")...set_target_properties(test PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH[variant=Debug] "YES")


You can do it by adding this in your top level CMakeLists.txt:

set(CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH[variant=Release] NO)

Remove [variant=Release] to apply it to all variants.