From 362464463015fa4e6690e5733fa3ee0be11fa32f Mon Sep 17 00:00:00 2001 From: Alexandru Croitor Date: Fri, 24 Aug 2018 02:03:57 +0200 Subject: [PATCH] Pass -isysroot to compiler / linker when doing a macOS build Previously the compiler would use system headers located at /System/Library/Frameworks, which could result in compilation failures due to the headers not always being up-to-date in regards to the latest installed macOS SDK headers that come with Xcode. Fix the issue by passing the SDK path via the -isysroot option to the compiler and linker invocations. If no custom SDK path is given, the build system queries the SDK path via xcrun --show-sdk-path, which returns something similar to /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/ /Developer/SDKs/MacOSX.sdk/ Querying via xcrun is now also done for iphone (and simulator) platforms as well. Here is an example of a compilation failure message due to outdated headers: platform/osx/os_osx.mm:1421:41: error: use of undeclared identifier 'NSAppKitVersionNumber10_12'; did you mean 'NSAppKitVersionNumber'? if (floor(NSAppKitVersionNumber) >= NSAppKitVersionNumber10_12) { ^~~~~~~~~~~~~~~~~~~~~~~~~~ NSAppKitVersionNumber /System/Library/Frameworks/AppKit.framework/Headers/NSApplication.h:26:28: note: 'NSAppKitVersionNumber' declared here --- methods.py | 24 ++++++++++++++++++++++++ platform/iphone/detect.py | 9 +++++---- platform/osx/detect.py | 6 ++++++ 3 files changed, 35 insertions(+), 4 deletions(-) diff --git a/methods.py b/methods.py index e9450d95e2f..23761b521a4 100644 --- a/methods.py +++ b/methods.py @@ -613,3 +613,27 @@ def CommandNoCache(env, target, sources, command, **args): result = env.Command(target, sources, command, **args) env.NoCache(result) return result + +def detect_darwin_sdk_path(platform, env): + sdk_name = '' + if platform == 'osx': + sdk_name = 'macosx' + var_name = 'MACOS_SDK_PATH' + elif platform == 'iphone': + sdk_name = 'iphoneos' + var_name = 'IPHONESDK' + elif platform == 'iphonesimulator': + sdk_name = 'iphonesimulator' + var_name = 'IPHONESDK' + else: + raise Exception("Invalid platform argument passed to detect_darwin_sdk_path") + + if not env[var_name]: + try: + sdk_path = subprocess.check_output(['xcrun', '--sdk', sdk_name, '--show-sdk-path']).strip() + if sdk_path: + env[var_name] = sdk_path + except (subprocess.CalledProcessError, OSError) as e: + print("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name)) + raise + diff --git a/platform/iphone/detect.py b/platform/iphone/detect.py index b13a1e96435..8da7117077b 100644 --- a/platform/iphone/detect.py +++ b/platform/iphone/detect.py @@ -1,7 +1,7 @@ import os import string import sys - +from methods import detect_darwin_sdk_path def is_active(): return True @@ -22,9 +22,8 @@ def can_build(): def get_opts(): from SCons.Variables import BoolVariable return [ - ('IPHONEPLATFORM', 'Name of the iPhone platform', 'iPhoneOS'), ('IPHONEPATH', 'Path to iPhone toolchain', '/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain'), - ('IPHONESDK', 'Path to the iPhone SDK', '/Applications/Xcode.app/Contents/Developer/Platforms/${IPHONEPLATFORM}.platform/Developer/SDKs/${IPHONEPLATFORM}.sdk/'), + ('IPHONESDK', 'Path to the iPhone SDK', ''), BoolVariable('game_center', 'Support for game center', True), BoolVariable('store_kit', 'Support for in-app store', True), BoolVariable('icloud', 'Support for iCloud', True), @@ -103,13 +102,15 @@ def configure(env): ## Compile flags if (env["arch"] == "x86" or env["arch"] == "x86_64"): - env['IPHONEPLATFORM'] = 'iPhoneSimulator' + detect_darwin_sdk_path('iphonesimulator', env) env['ENV']['MACOSX_DEPLOYMENT_TARGET'] = '10.9' arch_flag = "i386" if env["arch"] == "x86" else env["arch"] env.Append(CCFLAGS=('-arch ' + arch_flag + ' -fobjc-abi-version=2 -fobjc-legacy-dispatch -fmessage-length=0 -fpascal-strings -fblocks -fasm-blocks -isysroot $IPHONESDK -mios-simulator-version-min=9.0 -DCUSTOM_MATRIX_TRANSFORM_H=\\\"build/iphone/matrix4_iphone.h\\\" -DCUSTOM_VECTOR3_TRANSFORM_H=\\\"build/iphone/vector3_iphone.h\\\"').split()) elif (env["arch"] == "arm"): + detect_darwin_sdk_path('iphone', env) env.Append(CCFLAGS='-fno-objc-arc -arch armv7 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -isysroot $IPHONESDK -fvisibility=hidden -mthumb "-DIBOutlet=__attribute__((iboutlet))" "-DIBOutletCollection(ClassName)=__attribute__((iboutletcollection(ClassName)))" "-DIBAction=void)__attribute__((ibaction)" -miphoneos-version-min=9.0 -MMD -MT dependencies'.split()) elif (env["arch"] == "arm64"): + detect_darwin_sdk_path('iphone', env) env.Append(CCFLAGS='-fno-objc-arc -arch arm64 -fmessage-length=0 -fno-strict-aliasing -fdiagnostics-print-source-range-info -fdiagnostics-show-category=id -fdiagnostics-parseable-fixits -fpascal-strings -fblocks -fvisibility=hidden -MMD -MT dependencies -miphoneos-version-min=9.0 -isysroot $IPHONESDK'.split()) env.Append(CPPFLAGS=['-DNEED_LONG_INT']) env.Append(CPPFLAGS=['-DLIBYUV_DISABLE_NEON']) diff --git a/platform/osx/detect.py b/platform/osx/detect.py index 8a0883eca3c..72a57b4e875 100644 --- a/platform/osx/detect.py +++ b/platform/osx/detect.py @@ -1,5 +1,6 @@ import os import sys +from methods import detect_darwin_sdk_path def is_active(): @@ -23,6 +24,7 @@ def get_opts(): return [ ('osxcross_sdk', 'OSXCross SDK version', 'darwin14'), + ('MACOS_SDK_PATH', 'Path to the macOS SDK', ''), EnumVariable('debug_symbols', 'Add debugging symbols to release builds', 'yes', ('yes', 'no', 'full')), BoolVariable('separate_debug_symbols', 'Create a separate file containing debugging symbols', False), ] @@ -84,6 +86,10 @@ def configure(env): env['AS'] = mpprefix + "/libexec/llvm-" + mpclangver + "/bin/llvm-as" env.Append(CCFLAGS=['-D__MACPORTS__']) #hack to fix libvpx MM256_BROADCASTSI128_SI256 define + detect_darwin_sdk_path('osx', env) + env.Append(CPPFLAGS=['-isysroot', '$MACOS_SDK_PATH']) + env.Append(LINKFLAGS=['-isysroot', '$MACOS_SDK_PATH']) + else: # osxcross build root = os.environ.get("OSXCROSS_ROOT", 0) basecmd = root + "/target/bin/x86_64-apple-" + env["osxcross_sdk"] + "-"