How to set arch dependent include directory for universal mac binary?

I’m trying to setup architecture dependant include paths in CMake for universal macOS builds.

I’m using a library that have platform dependant include headers.

The equivalent Xcode version of this is using an .xcconfig file and assigning it to the targets:

HEADER_SEARCH_PATHS = $(inherited) "../ThirdParty/include/ruby/2.7/mac"
HEADER_SEARCH_PATHS[arch=arm64] = $(inherited) "../ThirdParty/include/ruby/2.7/mac/arm64-darwin20"
HEADER_SEARCH_PATHS[arch=x86_64] = $(inherited) "../ThirdParty/include/ruby/2.7/mac/x86_64-darwin18"
  1. How can I do the same via CMake?

  2. How can I do this via a Find Module that sets up an imported library for a pre-compiled library?

  # Ruby 2.7
  add_library(SketchUp::SketchUpRuby_270 UNKNOWN IMPORTED)
  set_target_properties(SketchUp::SketchUpRuby_270 PROPERTIES

I don’t believe that CMake supports this today. CMake would need a genex to look up per-architecture bits and then also know to add -arch flags in front to hide from other arches on “fat” compilation rules. You can file a feature request, but it doesn’t sound trivial to resolve to me.

One thing that would work today would be to make another directory where the contents of those headers detects the target processor and chains off to the real directory based on that (basically moving the directory selection off to the compiler).

1 Like

Ah, thanks for the suggestion. I was wondering if I had to make two separate targets and manually lipo the binaries together. Doing a shim-header is simpler.

I’ll log a file request for per-arch config. Might find that I need it in other cases going forward now that we need to deal with arm64 on mac.