From f82fc6431b0ac6aa143a1cdbe7d3f04a51661948 Mon Sep 17 00:00:00 2001 From: wraitii Date: Sun, 15 May 2022 21:22:49 +0000 Subject: [PATCH] Fix SM compilation on M1, fix cross-compilation. Fixes 08e7efc76a. The SM build script worked on its own, but the mac OS libraries script passes it an unexpected value. This also fixes cross-compilation arm -> x86. Harfbuzz is explicitly not used when compiling freetype to avoid pkgconfig using it. Reorganize the logic a little bit around architecture handling. Differential Revision: https://code.wildfiregames.com/D4647 This was SVN commit r26882. --- build/premake/premake5.lua | 19 ++++++++++++++----- libraries/osx/build-osx-libs.sh | 27 ++++++++++++--------------- 2 files changed, 26 insertions(+), 20 deletions(-) diff --git a/build/premake/premake5.lua b/build/premake/premake5.lua index 0dcf5562f3..55d1e1036e 100644 --- a/build/premake/premake5.lua +++ b/build/premake/premake5.lua @@ -62,19 +62,28 @@ elseif not os.istarget("windows") then end -- detect CPU architecture (simplistic) +-- The user can target an architecture with HOSTTYPE, but the game still selects some know value. arch = "x86" macos_arch = "x86_64" + if _OPTIONS["android"] then arch = "arm" elseif os.istarget("windows") then - if os.getenv("PROCESSOR_ARCHITECTURE") == "amd64" or os.getenv("PROCESSOR_ARCHITEW6432") == "amd64" then + if os.getenv("HOSTTYPE") then + arch = os.getenv("HOSTTYPE") + elseif os.getenv("PROCESSOR_ARCHITECTURE") == "amd64" or os.getenv("PROCESSOR_ARCHITEW6432") == "amd64" then arch = "amd64" end else - os.execute(cc .. " -dumpmachine > .gccmachine.tmp") - local f = io.open(".gccmachine.tmp", "r") - local machine = f:read("*line") - f:close() + local machine = "x86_64" + if os.getenv("HOSTTYPE") and os.getenv("HOSTTYPE") ~= '' then + machine = os.getenv("HOSTTYPE") + else + os.execute(cc .. " -dumpmachine > .gccmachine.tmp") + local f = io.open(".gccmachine.tmp", "r") + machine = f:read("*line") + f:close() + end -- Special handling on mac os where xcode needs special flags. if os.istarget("macosx") then if string.find(machine, "arm64") then diff --git a/libraries/osx/build-osx-libs.sh b/libraries/osx/build-osx-libs.sh index 058d83b6f9..d80c12cd95 100755 --- a/libraries/osx/build-osx-libs.sh +++ b/libraries/osx/build-osx-libs.sh @@ -97,21 +97,16 @@ ARCHLESS_LDFLAGS="$LDFLAGS -stdlib=libc++" # If ARCH isn't set, select either x86_64 or arm64 if [ -z "${ARCH}" ]; then - if [ "`uname -m`" == "arm64" ]; then - ARCH="arm64" - # Some libs want this passed to configure for cross compilation. - HOST_PLATFORM="--host=aarch64-apple-darwin" - else - CXXFLAGS="$CXXFLAGS -msse4.1" - ARCH="x86_64" - # Some libs want this passed to configure for cross compilation. - HOST_PLATFORM="--host=x86_64-apple-darwin" - fi + ARCH=`uname -m` +fi +if [ $ARCH == "arm64" ]; then + # Some libs want this passed to configure for cross compilation. + HOST_PLATFORM="--host=aarch64-apple-darwin" +else + CXXFLAGS="$CXXFLAGS -msse4.1" + # Some libs want this passed to configure for cross compilation. + HOST_PLATFORM="--host=x86_64-apple-darwin" fi - -echo "ARCHITECTURE BREAKDOWN" -echo $ARCH -echo $HOST_PLATFORM CFLAGS="$CFLAGS -arch $ARCH" CXXFLAGS="$CXXFLAGS -arch $ARCH" @@ -463,10 +458,10 @@ then CONF_OPTS="--prefix=$INSTALL_DIR --disable-shared --enable-unicode - --enable-universal_binary=x86_64 --with-cocoa --with-opengl --with-libiconv-prefix=${ICONV_DIR} + --enable-universal-binary=${ARCH} --with-expat=builtin --with-libpng=builtin --without-libtiff @@ -557,7 +552,9 @@ then (./configure CFLAGS="$CFLAGS" LDFLAGS="$LDFLAGS" \ --prefix=$INSTALL_DIR \ + "$HOST_PLATFORM" \ --enable-shared=no \ + --with-harfbuzz=no \ --with-bzip2=no \ --with-brotli=no \ && make ${JOBS} && make install) || die "freetype build failed"