CMAKE plugin and OS 11 Universal Binary

If you’re only using Xcode with the graphical interface, and don’t do any command line builds you never need to turn off universal binaries.

Instead, just click “Build for My Mac” or “Build for Any Mac” whenever you want to change anything.

Hmm, maybe I’m missing something here. Do you mean in the menu on the attached image? If I use an untouched xcodeproj with -D CMAKE_OSX_ARCHITECTURES "x86_64;arm64" I always get universal builds no matter what I select there.

Screenshot 2022-11-14 at 14.16.00

I do mean that. On my computer selecting “My Mac” creates single architecture builds. Are you sure you don’t happen to have caches from a previous build too?

Thanks for all the help so far!
I trashed everything, but it’s still building an UB2.
However, if I set “Build Active Architecture Only” to “YES” then it behaves as you say.
But CMake seems to set this flag to “NO” by default (if CMAKE_OSX_ARCHITECTURES is set).
Have you tweaked anything to change that?

mmm. Ignore my previous suggestion then.
Looks like the solutions with global CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH are actually ignored in xcode, which is probably a CMake bug.

So, the maintainable solution I’d go for is to just generate two projects, as I’ve shown above. One for universal binary and one for non-universal binary, or toggle between them in the same project by calling CMake again.

This would have the advantage of also doing what you expect when building in the command line or using other IDEs like VSCode or CLion, where as custom scripting solutions would only work in XCode.

1 Like

With set (CMAKE_XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH "YES") I was only able to set the flag on the project while the targets still had it overridden to NO, but using the loop I already had I could do set_target_properties and set XCODE_ATTRIBUTE_ONLY_ACTIVE_ARCH to YES for all targets.

Now it behaves as you describe and just builds the needed arch depending on the selected target in the menu bar.

Thanks a lot! I find it very hard to locate reliable information on these kinds of XCode/CMake configuration issues and you helped me out a lot.

2 Likes

Hi guys,

So, in the end, what is the correct way to build universal binaries with different macOS minimum version? Because for the ARM side it has to be 11.0, while for the Intel side I would like to set it for example to 10.14. I’m working in CMake, no projucer and no Xcode.

If I do this at the beginning of the cmakelist file:

if (APPLE)
    set(CMAKE_OSX_DEPLOYMENT_TARGET "11.0" CACHE STRING "Minimum OS X deployment target" FORCE)
    set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
endif()

I get this error:

clang: note: diagnostic msg: Error generating preprocessed source(s) - cannot generate preprocessed source with multiple -arch options.

And I cannot compile. This is a huge blocking point for me right now, so any help would be really appreciated. Thank you guys.

I’m using this without issues:

if (APPLE)   
    set(CMAKE_OSX_ARCHITECTURES "x86_64;arm64" CACHE INTERNAL "")
    set(CMAKE_OSX_DEPLOYMENT_TARGET "10.11" CACHE STRING "Minimum OS X deployment version" FORCE)
endif()

As far as I know there’s no need to have 11.0 as the minimum for arm builds - why do you need it?

Oh yes,

It’s working, the error I posted before was triggered by another element (very strange combinations of event but ok).

Thank you!