Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake Top Level Xcode Project Properties

Tags:

c++

c

xcode

cmake

I am using Cmake with Xcode to generate a c++/c "project" (my_project) and some c++/c "targets" (one is a binary, the rest are libraries)

My CMakeLists.txt looks something like this:

project(my_project)
add_subdirectory(library_projectA)
add_subdirectory(library_projectB)
add_subdirectory(binary_project) 

Each Subdirectory has a CMakeLists.txt with either:

add_library(library_projectA)

Or

add_executable(binary_project)

Which produces a top level my_project.xcodeproj, which references the subprojects.

Xcode has this Hierarchical property inheritance (left fields take precedence over right fields):

Target, Project, Default

I would like to change the "Project" fields, i.e. for my_project. This should affect ALL Targets.

I have tried this:

add_custom_target(my_project)
add_target_properties(my_project PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "NO")

But this doesn't work.

Note that if I put this in one of the "Targets":

add_target_properties(binary_project PROPERTIES XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "NO")

Then this works, but only for that "Target"

If this isn't clear, I'd be happy to provide a working example, but this will take a bit of time...

On the off-chance anyone knows of a quicker fix to the whole problem, I'd like a clean install of Xcode not not come up with this (or any other) warning:

Project 'my_project' overrides the Architectures setting. This will remove the setting and allow Xcode to automatically select Architectures based on hardware available for the active platform and deployment target.

like image 287
Tim Rochester Avatar asked Nov 27 '13 14:11

Tim Rochester


1 Answers

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")
like image 187
Dmitry Avatar answered Oct 04 '22 08:10

Dmitry