Skip to content

Commit d57d0e3

Browse files
committed
Scons plugin setup
1 parent 57571ab commit d57d0e3

File tree

4 files changed

+116
-67
lines changed

4 files changed

+116
-67
lines changed

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
#
33
# gitignore contributors: remember to update Global/Xcode.gitignore, Objective-C.gitignore & Swift.gitignore
44

5+
.DS_Store
6+
57
## User settings
68
xcuserdata/
79

@@ -28,3 +30,7 @@ DerivedData/
2830
*.d
2931
*.o
3032
*.dblite
33+
34+
## Godot Plugins
35+
godot_headers/*
36+
bin/*

SConstruct

Lines changed: 110 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,13 @@ opts = Variables([], ARGUMENTS)
1919
env = DefaultEnvironment()
2020

2121
# Define our options
22-
opts.Add(EnumVariable('target', "Compilation target", 'debug', ['d', 'debug', 'r', 'release']))
23-
opts.Add(EnumVariable('platform', "Compilation platform", '', ['', 'ios']))
24-
opts.Add(EnumVariable('p', "Compilation target, alias for 'platform'", '', ['','ios']))
25-
opts.Add(EnumVariable('arch', "Compilation platform", '', ['', 'arm64', 'armv7', 'x86_64']))
22+
opts.Add(EnumVariable('target', "Compilation target", 'debug', ['debug', 'release', "release_debug"]))
23+
opts.Add(EnumVariable('arch', "Compilation Architecture", '', ['', 'arm64', 'armv7', 'x86_64']))
24+
opts.Add(BoolVariable('simulator', "Compilation platform", 'no'))
2625
opts.Add(BoolVariable('use_llvm', "Use the LLVM / Clang compiler", 'no'))
2726
opts.Add(PathVariable('target_path', 'The path where the lib is installed.', 'bin/'))
28-
opts.Add(PathVariable('target_name', 'The library name.', 'gdexample', PathVariable.PathAccept))
29-
opts.Add(EnumVariable('mode', 'Library build mode', 'static', ['static', 'dynamic']))
27+
opts.Add(EnumVariable('plugin', 'Plugin to build', '', ['', 'arkit', 'camera', 'icloud', 'gamecenter', 'inappstore']))
28+
opts.Add(EnumVariable('version', 'Godot version to target', '', ['', '3.2', '4.0']))
3029

3130
# Local dependency paths, adapt them to your setup
3231
godot_path = "godot/"
@@ -40,11 +39,16 @@ if env['use_llvm']:
4039
env['CC'] = 'clang'
4140
env['CXX'] = 'clang++'
4241

43-
if env['p'] != '':
44-
env['platform'] = env['p']
42+
if env['arch'] == '':
43+
print("No valid arch selected.")
44+
quit();
45+
46+
if env['plugin'] == '':
47+
print("No valid plugin selected.")
48+
quit();
4549

46-
if env['platform'] == '':
47-
print("No valid target platform selected.")
50+
if env['version'] == '':
51+
print("No valid Godot version selected.")
4852
quit();
4953

5054
# For the reference:
@@ -55,72 +59,111 @@ if env['platform'] == '':
5559
# - CPPDEFINES are for pre-processor defines
5660
# - LINKFLAGS are for linking flags
5761

58-
# Check our platform specifics
59-
if env['platform'] == "ios":
60-
env.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
62+
# Enable Obj-C modules
63+
env.Append(CCFLAGS=["-fmodules", "-fcxx-modules"])
64+
65+
if env['simulator']:
66+
sdk_name = 'iphonesimulator'
67+
env.Append(CCFLAGS=['-mios-simulator-version-min=10.0'])
68+
env.Append(LINKFLAGS=["-mios-simulator-version-min=10.0"])
69+
else:
70+
sdk_name = 'iphoneos'
71+
env.Append(CCFLAGS=['-miphoneos-version-min=10.0'])
72+
env.Append(LINKFLAGS=["-miphoneos-version-min=10.0"])
73+
74+
try:
75+
sdk_path = decode_utf8(subprocess.check_output(['xcrun', '--sdk', sdk_name, '--show-sdk-path']).strip())
76+
except (subprocess.CalledProcessError, OSError):
77+
raise ValueError("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name))
78+
79+
env.Append(CCFLAGS=[
80+
'-fobjc-arc',
81+
'-fmessage-length=0', '-fno-strict-aliasing', '-fdiagnostics-print-source-range-info',
82+
'-fdiagnostics-show-category=id', '-fdiagnostics-parseable-fixits', '-fpascal-strings',
83+
'-fblocks', '-fvisibility=hidden', '-MMD', '-MT', 'dependencies', '-fno-exceptions',
84+
'-Wno-ambiguous-macro',
85+
'-Wall', '-Werror=return-type',
86+
# '-Wextra',
87+
])
6188

62-
if env['arch'] == 'x86_64':
63-
sdk_name = 'iphonesimulator'
64-
env.Append(CCFLAGS=['-mios-simulator-version-min=10.0'])
89+
env.Append(CCFLAGS=['-arch', env['arch'], "-isysroot", "$IPHONESDK", "-stdlib=libc++", '-isysroot', sdk_path])
90+
env.Append(CCFLAGS=['-DPTRCALL_ENABLED'])
91+
env.Prepend(CXXFLAGS=[
92+
'-DNEED_LONG_INT', '-DLIBYUV_DISABLE_NEON',
93+
'-DIPHONE_ENABLED', '-DUNIX_ENABLED', '-DCOREAUDIO_ENABLED'
94+
])
95+
env.Append(LINKFLAGS=["-arch", env['arch'], '-isysroot', sdk_path, '-F' + sdk_path])
96+
97+
if env['version'] == '3.2':
98+
env.Prepend(CFLAGS=['-std=gnu11'])
99+
env.Prepend(CXXFLAGS=['-DGLES_ENABLED', '-std=gnu++14'])
100+
101+
if env['target'] == 'debug':
102+
env.Prepend(CXXFLAGS=[
103+
'-gdwarf-2', '-O0',
104+
'-DDEBUG_MEMORY_ALLOC', '-DDISABLE_FORCED_INLINE',
105+
'-D_DEBUG', '-DDEBUG=1', '-DDEBUG_ENABLED',
106+
'-DPTRCALL_ENABLED',
107+
])
108+
elif env['target'] == 'release_debug':
109+
env.Prepend(CXXFLAGS=['-O2', '-ftree-vectorize', '-fomit-frame-pointer',
110+
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1', '-DDEBUG_ENABLED',
111+
'-DPTRCALL_ENABLED',
112+
])
65113
else:
66-
sdk_name = 'iphoneos'
67-
env.Append(CCFLAGS=['-miphoneos-version-min=10.0'])
68-
69-
try:
70-
sdk_path = decode_utf8(subprocess.check_output(['xcrun', '--sdk', sdk_name, '--show-sdk-path']).strip())
71-
except (subprocess.CalledProcessError, OSError):
72-
raise ValueError("Failed to find SDK path while running xcrun --sdk {} --show-sdk-path.".format(sdk_name))
73-
74-
env['target_path'] += 'ios/'
75-
env.Append(CCFLAGS=['-arch', env['arch'], "-isysroot", "$IPHONESDK", "-stdlib=libc++", '-isysroot', sdk_path])
76-
env.Append(CXXFLAGS=['-std=c++17'])
77-
env.Append(CCFLAGS=['-DPTRCALL_ENABLED'])
78-
79-
if env['target'] in ('debug', 'd'):
80-
env.Append(CCFLAGS=['-g', '-O2', '-DDEBUG', '-DDEBUG_ENABLED', '-DDEBUG_MEMORY_ALLOC', '-DDISABLE_FORCED_INLINE', '-DTYPED_METHOD_BIND'])
114+
env.Prepend(CXXFLAGS=[
115+
'-O2', '-ftree-vectorize', '-fomit-frame-pointer',
116+
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1',
117+
'-DPTRCALL_ENABLED',
118+
])
119+
elif env['version'] == '4.0':
120+
env.Prepend(CFLAGS=['-std=gnu11'])
121+
env.Prepend(CXXFLAGS=['-DVULKAN_ENABLED', '-std=gnu++17'])
122+
123+
if env['target'] == 'debug':
124+
env.Prepend(CXXFLAGS=[
125+
'-gdwarf-2', '-O0',
126+
'-DDEBUG_MEMORY_ALLOC', '-DDISABLE_FORCED_INLINE',
127+
'-D_DEBUG', '-DDEBUG=1', '-DDEBUG_ENABLED',
128+
])
129+
elif env['target'] == 'release_debug':
130+
env.Prepend(CXXFLAGS=[
131+
'-O2', '-ftree-vectorize', '-fomit-frame-pointer',
132+
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1', '-DDEBUG_ENABLED',
133+
])
81134
else:
82-
env.Append(CCFLAGS=['-g', '-O3'])
83-
84-
85-
env.Append(
86-
CCFLAGS="-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=10.0".split()
87-
)
88-
env.Append(LINKFLAGS=[])
89-
90-
env.Append(
91-
LINKFLAGS=[
92-
"-arch",
93-
env['arch'],
94-
"-miphoneos-version-min=10.0",
95-
'-isysroot', sdk_path,
96-
'-F' + sdk_path
97-
]
98-
)
99-
100-
# make sure our binding library is properly includes
135+
env.Prepend(CXXFLAGS=[
136+
'-O2', '-ftree-vectorize', '-fomit-frame-pointer',
137+
'-DNDEBUG', '-DNS_BLOCK_ASSERTIONS=1',
138+
])
139+
else:
140+
print("No valid version to set flags for.")
141+
quit();
142+
143+
# Adding header files
101144
env.Append(CPPPATH=[
102145
'.',
103-
godot_path,
104-
godot_path + 'main/',
105-
godot_path + 'core/',
106-
godot_path + 'core/os/',
107-
godot_path + 'core/platform/',
108-
godot_path + 'platform/iphone/',
109-
godot_path + 'modules/',
110-
godot_path + 'scene/',
111-
godot_path + 'servers/',
112-
godot_path + 'drivers/',
113-
godot_path + 'thirdparty/',
146+
'godot_headers',
147+
'godot_headers/main',
148+
'godot_headers/core',
149+
'godot_headers/core/os',
150+
'godot_headers/core/platform',
151+
'godot_headers/platform/iphone',
152+
'godot_headers/modules',
153+
'godot_headers/scene',
154+
'godot_headers/servers',
155+
'godot_headers/drivers',
156+
'godot_headers/thirdparty',
114157
])
115-
env.Append(LIBPATH=[godot_path + 'bin/'])
116-
env.Append(LIBS=[godot_library])
117158

118159
# tweak this if you want to use different folders, or more folders, to store your source code in.
119-
sources = Glob('godot_plugin/*.cpp')
120-
sources.append(Glob("godot_plugin/*.mm"))
121-
sources.append(Glob("godot_plugin/*.m"))
160+
sources = Glob(env['plugin'] + '/*.cpp')
161+
sources.append(Glob(env['plugin'] + '/*.mm'))
162+
sources.append(Glob(env['plugin'] + '/*.m'))
122163

123-
library = env.StaticLibrary(target=env['target_path'] + env['target_name'] , source=sources)
164+
# lib<plugin>.<arch>-<simulator|iphone>.<release|debug|release_debug>.a
165+
library_name = env['plugin'] + "." + env["arch"] + "-" + ("simulator" if env["simulator"] else "iphone") + "." + env["target"] + ".a"
166+
library = env.StaticLibrary(target=env['target_path'] + library_name, source=sources)
124167

125168
Default(library)
126169

bin/dummy

Whitespace-only changes.

godot_headers/dummy

Whitespace-only changes.

0 commit comments

Comments
 (0)