1

I want to build a Apple Universal Binary (=an executable that natively runs on Apple Silicon as well as on Intel Macs) with CMake. Therefore, I have enabled the compilation of arm64 and x64 via

if (APPLE)
    # Create Universal Binary
    set(CMAKE_OSX_ARCHITECTURES "arm64;x86_64")
endif()

But how do I now define the path to an already precompiled static library? I cannot find any CMake variable that tells me if the current compilation run is for x64 or arm64 and thus, the linking current fails with the following error:

[build] ld: warning: ignoring file ../thirdparty/xxx/bin/libxxx-x86_64.dylib, building for macOS-arm64 but attempting to link with file built for macOS-x86_64

What are the best practices to deal with this specific issue?

thomasreiser
  • 180
  • 2
  • 13
  • offtopic: I didn't had to set `CMAKE_OSX_ARCHITECTURES` in my project. It just worked out of the box when M1 support was introduced. – Marek R Mar 18 '22 at 10:15
  • IMO problem is `XXX` library which should be build as universal binary. – Marek R Mar 18 '22 at 10:16
  • @MarekR I was hoping that I don't need to provide any external library/dependency as a universal binary – thomasreiser Mar 18 '22 at 11:55
  • @thomasreiser That's just a warning. You can specify libs for all architectures on the command line and your app should link fine. CMake creates only a single target for the universal executable, and creates universal binary as a single invocation of compile and link. There are no separate compile and link for different archs. – sanjivgupta Nov 21 '22 at 16:29

0 Answers0