macos-arch-fix.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. diff --git a/CMakeLists.txt b/CMakeLists.txt
  2. index 6451fcf1b..dbd5016ca 100644
  3. --- a/CMakeLists.txt
  4. +++ b/CMakeLists.txt
  5. @@ -63,11 +63,22 @@ option(PNG_HARDWARE_OPTIMIZATIONS "Enable hardware optimizations" ON)
  6. set(PNG_PREFIX "" CACHE STRING "Prefix to add to the API function names")
  7. set(DFA_XTRA "" CACHE FILEPATH "File containing extra configuration settings")
  8. +# CMake currently sets CMAKE_SYSTEM_PROCESSOR to one of x86_64 or arm64 on macOS,
  9. +# based upon the OS architecture, not the target architecture. As such, we need
  10. +# to check CMAKE_OSX_ARCHITECTURES to identify which hardware-specific flags to
  11. +# enable. Note that this will fail if you attempt to build a universal binary in
  12. +# a single cmake invokation.
  13. +if (APPLE AND CMAKE_OSX_ARCHITECTURES)
  14. + set(TARGET_ARCH ${CMAKE_OSX_ARCHITECTURES})
  15. +else()
  16. + set(TARGET_ARCH ${CMAKE_SYSTEM_PROCESSOR})
  17. +endif()
  18. +
  19. if(PNG_HARDWARE_OPTIMIZATIONS)
  20. # set definitions and sources for arm
  21. -if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" OR
  22. - CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64")
  23. +if(TARGET_ARCH MATCHES "^arm" OR
  24. + TARGET_ARCH MATCHES "^aarch64")
  25. set(PNG_ARM_NEON_POSSIBLE_VALUES check on off)
  26. set(PNG_ARM_NEON "check" CACHE STRING "Enable ARM NEON optimizations:
  27. check: (default) use internal checking code;
  28. @@ -121,8 +132,8 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "^powerpc*" OR
  29. endif()
  30. # set definitions and sources for intel
  31. -if(CMAKE_SYSTEM_PROCESSOR MATCHES "^i?86" OR
  32. - CMAKE_SYSTEM_PROCESSOR MATCHES "^x86_64*")
  33. +if(TARGET_ARCH MATCHES "^i?86" OR
  34. + TARGET_ARCH MATCHES "^x86_64*")
  35. set(PNG_INTEL_SSE_POSSIBLE_VALUES on off)
  36. set(PNG_INTEL_SSE "on" CACHE STRING "Enable INTEL_SSE optimizations:
  37. off: disable the optimizations")
  38. @@ -171,8 +182,8 @@ endif()
  39. else(PNG_HARDWARE_OPTIMIZATIONS)
  40. # set definitions and sources for arm
  41. -if(CMAKE_SYSTEM_PROCESSOR MATCHES "^arm" OR
  42. - CMAKE_SYSTEM_PROCESSOR MATCHES "^aarch64")
  43. +if(TARGET_ARCH MATCHES "^arm" OR
  44. + TARGET_ARCH MATCHES "^aarch64")
  45. add_definitions(-DPNG_ARM_NEON_OPT=0)
  46. endif()
  47. @@ -183,8 +194,8 @@ if(CMAKE_SYSTEM_PROCESSOR MATCHES "^powerpc*" OR
  48. endif()
  49. # set definitions and sources for intel
  50. -if(CMAKE_SYSTEM_PROCESSOR MATCHES "^i?86" OR
  51. - CMAKE_SYSTEM_PROCESSOR MATCHES "^x86_64*")
  52. +if(TARGET_ARCH MATCHES "^i?86" OR
  53. + TARGET_ARCH MATCHES "^x86_64")
  54. add_definitions(-DPNG_INTEL_SSE_OPT=0)
  55. endif()