Detect current architecture when cross-compiling Apple Universal Binary with CMake

987 Views Asked by At

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?

0

There are 0 best solutions below