Use CMake-native methods to do our static-build macOS trickery (#2083)

This should remain equivalent for our current setups,
but play nicer with anyone wanting to experiment further.

It *may* break for someone building on an Intel Mac,
but this is a libpng limitation and thus out of our control.
This commit is contained in:
Eldred Habert
2026-09-14 09:55:34 -04:00
committed by GitHub
parent c8e8a2f522
commit 0fe43bf0cb
+9 -6
View File
@@ -6,13 +6,16 @@
# triggers some poorly-tested code paths within Apple's linker, which then crashes. # triggers some poorly-tested code paths within Apple's linker, which then crashes.
# This can be worked around by using LLVM's LLD linker and passing `-fuse-ld=lld` when linking. # This can be worked around by using LLVM's LLD linker and passing `-fuse-ld=lld` when linking.
# The `-mmacosx-version-min=10.4` flag ensures that the binary only uses APIs available on Mac OS X 10.4 Tiger. set(CMAKE_OSX_DEPLOYMENT_TARGET 10.4 CACHE STRING "Minimum Mac OS X version to target for deployment (at runtime)")
# The `-arch` flags build a "fat binary" that works on both Apple architectures: # This builds a "fat binary" that works on both Apple architectures:
# older Intel x64 Macs and newer ARM "Apple Silicon" ones. # older Intel x64 Macs and newer ARM "Apple Silicon" ones.
set(secret_sauce -mmacosx-version-min=10.4 "SHELL:-arch x86_64" "SHELL:-arch arm64") # Avoid `-arch` being dedup'd. # Due to a libpng build script limitation/bug (as of 1.6.58), the native architecture has to be first...
add_compile_options(${secret_sauce}) # and since our CI builds this executable on an ARM machine, that's what we're putting first.
add_link_options(${secret_sauce}) set(CMAKE_OSX_ARCHITECTURES arm64 x86_64 CACHE STRING "Build architectures for Mac OS X")
set(PNG_HARDWARE_OPTIMIZATIONS OFF) # These do not play well with a dual-arch build. # This controls the SIMD optimizations, which include architecture-specific headers that get rejected
# in a dual-arch build, thus we have to disable them.
# This shouldn't be a big deal for RGBGFX, anyway?
set(PNG_HARDWARE_OPTIMIZATIONS OFF)
# Mac OS X has always provided zlib, so we can safely link dynamically against it. # Mac OS X has always provided zlib, so we can safely link dynamically against it.
# However, libpng is *not* provided by default, so we link it statically, which requires downloading and building it from source. # However, libpng is *not* provided by default, so we link it statically, which requires downloading and building it from source.