2

I'm setting up a MacOS universal binary build (x86_64 & arm64) for a JUCE based audio plugin project. The x86_64 build has some IPP libraries (which are x86 only) as a dependency while the ARM build uses some ARM specific replacement routines written by us. So I need to set up CMake to build the plugin as universal binary but only link to IPP libs for the x86_64 part. My approach so far looks like that

# somewhere at the top of my CMakeLists.txt
set(CMAKE_OSX_ARCHITECTURES arm64 x86_64)
set(ONLY_ACTIVE_ARCH        NO)

# somewhere later the IPP stuff is handled
add_library(ALL_IPP INTERFACE)

set(IPP_ROOT "/opt/intel/ipp")

target_include_directories(ALL_IPP INTERFACE "${IPP_ROOT}/include")

add_library(ippi    STATIC IMPORTED GLOBAL)
add_library(ipps    STATIC IMPORTED GLOBAL)
add_library(ippvm   STATIC IMPORTED GLOBAL)
add_library(ippcore STATIC IMPORTED GLOBAL)

set (IPP_LIB "${IPP_ROOT}/lib")

set_target_properties(ippi    PROPERTIES IMPORTED_LOCATION ${IPP_LIB}/libippi.a    OSX_ARCHITECTURES x86_64)
set_target_properties(ipps    PROPERTIES IMPORTED_LOCATION ${IPP_LIB}/libipps.a    OSX_ARCHITECTURES x86_64)
set_target_properties(ippvm   PROPERTIES IMPORTED_LOCATION ${IPP_LIB}/libippvm.a   OSX_ARCHITECTURES x86_64)
set_target_properties(ippcore PROPERTIES IMPORTED_LOCATION ${IPP_LIB}/libippcore.a OSX_ARCHITECTURES x86_64)

target_link_libraries(ALL_IPP INTERFACE ippi ipps ippvm ippcore)

# somewhere later
target_link_libraries(myPlugin PRIVATE ALL_IPP)

This approach leads to build warnings like

ld: warning: ignoring file /opt/intel/ipp/lib/libippi.a, building for macOS-arm64 but attempting to link with file built for unknown-x86_64

I'm not that experienced with CMake, so its totally possible that I'm choosing a completely wrong approach here or that there is just a little stupid error. All help is greatly appreciated!

PluginPenguin
  • 1,576
  • 11
  • 25
  • Sooo `if (NOT CMAKE_CROSSCOMPILING) target_link_libraries(...)`? Or maybe `if (UNIX)` or `if (CMAKE_SYSTEM_PROCESSOR MATCHES "X86")`? etc? – KamilCuk Nov 02 '20 at 09:06
  • I don't think this is the right approach. First of all the universal binary build is one single target compiled in one run for both architectures and getting combined into a single output binary so the whole build is done in one run and I cannot add conditional expressions that only affect one target architecture if I understood everything correctly. Then, I won't rely on the architecture of my build machine. This should build universal binaries on both, intel and arm Macs. – PluginPenguin Nov 02 '20 at 09:35
  • Note: the [docs for `CMAKE_OSX_ARCHITECTURE`](https://cmake.org/cmake/help/latest/variable/CMAKE_OSX_ARCHITECTURES.html) recommend setting it as a cache variable if you want to support pre-cmake-3.21 – starball Aug 31 '22 at 02:14
  • [the apple docs on porting to universal binaries say that you can't use anything but libraries that are universal binaries](https://developer.apple.com/documentation/apple-silicon/porting-your-macos-apps-to-apple-silicon#Obtain-Universal-Versions-of-Linked-Libraries). I haven't fact-checked, but it's official documentation. – starball Aug 31 '22 at 02:37

0 Answers0