openexr
openexr copied to clipboard
Building universal 2 on macOS is broken
CMake has a handy way to build Universal (fat) binaries with x86_64 and arm64 chunks. A recent change seems to break it (https://github.com/AcademySoftwareFoundation/openexr/pull/772). This is with Xcode 12.2 beta 2.
I have found that trying to detect compiler support for CPU specific functions is really annoying when building universal binaries with cmake as what you want to ask is not does my compiler support AVX? as this will try to build AVX instructions for both x86_64 (fine) and then arm64 (fail), which then fails. What you needs is does my compiler support AVX in x86_64 mode?, then to use platform #defines to switch in the actual code.
% cmake -DPYILMBASE_ENABLE=OFF -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" ../
-- The C compiler identification is AppleClang 12.0.0.12000032
-- The CXX compiler identification is AppleClang 12.0.0.12000032
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Configure ILMBASE Version: 2.5.3 Lib API: 25.0.2
-- Setting build type to 'Release' as none was specified.
-- Looking for pthread.h
-- Looking for pthread.h - found
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE
-- Looking for include file ucontext.h
-- Looking for include file ucontext.h - not found
-- Configure OpenEXR Version: 2.5.3 Lib API: 25.0.2
-- Found ZLIB: /Applications/Xcode-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX11.0.sdk/usr/lib/libz.tbd (found version "1.2.11")
-- Performing Test OPENEXR_IMF_HAVE_SYSCONF_NPROCESSORS_ONLN
-- Performing Test OPENEXR_IMF_HAVE_SYSCONF_NPROCESSORS_ONLN - Success
-- Performing Test OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX
-- Performing Test OPENEXR_IMF_HAVE_GCC_INLINE_ASM_AVX - Failed
CMake Error at OpenEXR/config/CMakeLists.txt:51 (if):
if given arguments:
"arm64" "x86_64" "MATCHES" "arm64"
Unknown arguments specified
If I revert the PR linked above I can build univerally, but the AVX ASM is disabled, which is also not desirable.
Thanks for the report. To start, can I request that if you are on a release version of CMake, could you retest using CMake 3.19, which is now available as a release candidate? https://cmake.org/download/ 3.19 has fixes for Xcode 12, including moving CMake from the Xcode 3 (!!!??!!!!!) build system to Xcode's current build system. They did this specifically to address building universal binaries.
I don't expect this will fix the issues you've encountered, but I think we should start from a version of CMake that's intended to address Apple Silicon, and work with Xcode 12.
I have done some further testing with cmake release and 3.19 and have a PR here. https://github.com/AcademySoftwareFoundation/openexr/pull/854
Also I reproduced this with the normal Makefile generator, the Xcode build system changes only matter with -GXcode in the cmake command (makeing xcode project files).
Hmmm Universal 2 builds seem to be broken again on master... Maybe something to do with the library split?
If I checkout master at this commit, I can totally cmake Ilmbase with universal 2, and then cmake OpenEXR with universal 2, pointing to the built Ilmbase by exporting IlmBase_DIR.
Can you post the cmake command you are using to generate?
Sure thing (using cmake version 3.19.1):
cmake -DCMAKE_OSX_ARCHITECTURES="arm64;x86_64" ..