@@ -159,6 +159,8 @@ opts.Add(
159159 )
160160)
161161
162+ opts .Add (BoolVariable ("build_library" , "Build the godot-cpp library." , True ))
163+
162164opts .Update (env )
163165Help (opts .GenerateHelpText (env ))
164166
@@ -173,11 +175,18 @@ if host_platform == "windows" and env["platform"] != "android":
173175
174176 opts .Update (env )
175177
178+ # Require C++14
179+ if host_platform == "windows" and env ["platform" ] == "windows" and not env ["use_mingw" ]:
180+ # MSVC
181+ env .Append (CCFLAGS = ["/std:c++14" ])
182+ else :
183+ env .Append (CCFLAGS = ["-std=c++14" ])
184+
176185if env ["platform" ] == "linux" or env ["platform" ] == "freebsd" :
177186 if env ["use_llvm" ]:
178187 env ["CXX" ] = "clang++"
179188
180- env .Append (CCFLAGS = ["-fPIC" , "-std=c++14" , "- Wwrite-strings" ])
189+ env .Append (CCFLAGS = ["-fPIC" , "-Wwrite-strings" ])
181190 env .Append (LINKFLAGS = ["-Wl,-R,'$$ORIGIN'" ])
182191
183192 if env ["target" ] == "debug" :
@@ -206,8 +215,6 @@ elif env["platform"] == "osx":
206215 env .Append (LINKFLAGS = ["-arch" , env ["macos_arch" ]])
207216 env .Append (CCFLAGS = ["-arch" , env ["macos_arch" ]])
208217
209- env .Append (CCFLAGS = ["-std=c++14" ])
210-
211218 if env ["macos_deployment_target" ] != "default" :
212219 env .Append (CCFLAGS = ["-mmacosx-version-min=" + env ["macos_deployment_target" ]])
213220 env .Append (LINKFLAGS = ["-mmacosx-version-min=" + env ["macos_deployment_target" ]])
@@ -216,13 +223,7 @@ elif env["platform"] == "osx":
216223 env .Append (CCFLAGS = ["-isysroot" , env ["macos_sdk_path" ]])
217224 env .Append (LINKFLAGS = ["-isysroot" , env ["macos_sdk_path" ]])
218225
219- env .Append (
220- LINKFLAGS = [
221- "-framework" ,
222- "Cocoa" ,
223- "-Wl,-undefined,dynamic_lookup" ,
224- ]
225- )
226+ env .Append (LINKFLAGS = ["-Wl,-undefined,dynamic_lookup" ])
226227
227228 if env ["target" ] == "debug" :
228229 env .Append (CCFLAGS = ["-Og" , "-g" ])
@@ -233,7 +234,6 @@ elif env["platform"] == "ios":
233234 if env ["ios_simulator" ]:
234235 sdk_name = "iphonesimulator"
235236 env .Append (CCFLAGS = ["-mios-simulator-version-min=10.0" ])
236- env ["LIBSUFFIX" ] = ".simulator" + env ["LIBSUFFIX" ]
237237 else :
238238 sdk_name = "iphoneos"
239239 env .Append (CCFLAGS = ["-miphoneos-version-min=10.0" ])
@@ -250,14 +250,13 @@ elif env["platform"] == "ios":
250250 env ["CXX" ] = compiler_path + "clang++"
251251 env ["AR" ] = compiler_path + "ar"
252252 env ["RANLIB" ] = compiler_path + "ranlib"
253+ env ["SHLIBSUFFIX" ] = ".dylib"
253254
254- env .Append (CCFLAGS = ["-std=c++14" , "- arch" , env ["ios_arch" ], "-isysroot" , sdk_path ])
255+ env .Append (CCFLAGS = ["-arch" , env ["ios_arch" ], "-isysroot" , sdk_path ])
255256 env .Append (
256257 LINKFLAGS = [
257258 "-arch" ,
258259 env ["ios_arch" ],
259- "-framework" ,
260- "Cocoa" ,
261260 "-Wl,-undefined,dynamic_lookup" ,
262261 "-isysroot" ,
263262 sdk_path ,
@@ -296,14 +295,20 @@ elif env["platform"] == "windows":
296295 # Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
297296 env = Environment (ENV = os .environ , tools = ["mingw" ])
298297 opts .Update (env )
299- # env = env.Clone(tools=['mingw'])
298+
299+ # Still need to use C++14.
300+ env .Append (CCFLAGS = ["-std=c++14" ])
301+ # Don't want lib prefixes
302+ env ["IMPLIBPREFIX" ] = ""
303+ env ["SHLIBPREFIX" ] = ""
300304
301305 env ["SPAWN" ] = mySpawn
306+ env .Replace (ARFLAGS = ["q" ])
302307
303308 # Native or cross-compilation using MinGW
304309 if host_platform == "linux" or host_platform == "freebsd" or host_platform == "osx" or env ["use_mingw" ]:
305310 # These options are for a release build even using target=debug
306- env .Append (CCFLAGS = ["-O3" , "-std=c++14" , "- Wwrite-strings" ])
311+ env .Append (CCFLAGS = ["-O3" , "-Wwrite-strings" ])
307312 env .Append (
308313 LINKFLAGS = [
309314 "--static" ,
@@ -318,9 +323,10 @@ elif env["platform"] == "android":
318323 # Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
319324 env = Environment (ENV = os .environ , tools = ["mingw" ])
320325 opts .Update (env )
321- # env = env.Clone(tools=['mingw'])
322326
327+ # Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
323328 env ["SPAWN" ] = mySpawn
329+ env .Replace (ARFLAGS = ["q" ])
324330
325331 # Verify NDK root
326332 if not "ANDROID_NDK_ROOT" in env :
@@ -385,11 +391,12 @@ elif env["platform"] == "android":
385391 # Setup tools
386392 env ["CC" ] = toolchain + "/bin/clang"
387393 env ["CXX" ] = toolchain + "/bin/clang++"
388- env ["AR" ] = toolchain + "/bin/" + arch_info ["tool_path" ] + "-ar"
389- env ["AS" ] = toolchain + "/bin/" + arch_info ["tool_path" ] + "-as"
390- env ["LD" ] = toolchain + "/bin/" + arch_info ["tool_path" ] + "-ld"
391- env ["STRIP" ] = toolchain + "/bin/" + arch_info ["tool_path" ] + "-strip"
392- env ["RANLIB" ] = toolchain + "/bin/" + arch_info ["tool_path" ] + "-ranlib"
394+ env ["AR" ] = toolchain + "/bin/llvm-ar"
395+ env ["AS" ] = toolchain + "/bin/llvm-as"
396+ env ["LD" ] = toolchain + "/bin/llvm-ld"
397+ env ["STRIP" ] = toolchain + "/bin/llvm-strip"
398+ env ["RANLIB" ] = toolchain + "/bin/llvm-ranlib"
399+ env ["SHLIBSUFFIX" ] = ".so"
393400
394401 env .Append (
395402 CCFLAGS = [
@@ -399,6 +406,7 @@ elif env["platform"] == "android":
399406 ]
400407 )
401408 env .Append (CCFLAGS = arch_info ["ccflags" ])
409+ env .Append (LINKFLAGS = ["--target=" + arch_info ["target" ] + env ["android_api_level" ], "-march=" + arch_info ["march" ]])
402410
403411 if env ["target" ] == "debug" :
404412 env .Append (CCFLAGS = ["-Og" , "-g" ])
@@ -478,14 +486,25 @@ if env["platform"] == "android":
478486 arch_suffix = env ["android_arch" ]
479487elif env ["platform" ] == "ios" :
480488 arch_suffix = env ["ios_arch" ]
489+ if env ["ios_simulator" ]:
490+ arch_suffix += ".simulator"
481491elif env ["platform" ] == "osx" :
482492 if env ["macos_arch" ] != "universal" :
483493 arch_suffix = env ["macos_arch" ]
484494elif env ["platform" ] == "javascript" :
485495 arch_suffix = "wasm"
496+ # Expose it to projects that import this env.
497+ env ["arch_suffix" ] = arch_suffix
486498
487- library = env .StaticLibrary (
488- target = "bin/" + "libgodot-cpp.{}.{}.{}{}" .format (env ["platform" ], env ["target" ], arch_suffix , env ["LIBSUFFIX" ]),
489- source = sources ,
490- )
491- Default (library )
499+ library = None
500+ env ["OBJSUFFIX" ] = ".{}.{}.{}{}" .format (env ["platform" ], env ["target" ], arch_suffix , env ["OBJSUFFIX" ])
501+ library_name = "libgodot-cpp.{}.{}.{}{}" .format (env ["platform" ], env ["target" ], arch_suffix , env ["LIBSUFFIX" ])
502+
503+ if env ["build_library" ]:
504+ library = env .StaticLibrary (target = env .File ("bin/%s" % library_name ), source = sources )
505+ Default (library )
506+
507+ env .Append (CPPPATH = [env .Dir (f ) for f in [env ["headers_dir" ], "include" , "include/gen" , "include/core" ]])
508+ env .Append (LIBPATH = [env .Dir ("bin" )])
509+ env .Append (LIBS = library_name )
510+ Return ("env" )
0 commit comments