Fix compilation on Apple Silicon

This allows cross-compiling for x86_64 on mac ARM machines, and sets
things up for a switch later.
SDL upgrade is necessary for compilation with the GLES headers in
different SDKs.

Tested by: langbart, minohaka
Differential Revision: https://code.wildfiregames.com/D4424
This was SVN commit r26208.
This commit is contained in:
wraitii 2022-01-13 14:42:42 +00:00
parent a2ab6b9b72
commit c1f779dff5
2 changed files with 82 additions and 14 deletions

View file

@ -63,6 +63,7 @@ end
-- detect CPU architecture (simplistic, currently only supports x86, amd64 and ARM)
arch = "x86"
macos_arch = "x86_64"
if _OPTIONS["android"] then
arch = "arm"
elseif os.istarget("windows") then
@ -71,7 +72,11 @@ elseif os.istarget("windows") then
end
else
arch = os.getenv("HOSTTYPE")
if arch == "x86_64" or arch == "amd64" then
-- Force x86_64 on Mac OS for now, as Spidermonkey 78 isn't Apple Silicon compatible.
if os.istarget("macosx") then
arch = "amd64"
macos_arch = "x86_64"
elseif arch == "x86_64" or arch == "amd64" then
arch = "amd64"
else
os.execute(cc .. " -dumpmachine > .gccmachine.tmp")
@ -549,8 +554,14 @@ function setup_static_lib_project (project_name, rel_source_dirs, extern_libs, e
-- The exception to this principle is Atlas UI, which is not a static library.
rtti "off"
if os.istarget("macosx") and _OPTIONS["macosx-version-min"] then
xcodebuildsettings { MACOSX_DEPLOYMENT_TARGET = _OPTIONS["macosx-version-min"] }
if os.istarget("macosx") then
architecture(macos_arch)
buildoptions { "-arch " .. macos_arch }
linkoptions { "-arch " .. macos_arch }
xcodebuildsettings { ARCHS = macos_arch }
if _OPTIONS["macosx-version-min"] then
xcodebuildsettings { MACOSX_DEPLOYMENT_TARGET = _OPTIONS["macosx-version-min"] }
end
end
end
@ -573,8 +584,14 @@ function setup_shared_lib_project (project_name, rel_source_dirs, extern_libs, e
if os.istarget("windows") then
links { "delayimp" }
elseif os.istarget("macosx") and _OPTIONS["macosx-version-min"] then
xcodebuildsettings { MACOSX_DEPLOYMENT_TARGET = _OPTIONS["macosx-version-min"] }
elseif os.istarget("macosx") then
architecture(macos_arch)
buildoptions { "-arch " .. macos_arch }
linkoptions { "-arch " .. macos_arch }
xcodebuildsettings { ARCHS = macos_arch }
if _OPTIONS["macosx-version-min"] then
xcodebuildsettings { MACOSX_DEPLOYMENT_TARGET = _OPTIONS["macosx-version-min"] }
end
end
end
@ -1094,6 +1111,11 @@ function setup_main_exe ()
links { "pthread" }
links { "ApplicationServices.framework", "Cocoa.framework", "CoreFoundation.framework" }
architecture(macos_arch)
buildoptions { "-arch " .. macos_arch }
linkoptions { "-arch " .. macos_arch }
xcodebuildsettings { ARCHS = macos_arch }
if _OPTIONS["macosx-version-min"] then
xcodebuildsettings { MACOSX_DEPLOYMENT_TARGET = _OPTIONS["macosx-version-min"] }
end
@ -1125,6 +1147,14 @@ function setup_atlas_project(project_name, target_type, rel_source_dirs, rel_inc
-- Link to required libraries
links { "winmm", "delayimp" }
elseif os.istarget("macosx") then
architecture(macos_arch)
buildoptions { "-arch " .. macos_arch }
linkoptions { "-arch " .. macos_arch }
xcodebuildsettings { ARCHS = macos_arch }
if _OPTIONS["macosx-version-min"] then
xcodebuildsettings { MACOSX_DEPLOYMENT_TARGET = _OPTIONS["macosx-version-min"] }
end
elseif os.istarget("linux") or os.istarget("bsd") then
if os.getversion().description == "FreeBSD" then
buildoptions { "-fPIC" }
@ -1244,6 +1274,12 @@ function setup_atlas_frontend_project (project_name)
else -- Non-Windows, = Unix
links { "AtlasObject" }
if os.istarget("macosx") then
architecture(macos_arch)
buildoptions { "-arch " .. macos_arch }
linkoptions { "-arch " .. macos_arch }
xcodebuildsettings { ARCHS = macos_arch }
end
end
links { "AtlasUI" }
@ -1307,6 +1343,11 @@ function setup_collada_project(project_name, target_type, rel_source_dirs, rel_i
buildoptions { "-fno-strict-aliasing" }
-- On OSX, fcollada uses a few utility functions from coreservices
links { "CoreServices.framework" }
architecture(macos_arch)
buildoptions { "-arch " .. macos_arch }
linkoptions { "-arch " .. macos_arch }
xcodebuildsettings { ARCHS = macos_arch }
end
end
@ -1453,8 +1494,14 @@ function setup_tests()
includedirs { source_root .. "pch/test/" }
elseif os.istarget("macosx") and _OPTIONS["macosx-version-min"] then
xcodebuildsettings { MACOSX_DEPLOYMENT_TARGET = _OPTIONS["macosx-version-min"] }
elseif os.istarget("macosx") then
architecture(macos_arch)
buildoptions { "-arch " .. macos_arch }
linkoptions { "-arch " .. macos_arch }
xcodebuildsettings { ARCHS = macos_arch }
if _OPTIONS["macosx-version-min"] then
xcodebuildsettings { MACOSX_DEPLOYMENT_TARGET = _OPTIONS["macosx-version-min"] }
end
end
end

View file

@ -24,7 +24,7 @@ ZLIB_VERSION="zlib-1.2.11"
CURL_VERSION="curl-7.71.0"
ICONV_VERSION="libiconv-1.16"
XML2_VERSION="libxml2-2.9.10"
SDL2_VERSION="SDL2-2.0.12"
SDL2_VERSION="SDL2-2.0.18"
# NOTE: remember to also update LIB_URL below when changing version
BOOST_VERSION="boost_1_76_0"
# NOTE: remember to also update LIB_URL below when changing version
@ -87,7 +87,23 @@ CXXFLAGS="$CXXFLAGS $C_FLAGS -stdlib=libc++ -std=c++17 -msse4.1"
OBJCFLAGS="$OBJCFLAGS $C_FLAGS"
OBJCXXFLAGS="$OBJCXXFLAGS $C_FLAGS"
LDFLAGS="$LDFLAGS -stdlib=libc++"
# Force x86_64 architecture on MacOS for now.
# NB: annoyingly, this is rather unstandardised. Some libs expect -arch, others different things.
# Further: wxWidgets uses its own system and actually fails to compile with arch arguments.
ARCHLESS_CFLAGS=$CFLAGS
ARCHLESS_CXXFLAGS=$CXXFLAGS
ARCHLESS_LDFLAGS="$LDFLAGS -stdlib=libc++"
CFLAGS="$CFLAGS -arch x86_64"
CXXFLAGS="$CXXFLAGS -arch x86_64"
LDFLAGS="$LDFLAGS -arch x86_64"
# Some libs want this passed to configure for cross compilation.
HOST_PLATFORM="--host=x86_64-apple-darwin"
# CMake doesn't seem to pick up on architecture with CFLAGS only
CMAKE_FLAGS="-DCMAKE_OSX_ARCHITECTURES=x86_64"
JOBS=${JOBS:="-j2"}
@ -431,6 +447,7 @@ then
CONF_OPTS="--prefix=$INSTALL_DIR
--disable-shared
--enable-unicode
--enable-universal_binary=x86_64
--with-cocoa
--with-opengl
--with-libiconv-prefix=${ICONV_DIR}
@ -450,10 +467,10 @@ then
if [[ $MIN_OSX_VERSION && ${MIN_OSX_VERSION-_} ]]; then
CONF_OPTS="$CONF_OPTS --with-macosx-version-min=$MIN_OSX_VERSION"
fi
(../configure CFLAGS="$CFLAGS" \
CXXFLAGS="$CXXFLAGS" \
CPPFLAGS="-stdlib=libc++ -D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=1" \
LDFLAGS="$LDFLAGS" $CONF_OPTS \
(../configure CFLAGS="$ARCHLESS_CFLAGS" \
CXXFLAGS="$ARCHLESS_CXXFLAGS" \
CPPFLAGS="-D__ASSERT_MACROS_DEFINE_VERSIONS_WITHOUT_UNDERSCORES=1" \
LDFLAGS="$ARCHLESS_LDFLAGS" $CONF_OPTS \
&& make ${JOBS} && make install) || die "wxWidgets build failed"
popd
popd
@ -638,6 +655,7 @@ then
(./configure CFLAGS="$CFLAGS" \
CXXFLAGS="$CXXFLAGS" \
LDFLAGS="$LDFLAGS" \
"$HOST_PLATFORM" \
--prefix="$INSTALL_DIR" \
--enable-fat \
--disable-shared \
@ -784,6 +802,7 @@ then
(./configure CFLAGS="$CFLAGS" \
CXXFLAGS="$CXXFLAGS" \
LDFLAGS="$LDFLAGS" \
"$HOST_PLATFORM" \
--prefix="$INSTALL_DIR" \
GNUTLS_CFLAGS="-I${GNUTLS_DIR}/include" \
GNUTLS_LIBS="-L${GNUTLS_DIR}/lib -lgnutls" \
@ -832,6 +851,7 @@ then
(CFLAGS="$CFLAGS" CXXFLAGS="$CXXFLAGS" LDFLAGS="$LDFLAGS" \
../runConfigureICU MacOSX \
"$HOST_PLATFORM" \
--prefix=$INSTALL_DIR \
--disable-shared \
--enable-static \
@ -994,6 +1014,7 @@ then
-DFMT_TEST=False \
-DFMT_DOC=False \
-DCMAKE_INSTALL_PREFIX="$INSTALL_DIR" \
"$CMAKE_FLAGS" \
&& make fmt ${JOBS} && make install) || die "fmt build failed"
popd
@ -1031,7 +1052,7 @@ then
rm -f .already-built
fi
CXXFLAGS="$CXXFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" JOBS="$JOBS" ./build.sh || die "Error building NVTT"
CXXFLAGS="$CXXFLAGS" CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" CMAKE_FLAGS="$CMAKE_FLAGS" JOBS="$JOBS" ./build.sh || die "Error building NVTT"
popd > /dev/null