11#!/usr/bin/env python 
2- import   os 
3- import   sys 
2+ 
3+ Import ( "env" ) 
44
55# default values, adapt them to your setup 
66default_library_name  =  "libgdexample" 
@@ -10,71 +10,20 @@ default_target_path = "demo/bin/"
1010cpp_bindings_path  =  "../" 
1111# cpp_bindings_path = "godot-cpp/" 
1212godot_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 )
2913
3014opts  =  Variables ([], ARGUMENTS )
3115
3216# Define our options 
33- opts .Add (EnumVariable ("target" , "Compilation target" , "debug" , allowed_values = ("debug" , "release" ), ignorecase = 2 ))
3417opts .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" ),
42-         ignorecase = 2 ,
43-     )
18+     PathVariable ("target_path" , "The path where the lib is installed." , default_target_path , PathVariable .PathAccept )
4419)
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 (PathVariable ("target_path" , "The path where the lib is installed." , default_target_path , PathVariable .PathAccept ))
4820opts .Add (PathVariable ("target_name" , "The library name." , default_library_name , PathVariable .PathAccept ))
4921
50- # only support 64 at this time.. 
51- bits  =  64 
52- 
5322# Updates the environment with the option variables. 
5423opts .Update (env )
5524# Generates help for the -h scons option. 
5625Help (opts .GenerateHelpText (env ))
5726
58- # This makes sure to keep the session environment variables on Windows. 
59- # This way, you can run SCons in a Visual Studio 2017 prompt and it will find 
60- # all the required tools 
61- if  host_platform  ==  "windows"  and  env ["platform" ] !=  "android" :
62-     if  env ["bits" ] ==  "64" :
63-         env  =  Environment (TARGET_ARCH = "amd64" )
64-     elif  env ["bits" ] ==  "32" :
65-         env  =  Environment (TARGET_ARCH = "x86" )
66- 
67-     opts .Update (env )
68- 
69- # Process some arguments 
70- if  env ["use_llvm" ]:
71-     env ["CC" ] =  "clang" 
72-     env ["CXX" ] =  "clang++" 
73- 
74- if  env ["platform" ] ==  "" :
75-     print ("No valid target platform selected." )
76-     quit ()
77- 
7827# For the reference: 
7928# - CCFLAGS are compilation flags shared between C and C++ 
8029# - CFLAGS are for C-specific compilation flags 
@@ -83,67 +32,11 @@ if env["platform"] == "":
8332# - CPPDEFINES are for pre-processor defines 
8433# - LINKFLAGS are for linking flags 
8534
86- if  env ["target" ] ==  "debug" :
87-     env .Append (CPPDEFINES = ["DEBUG_ENABLED" , "DEBUG_METHODS_ENABLED" ])
88- 
89- # Check our platform specifics 
90- if  env ["platform" ] ==  "osx" :
91-     env ["target_path" ] +=  "osx/" 
92-     cpp_library  +=  ".osx" 
93-     env .Append (CCFLAGS = ["-arch" , "x86_64" ])
94-     env .Append (CXXFLAGS = ["-std=c++17" ])
95-     env .Append (LINKFLAGS = ["-arch" , "x86_64" ])
96-     if  env ["target" ] ==  "debug" :
97-         env .Append (CCFLAGS = ["-g" , "-O2" ])
98-     else :
99-         env .Append (CCFLAGS = ["-g" , "-O3" ])
100- 
101- elif  env ["platform" ] in  ("x11" , "linux" ):
102-     cpp_library  +=  ".linux" 
103-     env .Append (CCFLAGS = ["-fPIC" ])
104-     env .Append (CXXFLAGS = ["-std=c++17" ])
105-     if  env ["target" ] ==  "debug" :
106-         env .Append (CCFLAGS = ["-g3" , "-Og" ])
107-     else :
108-         env .Append (CCFLAGS = ["-g" , "-O3" ])
109- 
110- elif  env ["platform" ] ==  "windows" :
111-     cpp_library  +=  ".windows" 
112-     # This makes sure to keep the session environment variables on windows, 
113-     # that way you can run scons in a vs 2017 prompt and it will find all the required tools 
114-     env .Append (ENV = os .environ )
115- 
116-     env .Append (CPPDEFINES = ["WIN32" , "_WIN32" , "_WINDOWS" , "_CRT_SECURE_NO_WARNINGS" ])
117-     env .Append (CCFLAGS = ["-W3" , "-GR" ])
118-     env .Append (CXXFLAGS = ["-std:c++17" ])
119-     if  env ["target" ] ==  "debug" :
120-         env .Append (CPPDEFINES = ["_DEBUG" ])
121-         env .Append (CCFLAGS = ["-EHsc" , "-MDd" , "-ZI" , "-FS" ])
122-         env .Append (LINKFLAGS = ["-DEBUG" ])
123-     else :
124-         env .Append (CPPDEFINES = ["NDEBUG" ])
125-         env .Append (CCFLAGS = ["-O2" , "-EHsc" , "-MD" ])
126- 
127-     if  not (env ["use_llvm" ]):
128-         env .Append (CPPDEFINES = ["TYPED_METHOD_BIND" ])
129- 
130- # determine our architecture suffix 
131- arch_suffix  =  str (bits )
132- 
133- # suffix our godot-cpp library 
134- cpp_library  +=  "."  +  env ["target" ] +  "."  +  arch_suffix 
135- 
136- # make sure our binding library is properly includes 
137- env .Append (CPPPATH = ["." , godot_headers_path , cpp_bindings_path  +  "include/" , cpp_bindings_path  +  "gen/include/" ])
138- env .Append (LIBPATH = [cpp_bindings_path  +  "bin/" ])
139- env .Append (LIBS = [cpp_library ])
140- 
14135# tweak this if you want to use different folders, or more folders, to store your source code in. 
14236env .Append (CPPPATH = ["src/" ])
14337sources  =  Glob ("src/*.cpp" )
14438
145- target_name  =  "{}.{}.{}.{}" .format (env ["target_name" ], env ["platform" ], env ["target" ], arch_suffix )
146- print (target_name )
39+ target_name  =  "{}{}" .format (env ["target_name" ], env ["SHLIBSUFFIX" ])
14740library  =  env .SharedLibrary (target = env ["target_path" ] +  target_name , source = sources )
14841
14942Default (library )
0 commit comments