22import os
33import sys
44
5- # default values, adapt them to your setup
6- default_library_name = "libgdexample"
7- default_target_path = "demo/bin/"
8-
9- # Local dependency paths, adapt them to your setup
10- cpp_bindings_path = "../"
11- # cpp_bindings_path = "godot-cpp/"
12- godot_headers_path = cpp_bindings_path + "godot-headers/"
13- cpp_library = "libgodot-cpp"
14-
15- # Try to detect the host platform automatically.
16- # This is used if no `platform` argument is passed
17- if sys .platform .startswith ("linux" ):
18- host_platform = "linux"
19- elif sys .platform .startswith ("freebsd" ):
20- host_platform = "freebsd"
21- elif sys .platform == "darwin" :
22- host_platform = "osx"
23- elif sys .platform == "win32" or sys .platform == "msys" :
24- host_platform = "windows"
25- else :
26- raise ValueError ("Could not detect platform automatically, please specify with " "platform=<platform>" )
27-
28- env = Environment (ENV = os .environ )
29-
30- opts = Variables ([], ARGUMENTS )
31-
32- # Define our options
33- opts .Add (EnumVariable ("target" , "Compilation target" , "debug" , allowed_values = ("debug" , "release" ), ignorecase = 2 ))
34- opts .Add (
35- EnumVariable (
36- "platform" ,
37- "Compilation platform" ,
38- host_platform ,
39- # We'll need to support these in due times
40- # allowed_values=("linux", "freebsd", "osx", "windows", "android", "ios", "javascript"),
41- allowed_values = ("linux" , "windows" , "osx" ),
42- ignorecase = 2 ,
43- )
44- )
45- opts .Add (EnumVariable ("bits" , "Target platform bits" , "64" , ("32" , "64" )))
46- opts .Add (BoolVariable ("use_llvm" , "Use the LLVM / Clang compiler" , "no" ))
47- opts .Add (EnumVariable ("macos_arch" , "Target macOS architecture" , "universal" , ["universal" , "x86_64" , "arm64" ]))
48- opts .Add (PathVariable ("target_path" , "The path where the lib is installed." , default_target_path , PathVariable .PathAccept ))
49- opts .Add (PathVariable ("target_name" , "The library name." , default_library_name , PathVariable .PathAccept ))
50-
51- # only support 64 at this time..
52- bits = 64
53-
54- # Updates the environment with the option variables.
55- opts .Update (env )
56- # Generates help for the -h scons option.
57- Help (opts .GenerateHelpText (env ))
58-
59- # This makes sure to keep the session environment variables on Windows.
60- # This way, you can run SCons in a Visual Studio 2017 prompt and it will find
61- # all the required tools
62- if host_platform == "windows" and env ["platform" ] != "android" :
63- if env ["bits" ] == "64" :
64- env = Environment (TARGET_ARCH = "amd64" )
65- elif env ["bits" ] == "32" :
66- env = Environment (TARGET_ARCH = "x86" )
67-
68- opts .Update (env )
69-
70- # Process some arguments
71- if env ["use_llvm" ]:
72- env ["CC" ] = "clang"
73- env ["CXX" ] = "clang++"
74-
75- if env ["platform" ] == "" :
76- print ("No valid target platform selected." )
77- quit ()
5+ env = SConscript ("../SConstruct" )
786
797# For the reference:
808# - CCFLAGS are compilation flags shared between C and C++
@@ -84,82 +12,10 @@ if env["platform"] == "":
8412# - CPPDEFINES are for pre-processor defines
8513# - LINKFLAGS are for linking flags
8614
87- if env ["target" ] == "debug" :
88- env .Append (CPPDEFINES = ["DEBUG_ENABLED" , "DEBUG_METHODS_ENABLED" ])
89-
90- # Check our platform specifics
91- if env ["platform" ] == "osx" :
92- env ["target_path" ] += "{}.{}.framework/" .format (env ["target_name" ], env ["target" ])
93- cpp_library += ".osx"
94-
95- if env ["bits" ] == "32" :
96- raise ValueError ("Only 64-bit builds are supported for the macOS target." )
97-
98- if env ["macos_arch" ] == "universal" :
99- env .Append (LINKFLAGS = ["-arch" , "x86_64" , "-arch" , "arm64" ])
100- env .Append (CCFLAGS = ["-arch" , "x86_64" , "-arch" , "arm64" ])
101- else :
102- env .Append (LINKFLAGS = ["-arch" , env ["macos_arch" ]])
103- env .Append (CCFLAGS = ["-arch" , env ["macos_arch" ]])
104-
105- env .Append (CXXFLAGS = ["-std=c++17" ])
106- if env ["target" ] == "debug" :
107- env .Append (CCFLAGS = ["-g" , "-O2" ])
108- else :
109- env .Append (CCFLAGS = ["-g" , "-O3" ])
110-
111- arch_suffix = env ["macos_arch" ]
112-
113- elif env ["platform" ] in ("x11" , "linux" ):
114- cpp_library += ".linux"
115- env .Append (CCFLAGS = ["-fPIC" ])
116- env .Append (CXXFLAGS = ["-std=c++17" ])
117- if env ["target" ] == "debug" :
118- env .Append (CCFLAGS = ["-g3" , "-Og" ])
119- else :
120- env .Append (CCFLAGS = ["-g" , "-O3" ])
121-
122- arch_suffix = str (bits )
123- elif env ["platform" ] == "windows" :
124- cpp_library += ".windows"
125- # This makes sure to keep the session environment variables on windows,
126- # that way you can run scons in a vs 2017 prompt and it will find all the required tools
127- env .Append (ENV = os .environ )
128-
129- env .Append (CPPDEFINES = ["WIN32" , "_WIN32" , "_WINDOWS" , "_CRT_SECURE_NO_WARNINGS" ])
130- env .Append (CCFLAGS = ["-W3" , "-GR" ])
131- env .Append (CXXFLAGS = ["-std:c++17" ])
132- if env ["target" ] == "debug" :
133- env .Append (CPPDEFINES = ["_DEBUG" ])
134- env .Append (CCFLAGS = ["-EHsc" , "-MDd" , "-ZI" , "-FS" ])
135- env .Append (LINKFLAGS = ["-DEBUG" ])
136- else :
137- env .Append (CPPDEFINES = ["NDEBUG" ])
138- env .Append (CCFLAGS = ["-O2" , "-EHsc" , "-MD" ])
139-
140- if not (env ["use_llvm" ]):
141- env .Append (CPPDEFINES = ["TYPED_METHOD_BIND" ])
142-
143- arch_suffix = str (bits )
144-
145- # suffix our godot-cpp library
146- cpp_library += "." + env ["target" ] + "." + arch_suffix
147-
148- # make sure our binding library is properly includes
149- env .Append (CPPPATH = ["." , godot_headers_path , cpp_bindings_path + "include/" , cpp_bindings_path + "gen/include/" ])
150- env .Append (LIBPATH = [cpp_bindings_path + "bin/" ])
151- env .Append (LIBS = [cpp_library ])
152-
15315# tweak this if you want to use different folders, or more folders, to store your source code in.
15416env .Append (CPPPATH = ["src/" ])
15517sources = Glob ("src/*.cpp" )
15618
157- if env ["platform" ] == "osx" :
158- target_name = "{}.{}" .format (env ["target_name" ], env ["target" ])
159- else :
160- target_name = "{}.{}.{}.{}" .format (env ["target_name" ], env ["platform" ], env ["target" ], arch_suffix )
161-
162- print (target_name )
163- library = env .SharedLibrary (target = env ["target_path" ] + target_name , source = sources )
19+ library = env .SharedLibrary ("demo/bin/libgdexample" + env ["SHLIBSUFFIX" ], source = sources )
16420
16521Default (library )
0 commit comments