@@ -144,6 +144,9 @@ opts.Add(
144144)
145145opts .Add (BoolVariable ("generate_template_get_node" , "Generate a template version of the Node class's get_node." , True ))
146146
147+ opts .Add (BoolVariable ("build_library" , "Build the godot-cpp library." , True ))
148+ opts .Add ("build_projects" , "List of projects to build (comma-separated list of paths)." , "" )
149+
147150opts .Update (env )
148151Help (opts .GenerateHelpText (env ))
149152
@@ -165,14 +168,21 @@ if host_platform == "windows" and env["platform"] != "android":
165168
166169 opts .Update (env )
167170
171+ # Require C++17
172+ if host_platform == "windows" and env ["platform" ] == "windows" and not env ["use_mingw" ]:
173+ # MSVC
174+ env .Append (CCFLAGS = ["/std:c++17" ])
175+ else :
176+ env .Append (CCFLAGS = ["-std=c++17" ])
177+
168178if env ["target" ] == "debug" :
169179 env .Append (CPPDEFINES = ["DEBUG_ENABLED" , "DEBUG_METHODS_ENABLED" ])
170180
171181if env ["platform" ] == "linux" or env ["platform" ] == "freebsd" :
172182 if env ["use_llvm" ]:
173183 env ["CXX" ] = "clang++"
174184
175- env .Append (CCFLAGS = ["-fPIC" , "-std=c++17" , "- Wwrite-strings" ])
185+ env .Append (CCFLAGS = ["-fPIC" , "-Wwrite-strings" ])
176186 env .Append (LINKFLAGS = ["-Wl,-R,'$$ORIGIN'" ])
177187
178188 if env ["target" ] == "debug" :
@@ -201,8 +211,6 @@ elif env["platform"] == "osx":
201211 env .Append (LINKFLAGS = ["-arch" , env ["macos_arch" ]])
202212 env .Append (CCFLAGS = ["-arch" , env ["macos_arch" ]])
203213
204- env .Append (CCFLAGS = ["-std=c++17" ])
205-
206214 if env ["macos_deployment_target" ] != "default" :
207215 env .Append (CCFLAGS = ["-mmacosx-version-min=" + env ["macos_deployment_target" ]])
208216 env .Append (LINKFLAGS = ["-mmacosx-version-min=" + env ["macos_deployment_target" ]])
@@ -245,14 +253,13 @@ elif env["platform"] == "ios":
245253 env ["CXX" ] = compiler_path + "clang++"
246254 env ["AR" ] = compiler_path + "ar"
247255 env ["RANLIB" ] = compiler_path + "ranlib"
256+ env ["SHLIBSUFFIX" ] = ".dylib"
248257
249- env .Append (CCFLAGS = ["-std=c++17" , "- arch" , env ["ios_arch" ], "-isysroot" , sdk_path ])
258+ env .Append (CCFLAGS = ["-arch" , env ["ios_arch" ], "-isysroot" , sdk_path ])
250259 env .Append (
251260 LINKFLAGS = [
252261 "-arch" ,
253262 env ["ios_arch" ],
254- "-framework" ,
255- "Cocoa" ,
256263 "-Wl,-undefined,dynamic_lookup" ,
257264 "-isysroot" ,
258265 sdk_path ,
@@ -292,14 +299,21 @@ elif env["platform"] == "windows":
292299 # Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
293300 env = Environment (ENV = os .environ , tools = ["mingw" ])
294301 opts .Update (env )
295- # env = env.Clone(tools=['mingw'])
296302
303+ # Still need to use C++17.
304+ env .Append (CCFLAGS = ["-std=c++17" ])
305+ # Don't want lib prefixes
306+ env ["IMPLIBPREFIX" ] = ""
307+ env ["SHLIBPREFIX" ] = ""
308+
309+ # Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
297310 env ["SPAWN" ] = mySpawn
311+ env .Replace (ARFLAGS = ["q" ])
298312
299313 # Native or cross-compilation using MinGW
300314 if host_platform == "linux" or host_platform == "freebsd" or host_platform == "osx" or env ["use_mingw" ]:
301315 # These options are for a release build even using target=debug
302- env .Append (CCFLAGS = ["-O3" , "-std=c++17" , "- Wwrite-strings" ])
316+ env .Append (CCFLAGS = ["-O3" , "-Wwrite-strings" ])
303317 env .Append (
304318 LINKFLAGS = [
305319 "--static" ,
@@ -314,9 +328,10 @@ elif env["platform"] == "android":
314328 # Don't Clone the environment. Because otherwise, SCons will pick up msvc stuff.
315329 env = Environment (ENV = os .environ , tools = ["mingw" ])
316330 opts .Update (env )
317- # env = env.Clone(tools=['mingw'])
318331
332+ # Long line hack. Use custom spawn, quick AR append (to avoid files with the same names to override each other).
319333 env ["SPAWN" ] = mySpawn
334+ env .Replace (ARFLAGS = ["q" ])
320335
321336 # Verify NDK root
322337 if not "ANDROID_NDK_ROOT" in env :
@@ -382,11 +397,13 @@ elif env["platform"] == "android":
382397 env ["CC" ] = toolchain + "/bin/clang"
383398 env ["CXX" ] = toolchain + "/bin/clang++"
384399 env ["AR" ] = toolchain + "/bin/" + arch_info ["tool_path" ] + "-ar"
400+ env ["SHLIBSUFFIX" ] = ".so"
385401
386402 env .Append (
387403 CCFLAGS = ["--target=" + arch_info ["target" ] + env ["android_api_level" ], "-march=" + arch_info ["march" ], "-fPIC" ]
388404 ) # , '-fPIE', '-fno-addrsig', '-Oz'])
389405 env .Append (CCFLAGS = arch_info ["ccflags" ])
406+ env .Append (LINKFLAGS = ["--target=" + arch_info ["target" ] + env ["android_api_level" ], "-march=" + arch_info ["march" ]])
390407
391408 if env ["target" ] == "debug" :
392409 env .Append (CCFLAGS = ["-Og" , "-g" ])
@@ -474,8 +491,16 @@ elif env["platform"] == "javascript":
474491elif env ["platform" ] == "osx" :
475492 arch_suffix = env ["macos_arch" ]
476493
477- library = env .StaticLibrary (
478- target = "bin/" + "libgodot-cpp.{}.{}.{}{}" .format (env ["platform" ], env ["target" ], arch_suffix , env ["LIBSUFFIX" ]),
479- source = sources ,
480- )
481- Default (library )
494+ library = None
495+ env ["OBJSUFFIX" ] = ".{}.{}.{}{}" .format (env ["platform" ], env ["target" ], arch_suffix , env ["OBJSUFFIX" ])
496+ library_name = "libgodot-cpp.{}.{}.{}{}" .format (env ["platform" ], env ["target" ], arch_suffix , env ["LIBSUFFIX" ])
497+
498+ if env ["build_library" ]:
499+ library = env .StaticLibrary (target = env .File ("bin/%s" % library_name ), source = sources )
500+ Default (library )
501+
502+ env ["SHLIBSUFFIX" ] = "{}.{}.{}{}" .format (env ["platform" ], env ["target" ], arch_suffix , env ["SHLIBSUFFIX" ])
503+ env .Append (CPPPATH = [env .Dir (f ) for f in ["gen/include" , "include" , "godot-headers" ]])
504+ env .Append (LIBPATH = [env .Dir ("bin" )])
505+ env .Append (LIBS = library_name )
506+ Return ("env" )
0 commit comments