forked from Unity-Technologies/com.autodesk.fbx
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.py
executable file
·163 lines (132 loc) · 5.8 KB
/
build.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
#!/usr/bin/python -B
import argparse
import shutil
import os
import subprocess
import sys
parser = argparse.ArgumentParser(description='Parse the options')
parser.add_argument('--swig', type=str, dest='swig_location', help='Root location of the swig executable')
parser.add_argument('--fbxsdk', type=str, dest='fbxsdk_location', help='location of the FBX SDK')
parser.add_argument('-s', '--stevedore', action='store_true', dest='use_stevedore', help='Use stevedore (used for internal builds)')
parser.add_argument('-n', '--ninja', action='store_true', dest='use_ninja', help='Generate Ninja build files')
parser.add_argument('-t', '--build_type', default='Release', dest='build_type', help='Build type to do (Release, Debug, ...)')
parser.add_argument('-z', '--zap', '-c', '--clean', action='store_true', dest='clean_build', help='Removes the build directory')
parser.add_argument('-v', '--verbose', action='store_true', dest='verbose_build', help='Make CMake verbose')
parser.add_argument('--yamato', action='store_true', dest='yamato_build', help='Used internally for CI')
args = parser.parse_args()
curdir = os.path.dirname(os.path.abspath(__file__))
builddir = os.path.join(curdir, 'build')
# Clean the build?
if args.clean_build and os.path.exists(builddir):
print("Deleting build directory..")
shutil.rmtree(builddir)
if not os.path.exists(builddir):
os.mkdir(builddir)
# Set the executable name
if sys.platform.startswith('win'):
shell = True
cmake_exe = 'cmake.exe'
else:
cmake_exe = 'cmake'
shell = False
# Minimal configuration
config_args = [
cmake_exe,
'..', # because the working directory is the "build" directory, go back
'-DCMAKE_SOURCE_DIR={}'.format(curdir),
'-DCMAKE_BUILD_TYPE={}'.format(args.build_type),
'-DCMAKE_INSTALL_PREFIX={}'.format(os.path.join(builddir, 'install')),
'-DCMAKE_OSX_ARCHITECTURES=arm64',
]
# Where to find swig if not standard install
if args.swig_location is not None:
config_args.append('-DSWIG_EXECUTABLE={}'.format(args.swig_location))
# config_args.append(args.swig_location)
if args.fbxsdk_location is not None:
config_args.append('-DFBXSDK_ROOT_PATH={}'.format(args.fbxsdk_location))
# Use Stevedore?
config_args.append('-DUSE_STEVEDORE' + ('=ON' if args.use_stevedore else '=OFF'))
# Is a CI build?
config_args.append('-DYAMATO' + ('=ON' if args.yamato_build else '=OFF'))
# Generator selection
config_args.append('-G')
if args.use_ninja:
config_args.append('Ninja')
else:
if sys.platform.startswith('win'):
config_args.append('Visual Studio 16 2019')
config_args.append('-Ax64')
else:
config_args.append('Unix Makefiles')
# Remove this if you're a build system dev
config_args.append('-Wno-dev')
# Do the config
print(' '.join(config_args))
retcode = subprocess.check_call(config_args, stderr=subprocess.STDOUT, shell=shell, cwd=builddir)
if retcode != 0:
sys.exit(retcode)
# And do the build
build_args= [
cmake_exe,
'--build',
'.',
'--target',
'install',
'--config',
args.build_type
]
if args.verbose_build and (args.use_ninja or sys.platform.startswith('win')):
build_args.append('--verbose')
env = None
# Mac and Linux SWIG were compiled and have hard coded paths to swig.swg.
# Set the correct location in the environment for the build, since the
# configure is able to set it for itself.
if args.use_stevedore and not sys.platform.startswith('win'):
env = os.environ
def find(name, path):
'''
https://stackoverflow.com/a/1724723
'''
for root, dirs, files in os.walk(path):
if name in files:
# we need only the directory
return root
env["SWIG_LIB"] = find('swig.swg', builddir)
print(build_args)
retcode = subprocess.check_call(build_args, stderr=subprocess.STDOUT, shell=shell, cwd=builddir, env=env)
if retcode != 0:
sys.exit(retcode)
if sys.platform.startswith('darwin'):
# On Mac build two binaries (one that works on arm and one x86_64 that works on 10.13+).
# The arm binary is already built, here we build the second one and combine the two with lipo
# use a different build directory
builddir_legacy = os.path.join(curdir, 'build_legacy_mac')
if args.clean_build and os.path.exists(builddir_legacy):
shutil.rmtree(builddir_legacy)
if not os.path.exists(builddir_legacy):
os.mkdir(builddir_legacy)
install_prefix = '-DCMAKE_INSTALL_PREFIX={}'.format(os.path.join(builddir_legacy, 'install'))
# use all the same config args except the install prefix
config_args = [a for a in config_args if not (a.startswith("-DCMAKE_INSTALL_PREFIX") or a.startswith("-DCMAKE_OSX_ARCHITECTURES"))]
config_args.append(install_prefix)
config_args.append('-DCMAKE_OSX_ARCHITECTURES=x86_64')
retcode = subprocess.check_call(config_args, stderr=subprocess.STDOUT, shell=shell, cwd=builddir_legacy)
if retcode != 0:
sys.exit(retcode)
retcode = subprocess.check_call(build_args, stderr=subprocess.STDOUT, shell=shell, cwd=builddir_legacy, env=env)
if retcode != 0:
sys.exit(retcode)
# combine the arm build and the legacy build with lipo
bundle_path = "install/com.autodesk.fbx/Editor/Plugins/UnityFbxSdkNative.bundle/Contents/MacOS/UnityFbxSdkNative"
bundle_name = "UnityFbxSdkNative"
arm_bundle = os.path.join(builddir, bundle_path)
legacy_bundle = os.path.join(builddir_legacy, bundle_path)
lipo_call = ["lipo", "-create", "-output", bundle_name, arm_bundle, legacy_bundle]
retcode = subprocess.check_call(lipo_call, stderr=subprocess.STDOUT, shell=shell, cwd=curdir, env=env)
if retcode != 0:
sys.exit(retcode)
# replace the arm bundle with the universal binary
src = os.path.join(curdir, bundle_name)
dst = arm_bundle
shutil.copyfile(src, dst)
sys.exit(retcode)