10
10
import subprocess
11
11
import sys
12
12
import hashlib
13
+ import platform
13
14
from logger import get_logger
14
15
from amd_hipify import amd_hipify
15
-
16
+ from distutils . version import StrictVersion
16
17
17
18
SCRIPT_DIR = os .path .dirname (os .path .realpath (__file__ ))
18
19
REPO_DIR = os .path .normpath (os .path .join (SCRIPT_DIR , ".." , ".." ))
@@ -285,7 +286,9 @@ def parse_arguments():
285
286
"--use_xcode" , action = 'store_true' ,
286
287
help = "Use Xcode as cmake generator, this is only supported on MacOS." )
287
288
parser .add_argument (
288
- "--osx_arch" , default = "arm64" , choices = ["arm64" , "x86_64" ],
289
+ "--osx_arch" ,
290
+ default = "arm64" if platform .machine () == "arm64" else "x86_64" ,
291
+ choices = ["arm64" , "x86_64" ],
289
292
help = "Specify the Target specific architectures for macOS and iOS, This is only supported on MacOS" )
290
293
parser .add_argument (
291
294
"--apple_deploy_target" , type = str ,
@@ -845,6 +848,13 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home
845
848
if args .android_cpp_shared :
846
849
cmake_args += ["-DANDROID_STL=c++_shared" ]
847
850
851
+ if is_macOS () and not args .android :
852
+ cmake_args += ["-DCMAKE_OSX_ARCHITECTURES=" + args .osx_arch ]
853
+ # since cmake 3.19, it uses the xcode latest buildsystem, which is not supported by this project.
854
+ cmake_verstr = subprocess .check_output (['cmake' , '--version' ]).decode ('utf-8' ).split ()[2 ]
855
+ if args .use_xcode and StrictVersion (cmake_verstr ) >= StrictVersion ('3.19.0' ):
856
+ cmake_args += ["-T" , "buildsystem=1" ]
857
+
848
858
if args .ios :
849
859
if is_macOS ():
850
860
needed_args = [
@@ -870,7 +880,6 @@ def generate_build_tree(cmake_path, source_dir, build_dir, cuda_home, cudnn_home
870
880
"-DCMAKE_SYSTEM_NAME=iOS" ,
871
881
"-Donnxruntime_BUILD_SHARED_LIB=ON" ,
872
882
"-DCMAKE_OSX_SYSROOT=" + args .ios_sysroot ,
873
- "-DCMAKE_OSX_ARCHITECTURES=" + args .osx_arch ,
874
883
"-DCMAKE_OSX_DEPLOYMENT_TARGET=" + args .apple_deploy_target ,
875
884
# we do not need protoc binary for ios cross build
876
885
"-Dprotobuf_BUILD_PROTOC_BINARIES=OFF" ,
@@ -1735,9 +1744,8 @@ def build_protoc_for_host(cmake_path, source_dir, build_dir, args):
1735
1744
# CMake < 3.18 has a bug setting system arch to arm64 (if not specified) for Xcode 12,
1736
1745
# protoc for host should be built using host architecture
1737
1746
# Explicitly specify the CMAKE_OSX_ARCHITECTURES for x86_64 Mac.
1738
- import platform
1739
- if platform .machine () == 'x86_64' :
1740
- cmd_args += ['-DCMAKE_OSX_ARCHITECTURES=x86_64' ]
1747
+ cmd_args += ["-DCMAKE_OSX_ARCHITECTURES={}" .format (
1748
+ 'arm64' if platform .machine () == 'arm64' else 'x86_64' )]
1741
1749
1742
1750
run_subprocess (cmd_args , cwd = protoc_build_dir )
1743
1751
# Build step
0 commit comments