-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
SConstruct
183 lines (153 loc) · 5.95 KB
/
SConstruct
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env python
import os
import sys
import subprocess
if sys.version_info < (3,):
def decode_utf8(x):
return x
else:
import codecs
def decode_utf8(x):
return codecs.utf_8_decode(x)[0]
# Most of the settings are taken from https://github.com/BastiaanOlij/gdnative_cpp_example
opts = Variables([], ARGUMENTS)
# Gets the standard flags CC, CCX, etc.
env = DefaultEnvironment()
# Define our options
opts.Add(EnumVariable('target', "Compilation target", 'debug', ['debug', 'release', "release_debug"]))
opts.Add(EnumVariable('arch', "Compilation Architecture", '', ['', 'arm64', 'armv7', 'x86_64']))
opts.Add(BoolVariable('simulator', "Compilation platform", 'no'))
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bin/'))
opts.Add(EnumVariable('version', 'Godot version to target', '', ['', '3.2', '4.0']))
# Updates the environment with the option variables.
opts.Update(env)
plugin = 'adjust'
# Process some arguments
if env['use_llvm']:
env['CC'] = 'clang'
env['CXX'] = 'clang++'
if env['arch'] == '':
print("No valid arch selected.")
quit();
if env['version'] == '':
print("No valid Godot version selected.")
quit();
# For the reference:
# - CCFLAGS are compilation flags shared between C and C++
# - CFLAGS are for C-specific compilation flags
# - CXXFLAGS are for C++-specific compilation flags
# - CPPFLAGS are for pre-processor flags
# - CPPDEFINES are for pre-processor defines
# - LINKFLAGS are for linking flags
# Enable Obj-C modules
env.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
if env['simulator']:
sdk_name = 'iphonesimulator'
env.Append(CCFLAGS=['-mios-simulator-version-min=10.0'])
env.Append(LINKFLAGS=["-mios-simulator-version-min=10.0"])
else:
sdk_name = 'iphoneos'
env.Append(CCFLAGS=['-miphoneos-version-min=10.0'])
env.Append(LINKFLAGS=["-miphoneos-version-min=10.0"])
try:
sdk_path = decode_utf8(subprocess.check_output(['xcrun', '--sdk', sdk_name, '--show-sdk-path']).strip())
except (subprocess.CalledProcessError, OSError):
raise ValueError("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name))
env.Append(CCFLAGS=[
'-fobjc-arc',
'-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', '-fno-exceptions',
'-Wno-ambiguous-macro',
'-Wall', '-Werror=return-type',
# '-Wextra',
])
env.Append(CCFLAGS=['-arch', env['arch'], "-isysroot", "$IPHONESDK", "-stdlib=libc++", '-isysroot', sdk_path])
env.Append(CCFLAGS=['-DPTRCALL_ENABLED'])
env.Prepend(CXXFLAGS=[
'-DNEED_LONG_INT', '-DLIBYUV_DISABLE_NEON',
'-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DCOREAUDIO_ENABLED'
])
env.Append(LINKFLAGS=["-arch", env['arch'], '-isysroot', sdk_path, '-F' + sdk_path])
if env['arch'] == 'armv7':
env.Prepend(CXXFLAGS=['-fno-aligned-allocation'])
if env['version'] == '3.2':
env.Prepend(CFLAGS=['-std=gnu11'])
env.Prepend(CXXFLAGS=['-DGLES_ENABLED', '-std=gnu++14'])
if env['target'] == 'debug':
env.Prepend(CXXFLAGS=[
'-gdwarf-2', '-O0',
'-DDEBUG_MEMORY_ALLOC', '-DDISABLE_FORCED_INLINE',
'-D_DEBUG', '-DDEBUG=1', '-DDEBUG_ENABLED',
'-DPTRCALL_ENABLED',
])
elif env['target'] == 'release_debug':
env.Prepend(CXXFLAGS=['-O2', '-ftree-vectorize',
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1', '-DDEBUG_ENABLED',
'-DPTRCALL_ENABLED',
])
if env['arch'] != 'armv7':
env.Prepend(CXXFLAGS=['-fomit-frame-pointer'])
else:
env.Prepend(CXXFLAGS=[
'-O2', '-ftree-vectorize',
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1',
'-DPTRCALL_ENABLED',
])
if env['arch'] != 'armv7':
env.Prepend(CXXFLAGS=['-fomit-frame-pointer'])
elif env['version'] == '4.0':
env.Prepend(CFLAGS=['-std=gnu11'])
env.Prepend(CXXFLAGS=['-DVULKAN_ENABLED', '-std=gnu++17'])
if env['target'] == 'debug':
env.Prepend(CXXFLAGS=[
'-gdwarf-2', '-O0',
'-DDEBUG_MEMORY_ALLOC', '-DDISABLE_FORCED_INLINE',
'-D_DEBUG', '-DDEBUG=1', '-DDEBUG_ENABLED',
])
elif env['target'] == 'release_debug':
env.Prepend(CXXFLAGS=[
'-O2', '-ftree-vectorize',
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1', '-DDEBUG_ENABLED',
])
if env['arch'] != 'armv7':
env.Prepend(CXXFLAGS=['-fomit-frame-pointer'])
else:
env.Prepend(CXXFLAGS=[
'-O2', '-ftree-vectorize',
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1',
])
if env['arch'] != 'armv7':
env.Prepend(CXXFLAGS=['-fomit-frame-pointer'])
else:
print("No valid version to set flags for.")
quit();
# Adding header files
env.Append(CPPPATH=[
'.',
'godot',
'godot/main',
'godot/core',
'godot/core/os',
'godot/core/platform',
'godot/platform/iphone',
'godot/modules',
'godot/scene',
'godot/servers',
'godot/drivers',
'godot/thirdparty',
])
# tweak this if you want to use different folders, or more folders, to store your source code in.
sources = Glob(plugin + '/*.cpp')
sources.append(Glob(plugin + '/*.mm'))
sources.append(Glob(plugin + '/*.m'))
env.Append(CXXFLAGS=['-F', plugin])
env.Append(LINKFLAGS = ['-framework', plugin+'/AdjustSdk.framework'])
# lib<plugin>.<arch>-<simulator|iphone>.<release|debug|release_debug>.a
library_platform = env["arch"] + "-" + ("simulator" if env["simulator"] else "iphone")
library_name = plugin + "." + library_platform + "." + env["target"] + ".a"
library = env.StaticLibrary(target=env['target_path'] + library_name, source=sources)
Default(library)
# Generates help for the -h scons option.
Help(opts.GenerateHelpText(env))