-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSConstruct
More file actions
228 lines (192 loc) · 7.23 KB
/
SConstruct
File metadata and controls
228 lines (192 loc) · 7.23 KB
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
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
#!/usr/bin/env python
import os
import sys
import subprocess
env = SConscript("godot-cpp/SConstruct")
# Add our source include paths
env.Append(CPPPATH=["src/", "libopenmpt/"])
# Determine libopenmpt build target
if env["platform"] == "macos":
libopenmpt_config = "macos"
elif env["platform"] == "windows":
libopenmpt_config = "mingw-w64"
else:
libopenmpt_config = "gcc"
libopenmpt_target = "debug" if env["target"] == "template_debug" else "release"
# Build libopenmpt library if it doesn't exist
libopenmpt_lib_dir = "libopenmpt/bin"
libopenmpt_lib_name = "libopenmpt.a" # MinGW uses .a files like Unix
libopenmpt_lib_path = os.path.join(libopenmpt_lib_dir, libopenmpt_lib_name)
def build_libopenmpt(target, source, env):
"""Build libopenmpt using its Makefile"""
# Determine architecture
arch = env.get("arch", "universal")
# Build for each architecture if universal
if arch == "universal" and env["platform"] == "macos":
archs = ["arm64", "x86_64"]
lib_files = []
for single_arch in archs:
print(f"Building libopenmpt for {single_arch}...")
build_cmd = [
"make",
"-C", "libopenmpt",
"clean",
]
subprocess.run(build_cmd, capture_output=True)
build_cmd = [
"make",
"-C", "libopenmpt",
f"CONFIG={libopenmpt_config}",
"STATIC_LIB=1",
"SHARED_LIB=0",
"EXAMPLES=0",
"OPENMPT123=0",
"TEST=0",
"NO_ZLIB=1",
"NO_MPG123=1",
"NO_OGG=1",
"NO_VORBIS=1",
"NO_VORBISFILE=1",
"NO_MINIZ=1",
"NO_MINIMP3=1",
"NO_STBVORBIS=1",
"NO_PORTAUDIO=1",
"NO_PORTAUDIOCPP=1",
"NO_PULSEAUDIO=1",
"NO_SDL2=1",
"NO_FLAC=1",
"NO_SNDFILE=1",
]
# Add architecture-specific flags via environment
env_vars = os.environ.copy()
env_vars['CXXFLAGS'] = f"-arch {single_arch}"
env_vars['CFLAGS'] = f"-arch {single_arch}"
env_vars['LDFLAGS'] = f"-arch {single_arch}"
build_cmd.append('STDCXX=c++20')
if env["target"] == "template_debug":
build_cmd.append("DEBUG=1")
else:
build_cmd.append("DEBUG=0")
build_cmd.append("OPTIMIZE=speed")
print(f"Command: {' '.join(build_cmd)}")
result = subprocess.run(build_cmd, capture_output=False, env=env_vars)
if result.returncode != 0:
print(f"ERROR: Failed to build libopenmpt for {single_arch}")
return result.returncode
# Copy the built library
lib_file = f"libopenmpt/bin/libopenmpt_{single_arch}.a"
subprocess.run(["cp", "libopenmpt/bin/libopenmpt.a", lib_file])
lib_files.append(lib_file)
# Create universal binary with lipo
print("Creating universal binary...")
lipo_cmd = ["lipo", "-create"] + lib_files + ["-output", str(target[0])]
result = subprocess.run(lipo_cmd)
if result.returncode != 0:
print("ERROR: Failed to create universal binary")
return result.returncode
return 0
else:
# Single architecture build
build_cmd = [
"make",
"-C", "libopenmpt",
f"CONFIG={libopenmpt_config}",
"STATIC_LIB=1",
"SHARED_LIB=0",
"EXAMPLES=0",
"OPENMPT123=0",
"TEST=0",
"NO_ZLIB=1",
"NO_MPG123=1",
"NO_OGG=1",
"NO_VORBIS=1",
"NO_VORBISFILE=1",
"NO_MINIZ=1",
"NO_MINIMP3=1",
"NO_STBVORBIS=1",
"NO_PORTAUDIO=1",
"NO_PORTAUDIOCPP=1",
"NO_PULSEAUDIO=1",
"NO_SDL2=1",
"NO_FLAC=1",
"NO_SNDFILE=1",
]
# Add Windows architecture specification
if env["platform"] == "windows":
if env.get("arch") == "x86_64":
build_cmd.append("WINDOWS_ARCH=amd64")
elif env.get("arch") == "x86_32":
build_cmd.append("WINDOWS_ARCH=x86")
if env["target"] == "template_debug":
build_cmd.append("DEBUG=1")
else:
build_cmd.append("DEBUG=0")
build_cmd.append("OPTIMIZE=speed")
# Set up environment variables for the build
env_vars = os.environ.copy()
if env["platform"] == "windows":
env_vars['AR'] = 'ar'
print(f"Building libopenmpt: {' '.join(build_cmd)}")
result = subprocess.run(build_cmd, capture_output=False, env=env_vars)
if result.returncode != 0:
print("ERROR: Failed to build libopenmpt")
return result.returncode
# Copy to target location if different
if str(target[0]) != "libopenmpt/bin/libopenmpt.a":
subprocess.run(["cp", "libopenmpt/bin/libopenmpt.a", str(target[0])])
return 0
# Check if libopenmpt library exists, if not build it
if not os.path.exists(libopenmpt_lib_path):
print(f"libopenmpt library not found at {libopenmpt_lib_path}, building...")
# Create a dummy builder to trigger libopenmpt build
libopenmpt_builder = env.Command(
libopenmpt_lib_path,
"libopenmpt/Makefile",
build_libopenmpt
)
env.Depends("src/audio_stream_openmpt.cpp", libopenmpt_builder)
else:
print(f"Using existing libopenmpt library: {libopenmpt_lib_path}")
# Link against libopenmpt static library
env.Append(LIBPATH=[libopenmpt_lib_dir])
env.Append(LIBS=["openmpt"])
# Add C++ standard library for libopenmpt
if env["platform"] == "macos":
env.Append(LIBS=["c++"])
elif env["platform"] == "linux":
env.Append(LIBS=["stdc++"])
elif env["platform"] == "windows":
env.Append(LIBS=["stdc++"])
# Add our GDExtension source files
sources = Glob("src/*.cpp")
# Check if tests should be built
build_tests = ARGUMENTS.get("tests", "no") == "yes"
# Prepare source list
lib_sources = list(sources)
if build_tests:
# Enable tests in the build
env.Append(CPPDEFINES=["TESTS_ENABLED"])
env.Append(CPPPATH=["tests/doctest"])
# Add test interface sources
lib_sources.extend(["tests/test_interface.cpp", "tests/test_audio_stream.cpp"])
# Add documentation for Godot 4.3+
if env["target"] in ["editor", "template_debug"]:
try:
doc_data = env.GodotCPPDocData("src/gen/doc_data.gen.cpp", source=Glob("doc_classes/*.xml"))
lib_sources.append(doc_data)
except AttributeError:
print("Not including class reference as we're targeting a pre-4.3 baseline.")
# Create the library
if env["platform"] == "macos":
library = env.SharedLibrary(
"addons/libopenmpt/libopenmpt.{}.{}.framework/libopenmpt.{}.{}".format(
env["platform"], env["target"], env["platform"], env["target"]
),
source=lib_sources,
)
else:
library = env.SharedLibrary(
"addons/libopenmpt/libopenmpt{}{}".format(env["suffix"], env["SHLIBSUFFIX"]),
source=lib_sources,
)
Default(library)