11import os
22import sys
33import subprocess
4+ import ios_osxcross
45from SCons .Variables import *
56
67if sys .version_info < (3 ,):
@@ -17,15 +18,18 @@ def decode_utf8(x):
1718
1819def options (opts ):
1920 opts .Add (BoolVariable ("ios_simulator" , "Target iOS Simulator" , False ))
21+ opts .Add ("ios_min_version" , "Target minimum iphoneos/iphonesimulator version" , "10.0" )
2022 opts .Add (
2123 "IPHONEPATH" ,
2224 "Path to iPhone toolchain" ,
2325 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain" ,
2426 )
27+ opts .Add ("IPHONESDK" , "Path to the iPhone SDK" , "" )
28+ ios_osxcross .options (opts )
2529
2630
2731def exists (env ):
28- return sys .platform == "darwin"
32+ return sys .platform == "darwin" or ios_osxcross . exists ( env )
2933
3034
3135def generate (env ):
@@ -35,24 +39,32 @@ def generate(env):
3539
3640 if env ["ios_simulator" ]:
3741 sdk_name = "iphonesimulator"
38- env .Append (CCFLAGS = ["-mios-simulator-version-min=10.0" ])
42+ env .Append (CCFLAGS = ["-mios-simulator-version-min=" + env [ "ios_min_version" ] ])
3943 else :
4044 sdk_name = "iphoneos"
41- env .Append (CCFLAGS = ["-miphoneos-version-min=10.0" ])
45+ env .Append (CCFLAGS = ["-miphoneos-version-min=" + env ["ios_min_version" ]])
46+
47+ if sys .platform == "darwin" :
48+ if env ["IPHONESDK" ] == "" :
49+ try :
50+ env ["IPHONESDK" ] = decode_utf8 (
51+ subprocess .check_output (["xcrun" , "--sdk" , sdk_name , "--show-sdk-path" ]).strip ()
52+ )
53+ except (subprocess .CalledProcessError , OSError ):
54+ raise ValueError (
55+ "Failed to find SDK path while running xcrun --sdk {} --show-sdk-path." .format (sdk_name )
56+ )
57+
58+ compiler_path = env ["IPHONEPATH" ] + "/usr/bin/"
59+ env ["CC" ] = compiler_path + "clang"
60+ env ["CXX" ] = compiler_path + "clang++"
61+ env ["AR" ] = compiler_path + "ar"
62+ env ["RANLIB" ] = compiler_path + "ranlib"
63+ env ["SHLIBSUFFIX" ] = ".dylib"
64+ env ["ENV" ]["PATH" ] = env ["IPHONEPATH" ] + "/Developer/usr/bin/:" + env ["ENV" ]["PATH" ]
4265
43- try :
44- sdk_path = decode_utf8 (subprocess .check_output (["xcrun" , "--sdk" , sdk_name , "--show-sdk-path" ]).strip ())
45- except (subprocess .CalledProcessError , OSError ):
46- raise ValueError ("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path." .format (sdk_name ))
47-
48- compiler_path = env ["IPHONEPATH" ] + "/usr/bin/"
49- env ["ENV" ]["PATH" ] = env ["IPHONEPATH" ] + "/Developer/usr/bin/:" + env ["ENV" ]["PATH" ]
50-
51- env ["CC" ] = compiler_path + "clang"
52- env ["CXX" ] = compiler_path + "clang++"
53- env ["AR" ] = compiler_path + "ar"
54- env ["RANLIB" ] = compiler_path + "ranlib"
55- env ["SHLIBSUFFIX" ] = ".dylib"
66+ else :
67+ ios_osxcross .generate (env )
5668
5769 if env ["arch" ] == "universal" :
5870 if env ["ios_simulator" ]:
@@ -65,8 +77,8 @@ def generate(env):
6577 env .Append (LINKFLAGS = ["-arch" , env ["arch" ]])
6678 env .Append (CCFLAGS = ["-arch" , env ["arch" ]])
6779
68- env .Append (CCFLAGS = ["-isysroot" , sdk_path ])
69- env .Append (LINKFLAGS = ["-isysroot" , sdk_path , "-F" + sdk_path ])
80+ env .Append (CCFLAGS = ["-isysroot" , env [ "IPHONESDK" ] ])
81+ env .Append (LINKFLAGS = ["-isysroot" , env [ "IPHONESDK" ] , "-F" + env [ "IPHONESDK" ] ])
7082
7183 if env ["target" ] == "debug" :
7284 env .Append (CCFLAGS = ["-Og" , "-g" ])
0 commit comments