Fix issue in Rocket.lua script.
[Cafu-Engine.git] / SConstruct
blobd352d53375b364fc5ca2528a59b21c538e96ff16
1 import codecs, os, platform, shutil, sys, time
4 # See the SCons manual, http://www.scons.org/wiki/GoFastButton and the man page for more information about the next two lines.
5 Decider("MD5-timestamp")
6 SetOption("implicit_cache", 1)
8 # Print an empty line, so that there is a better visual separation at the command line between successive calls.
9 print("")
12 try:
13 import CompilerSetup
14 except ImportError:
15 # In order to make getting started with the Cafu source code more convenient, install the
16 # CompilerSetup.py file from the related template file (which is under version control) automatically.
17 shutil.copy("CompilerSetup.py.tmpl", "CompilerSetup.py")
18 import CompilerSetup
21 def FixFormatting(Filename, Lines):
22 with codecs.open(Filename, encoding='utf-8', errors='strict', mode='wb') as f:
23 for l in Lines:
24 f.write(l.replace("\t", " ").rstrip() + "\n")
27 def CheckFormatting(start_dir, QuickMode):
28 """
29 This function checks for common problems such as trailing whitespace, TABs,
30 improper encoding (non-UTF8), no EOL at end of file, and mixed(!) EOL styles
31 within a single file.
32 Files whose newline style does not match the operating system's default are
33 accounted for statistics, but not counted as errors.
34 """
35 t1 = time.time()
36 CheckedCount = 0
37 ProblemsCount = 0
38 c_NewL_Dos = 0
39 c_NewL_Unix = 0
41 QuickCount = 0
42 QuickRefCO = 0 # For excluding newly checked-out files.
43 QuickRefOld = time.time() - 3600 * 24 * 7 # For excluding too old files.
45 if QuickMode:
46 try:
47 QuickRefCO = os.path.getmtime(".gitattributes") + 3600
48 except:
49 print('Could not determine mtime for ".gitattributes".')
51 for root, dirs, files in os.walk(start_dir):
52 # print root, dirs
54 if not dirs and not files:
55 print(root, "is empty")
57 for filename in files:
58 if os.path.splitext(filename)[1] in [".h", ".hpp", ".c", ".cpp", ".lua", ".py", ".cmat", ".cgui", ""] or filename in ["CMakeLists.txt"]:
59 pathname = os.path.join(root, filename)
61 if QuickMode:
62 ts = os.path.getmtime(pathname)
63 if ts < QuickRefOld or ts < QuickRefCO:
64 QuickCount += 1
65 continue
67 CheckedCount += 1
69 try:
70 with codecs.open(pathname, encoding='utf-8', errors='strict') as f:
71 Lines = f.readlines()
73 c = {
74 "tabs": 0,
75 "NewL_Dos": 0,
76 "NewL_Unix": 0,
77 "NewL_Mac": 0,
78 "NewL_Other": 0,
79 "trailing_ws": 0,
82 for line in Lines:
83 if "\t" in line:
84 c["tabs"] += 1
86 if line.endswith("\r\n"):
87 c["NewL_Dos"] += 1
88 elif line.endswith("\n"):
89 c["NewL_Unix"] += 1
90 elif line.endswith("\r"):
91 c["NewL_Mac"] += 1
92 else:
93 # Note that "no newline at end of file" is a special case of this!
94 c["NewL_Other"] += 1
96 if line.rstrip("\r\n").endswith(" "):
97 c["trailing_ws"] += 1
99 if c["NewL_Dos" ]: c_NewL_Dos += 1
100 if c["NewL_Unix"]: c_NewL_Unix += 1
102 if c["tabs"] or c["trailing_ws"] or c["NewL_Mac"] or c["NewL_Other"] or (c["NewL_Dos"] and c["NewL_Unix"]):
103 print(pathname, c)
104 if False:
105 FixFormatting(pathname, Lines)
106 ProblemsCount += 1
108 except UnicodeDecodeError:
109 if filename in ["MainMenu_init.cgui", "MainMenu_main.cgui"]:
110 continue
112 print(pathname, "is not properly UTF-8 encoded")
113 ProblemsCount += 1
114 # subprocess.Popen(["iconv", "-f", "iso-8859-1", "-t", "utf-8", pathname, "-o", "xy.tmp"]).wait()
115 # subprocess.Popen(["mv", "-f", "xy.tmp", pathname]).wait()
117 for excl in ["FontWizard", "wxExt", "wxFB"]:
118 if "CaWE" in root and excl in dirs:
119 dirs.remove(excl)
121 for excl in [".git", ".svn", ".sconf_temp", "build", "docs", "ExtLibs", "out", ".vs"]:
122 if excl in dirs:
123 dirs.remove(excl)
125 t2 = time.time()
127 if ProblemsCount:
128 print("")
130 if QuickCount:
131 print("{} source files checked in {:.2f}s ({} files skipped due to quick mode).".format(CheckedCount, t2 - t1, QuickCount))
132 else:
133 print("{} source files checked in {:.2f}s.".format(CheckedCount, t2 - t1))
135 if c_NewL_Dos and c_NewL_Unix:
136 print("Files with DOS-style newlines:", c_NewL_Dos)
137 print("Files with Unix-style newlines:", c_NewL_Unix)
139 if ProblemsCount:
140 print("\nError: The formatting of the above {} indicated source files is unexpected.".format(ProblemsCount))
141 Exit(1)
143 print("")
146 if hasattr(CompilerSetup, "checkSourceFormatting") and CompilerSetup.checkSourceFormatting:
147 CheckFormatting(".", CompilerSetup.checkSourceFormatting == "quick")
150 # Import the (user-configured) base environment from the setup file.
151 # The base environment is evaluated and further refined (e.g. with compiler-specific settings) below.
152 envCommon = CompilerSetup.envCommon
155 # Add a Builder to envCommon that expects a Value node as its source, and builds the target from the contents
156 # of the source node: If the source value changes, the target file is re-built. See the section about Value()
157 # in the SCons man page and http://thread.gmane.org/gmane.comp.programming.tools.scons.user/23752 for details.
158 def BuildFileFromValue(env, target, source):
159 with open(str(target[0]), 'w') as f:
160 f.write(source[0].get_contents())
162 envCommon['BUILDERS']['FileFromValue'] = envCommon.Builder(action=BuildFileFromValue)
165 # A custom check to determine if the C++ compiler supports the C++11 `override` identifier.
166 def CheckOverrideIdentifier(context):
167 source = """
168 class A
170 public:
172 virtual int f() const { return 1; }
175 class B : public A
177 public:
179 int f() const override { return 2; }
182 int main()
184 return 0;
188 context.Message("Checking for C++11 `override` identifier... ")
189 result = context.TryLink(source, '.cpp')
190 context.Result(result)
191 return result
194 # This big if-else tree has a branch for each supported platform and each supported compiler.
195 # For the chosen combination of platform and compiler, it prepares the environments envDebug, envRelease and envProfile.
196 if sys.platform=="win32":
197 # Under Windows, there are no system copies of these libraries, so instead we use our own local copies.
198 # Setting these paths in envCommon means that they are "globally" available everywhere, but this is ok:
199 # Under Linux, all library headers are globally available (e.g. at /usr/include/) as well.
200 envCommon.Append(CPPPATH=["#/ExtLibs/freetype/include"])
201 envCommon.Append(CPPPATH=["#/ExtLibs/libpng"])
202 envCommon.Append(CPPPATH=["#/ExtLibs/zlib"])
204 if envCommon["MSVC_VERSION"] in ["8.0", "8.0Exp"]:
205 ##############################
206 ### Win32, Visual C++ 2005 ###
207 ##############################
209 compiler="vc8"
211 # Reference of commonly used compiler switches:
212 # /EHsc Enable exception handling.
213 # /GR Enable RTTI.
214 # /J Treat char as unsigned char.
215 # /MT Use multi-threaded run-time libraries (statically linked into the exe). Defines _MT.
216 # /MTd Use multi-threaded debug run-time libraries (statically linked into the exe). Defines _DEBUG and _MT.
217 # /Od Disable optimizations.
218 # /O2 Fastest possible code.
219 # /Ob2 Inline expansion at compilers discretion.
220 # /RTC1 Run-Time Error Checks: Catch release-build errors in debug build.
221 # /W3 Warning level.
222 # /WX Treat warnings as errors.
223 # /Z7 Include full debug info.
225 # Begin with an environment with settings that are common for debug, release and profile builds.
226 envCommon.Append(CCFLAGS = Split("/GR /EHsc")) # CCFLAGS is also taken as the default value for CXXFLAGS.
227 envCommon.Append(CPPDEFINES = ["_CRT_SECURE_NO_DEPRECATE", "_CRT_NONSTDC_NO_DEPRECATE"])
228 envCommon.Append(LINKFLAGS = Split("/incremental:no"))
230 # Explicitly instruct SCons to detect and use the Microsoft Platform SDK, as it is not among the default tools.
231 # See thread "Scons 2010/01/17 doesn't look for MS SDK?" at <http://scons.tigris.org/ds/viewMessage.do?dsForumId=1272&dsMessageId=2455554>
232 # for further information.
233 envCommon.Tool('mssdk')
235 # Environment for debug builds:
236 envDebug=envCommon.Clone();
237 envDebug.Append(CCFLAGS=Split("/MDd /Od /Z7 /RTC1"));
238 envDebug.Append(LINKFLAGS=["/debug"]);
240 # Environment for release builds:
241 envRelease=envCommon.Clone();
242 envRelease.Append(CCFLAGS=Split("/MD /O2 /Ob2"));
244 # Environment for profile builds:
245 envProfile=envCommon.Clone();
246 envProfile.Append(CCFLAGS=Split("/MD /O2 /Ob2 /Z7"));
247 envProfile.Append(LINKFLAGS=["/fixed:no", "/debug"]);
249 elif envCommon["MSVC_VERSION"] in ["9.0", "9.0Exp"]:
250 ##############################
251 ### Win32, Visual C++ 2008 ###
252 ##############################
254 compiler="vc9"
256 # Reference of commonly used compiler switches:
257 # Identical to the compiler switches for Visual C++ 2005, see there for more details.
259 # Begin with an environment with settings that are common for debug, release and profile builds.
260 envCommon.Append(CCFLAGS = Split("/GR /EHsc")) # CCFLAGS is also taken as the default value for CXXFLAGS.
261 envCommon.Append(CPPDEFINES = ["_CRT_SECURE_NO_DEPRECATE", "_CRT_NONSTDC_NO_DEPRECATE"])
262 envCommon.Append(LINKFLAGS = Split("/incremental:no"))
264 # Explicitly instruct SCons to detect and use the Microsoft Platform SDK, as it is not among the default tools.
265 # See thread "Scons 2010/01/17 doesn't look for MS SDK?" at <http://scons.tigris.org/ds/viewMessage.do?dsForumId=1272&dsMessageId=2455554>
266 # for further information.
267 envCommon.Tool('mssdk')
269 # This is a temporary workaround for SCons bug <http://scons.tigris.org/issues/show_bug.cgi?id=2663>.
270 # It should be removed again as soon as the bug is fixed in SCons.
271 if envCommon["TARGET_ARCH"] in ["x86_64", "amd64", "emt64"]:
272 envCommon["ENV"]["LIB"] = envCommon["ENV"]["LIB"].replace("C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0\\lib;", "C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0\\lib\\x64;");
273 envCommon["ENV"]["LIBPATH"] = envCommon["ENV"]["LIBPATH"].replace("C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0\\lib;", "C:\\Program Files\\Microsoft SDKs\\Windows\\v7.0\\lib\\x64;");
275 # Environment for debug builds:
276 envDebug=envCommon.Clone();
277 envDebug.Append(CCFLAGS=Split("/MDd /Od /Z7 /RTC1"));
278 envDebug.Append(LINKFLAGS=["/debug"]);
280 # Environment for release builds:
281 envRelease=envCommon.Clone();
282 envRelease.Append(CCFLAGS=Split("/MD /O2 /Ob2"));
284 # Environment for profile builds:
285 envProfile=envCommon.Clone();
286 envProfile.Append(CCFLAGS=Split("/MD /O2 /Ob2 /Z7"));
287 envProfile.Append(LINKFLAGS=["/fixed:no", "/debug"]);
289 elif envCommon["MSVC_VERSION"] in ["10.0", "10.0Exp"]:
290 ##############################
291 ### Win32, Visual C++ 2010 ###
292 ##############################
294 compiler="vc10"
296 # Reference of commonly used compiler switches:
297 # Identical to the compiler switches for Visual C++ 2005, see there for more details.
299 # Begin with an environment with settings that are common for debug, release and profile builds.
300 envCommon.Append(CCFLAGS = Split("/GR /EHsc")) # CCFLAGS is also taken as the default value for CXXFLAGS.
301 envCommon.Append(CPPDEFINES = ["_CRT_SECURE_NO_DEPRECATE", "_CRT_NONSTDC_NO_DEPRECATE"])
302 envCommon.Append(LINKFLAGS = Split("/incremental:no"))
304 # Explicitly instruct SCons to detect and use the Microsoft Platform SDK, as it is not among the default tools.
305 # See thread "Scons 2010/01/17 doesn't look for MS SDK?" at <http://scons.tigris.org/ds/viewMessage.do?dsForumId=1272&dsMessageId=2455554>
306 # for further information.
307 envCommon.Tool('mssdk')
309 # Environment for debug builds:
310 envDebug=envCommon.Clone();
311 envDebug.Append(CCFLAGS=Split("/MDd /Od /Z7 /RTC1"));
312 envDebug.Append(LINKFLAGS=["/debug"]);
314 # Environment for release builds:
315 envRelease=envCommon.Clone();
316 envRelease.Append(CCFLAGS=Split("/MD /O2 /Ob2"));
318 # Environment for profile builds:
319 envProfile=envCommon.Clone();
320 envProfile.Append(CCFLAGS=Split("/MD /O2 /Ob2 /Z7"));
321 envProfile.Append(LINKFLAGS=["/fixed:no", "/debug"]);
323 elif envCommon["MSVC_VERSION"] in ["11.0", "11.0Exp"]:
324 ##############################
325 ### Win32, Visual C++ 2012 ###
326 ##############################
328 compiler="vc11"
330 # Reference of commonly used compiler switches:
331 # Identical to the compiler switches for Visual C++ 2005, see there for more details.
333 # Begin with an environment with settings that are common for debug, release and profile builds.
334 envCommon.Append(CCFLAGS = Split("/GR /EHsc")) # CCFLAGS is also taken as the default value for CXXFLAGS.
335 envCommon.Append(CPPDEFINES = ["_CRT_SECURE_NO_DEPRECATE", "_CRT_NONSTDC_NO_DEPRECATE"])
336 envCommon.Append(LINKFLAGS = Split("/incremental:no"))
338 # Environment for debug builds:
339 envDebug=envCommon.Clone();
340 envDebug.Append(CCFLAGS=Split("/MDd /Od /Z7 /RTC1"));
341 envDebug.Append(LINKFLAGS=["/debug"]);
343 # Environment for release builds:
344 envRelease=envCommon.Clone();
345 envRelease.Append(CCFLAGS=Split("/MD /O2 /Ob2"));
347 # Environment for profile builds:
348 envProfile=envCommon.Clone();
349 envProfile.Append(CCFLAGS=Split("/MD /O2 /Ob2 /Z7"));
350 envProfile.Append(LINKFLAGS=["/fixed:no", "/debug"]);
352 elif envCommon["MSVC_VERSION"] in ["12.0", "12.0Exp", "14.0", "14.0Exp"]:
353 #######################################
354 ### Win32, Visual C++ 2013 and 2015 ###
355 #######################################
357 compiler = "vc" + envCommon["MSVC_VERSION"][:2] # "vc12" or "vc14"
358 assert compiler in ["vc12", "vc14"]
360 # Reference of commonly used compiler switches:
361 # Identical to the compiler switches for Visual C++ 2005, see there for more details.
363 # Begin with an environment with settings that are common for debug, release and profile builds.
364 envCommon.Append(CCFLAGS = Split("/GR /EHsc")) # CCFLAGS is also taken as the default value for CXXFLAGS.
365 envCommon.Append(CPPDEFINES = ["_CRT_SECURE_NO_DEPRECATE", "_CRT_NONSTDC_NO_DEPRECATE", "_WINSOCK_DEPRECATED_NO_WARNINGS"])
366 envCommon.Append(LINKFLAGS = Split("/incremental:no"))
368 # Environment for debug builds:
369 envDebug=envCommon.Clone();
370 envDebug.Append(CCFLAGS=Split("/MDd /Od /Z7 /RTC1"));
371 envDebug.Append(LINKFLAGS=["/debug"]);
373 # Environment for release builds:
374 envRelease=envCommon.Clone();
375 envRelease.Append(CCFLAGS=Split("/MD /O2 /Ob2 /GL"));
377 # Environment for profile builds:
378 envProfile=envCommon.Clone();
379 envProfile.Append(CCFLAGS=Split("/MD /O2 /Ob2 /Z7"));
380 envProfile.Append(LINKFLAGS=["/fixed:no", "/debug"]);
382 else:
383 ###############################
384 ### Win32, unknown compiler ###
385 ###############################
387 print("Unknown compiler " + envCommon["MSVC_VERSION"] + " on platform " + sys.platform + ".")
388 Exit(1)
390 elif sys.platform.startswith("linux"):
391 ErrorMsg = "Please install the %s library (development files)!\nOn many systems, the required package is named %s (possibly with a different version number)."
392 conf = Configure(envCommon)
394 # conf.CheckLib(...) # See http://www.cafu.de/wiki/cppdev:gettingstarted#linux_packages for additional libraries and headers that should be checked here.
396 #if not conf.CheckLibWithHeader("freetype", "ft2build.h", "c"): # TODO: What is the proper way to check for freetype?
397 #print ErrorMsg % ("freetype", "libfreetype6-dev")
398 #Exit(1)
400 if not conf.CheckLibWithHeader("png", "png.h", "c"):
401 print(ErrorMsg % ("png", "libpng12-dev"))
402 Exit(1)
404 if not conf.CheckLibWithHeader("z", "zlib.h", "c"):
405 print(ErrorMsg % ("zlib", "zlib1g-dev"))
406 Exit(1)
408 envCommon = conf.Finish()
410 if envCommon["CXX"]=="g++":
411 ##################
412 ### Linux, g++ ###
413 ##################
415 compiler="g++"
417 # The initial environment has settings that are common for debug, release and profile builds.
418 envCommon.Append(CCFLAGS = []) # CCFLAGS is also taken as the default value for CXXFLAGS.
419 envCommon.Append(CXXFLAGS = ["-std=c++0x"])
421 # Run additional, compiler-specific checks.
422 conf = Configure(envCommon, custom_tests = {'CheckOverrideIdentifier' : CheckOverrideIdentifier})
424 if not conf.CheckOverrideIdentifier():
425 print("C++11 `override` identifier is not supported (defining an empty macro as a work-around).")
426 conf.env.Append(CPPDEFINES = [("override", "")])
428 envCommon = conf.Finish()
430 # Environment for debug builds:
431 envDebug=envCommon.Clone();
432 envDebug.Append(CCFLAGS=["-g"]);
434 # Environment for release builds:
435 envRelease=envCommon.Clone();
436 envRelease.Append(CCFLAGS=["-O3"]);
437 envRelease.Append(LINKFLAGS=["-Wl,--strip-all"]); # Reduce file size, and keep nosy people from printing our symbol names (e.g. with strings -a).
439 # Environment for profile builds:
440 envProfile=envCommon.Clone();
441 envProfile.Append(CCFLAGS=["-O3", "-g"]);
443 else:
444 ###############################
445 ### Linux, unknown compiler ###
446 ###############################
448 print("Unknown compiler " + envCommon["CXX"] + " on platform " + sys.platform + ".")
449 Exit(1)
451 else:
452 print("Unknown platform '" + sys.platform + "'.")
453 Exit(1)
455 envDebug .Append(CPPDEFINES=["DEBUG"]);
456 envRelease.Append(CPPDEFINES=["NDEBUG"]); # Need NDEBUG to have the assert macro generate no runtime code.
457 envProfile.Append(CPPDEFINES=["NDEBUG"]); # Need NDEBUG to have the assert macro generate no runtime code.
460 ####################################
461 ### Build all external libraries ###
462 ####################################
464 # Set the list of variants (debug, profile, release) that should be built.
465 BVs=ARGUMENTS.get("bv", CompilerSetup.buildVariants)
467 # Set the build directories.
468 my_build_dir="build/"+sys.platform+"/"+compiler
469 if envCommon["TARGET_ARCH"]: my_build_dir += "/"+envCommon["TARGET_ARCH"];
471 my_build_dir_dbg=my_build_dir+"/debug"
472 my_build_dir_rel=my_build_dir+"/release"
473 my_build_dir_prf=my_build_dir+"/profile"
476 ExtLibsList = [
477 "bullet",
478 "freealut",
479 "freetype",
480 "glfw",
481 "jpeg",
482 "libogg",
483 "libpng",
484 "libvorbis",
485 "lwo",
486 "lua",
487 "minizip",
488 "mpg123",
489 "noise",
490 "openal-soft",
491 "zlib",
494 if sys.platform=="win32":
495 ExtLibsList.remove("openal-soft") # OpenAL-Soft is not built on Windows, use the OpenAL Windows SDK there.
496 else: # sys.platform.startswith("linux")
497 ExtLibsList.remove("freetype") # We use the system copies of these libraries.
498 ExtLibsList.remove("libpng")
499 ExtLibsList.remove("zlib")
501 for lib_name in ExtLibsList:
502 s_name=lib_name
504 if lib_name=="bullet": s_name+="/src";
505 if lib_name=="lua": s_name+="/src";
506 if lib_name=="mpg123": s_name+="/src/libmpg123";
508 if "d" in BVs: SConscript("ExtLibs/"+s_name+"/SConscript", exports={ "env": envDebug }, variant_dir="ExtLibs/"+lib_name+"/"+my_build_dir_dbg, duplicate=0)
509 if "r" in BVs: SConscript("ExtLibs/"+s_name+"/SConscript", exports={ "env": envRelease }, variant_dir="ExtLibs/"+lib_name+"/"+my_build_dir_rel, duplicate=0)
510 if "p" in BVs: SConscript("ExtLibs/"+s_name+"/SConscript", exports={ "env": envProfile }, variant_dir="ExtLibs/"+lib_name+"/"+my_build_dir_prf, duplicate=0)
513 # Compile wxWidgets for the current platform.
514 if not envCommon.GetOption('clean'):
515 if sys.platform=="win32":
516 if compiler.startswith("vc"):
517 # If we target a non-x86 architecture, the Makefiles automatically append a suffix to the directory names (no need to tweak COMPILER_PREFIX).
518 if envCommon["TARGET_ARCH"] in ["x86_64", "amd64", "emt64"]: target_cpu=" TARGET_CPU=AMD64"
519 elif envCommon["TARGET_ARCH"] in ["ia64"]: target_cpu=" TARGET_CPU=IA64"
520 else: target_cpu=""
522 result=envDebug. Execute("nmake /nologo /f makefile.vc BUILD=debug SHARED=0 COMPILER_PREFIX="+compiler+target_cpu, chdir="ExtLibs/wxWidgets/build/msw");
523 if (result!=0): envDebug. Exit(result);
524 result=envRelease.Execute("nmake /nologo /f makefile.vc BUILD=release SHARED=0 COMPILER_PREFIX="+compiler+target_cpu, chdir="ExtLibs/wxWidgets/build/msw");
525 if (result!=0): envRelease.Exit(result);
526 print(""); # Print just another empty line for better visual separation.
528 elif sys.platform.startswith("linux"):
529 # This automatic compilation of wxGTK requires that some library packages have been installed already,
530 # e.g. libgtk2.0-dev, libgl1-mesa-dev and libglu1-mesa-dev under Ubuntu 8.04.
531 # See the documentation at http://www.cafu.de/wiki/ for more details!
532 if not os.path.exists("ExtLibs/wxWidgets/build-gtk/make-ok-flag"):
533 envRelease.Execute(Mkdir("ExtLibs/wxWidgets/build-gtk"));
534 result=envRelease.Execute("../configure --with-gtk --disable-shared --without-libtiff --disable-pnm --disable-pcx --disable-iff --with-opengl --with-regex=builtin --disable-compat26 --disable-compat28", chdir="ExtLibs/wxWidgets/build-gtk");
535 if (result!=0): envRelease.Exit(result);
536 result=envRelease.Execute("make && touch make-ok-flag", chdir="ExtLibs/wxWidgets/build-gtk");
537 if (result!=0): envRelease.Exit(result);
540 ######################################
541 ### Install the external libraries ###
542 ######################################
544 # "Install" (copy) all DLLs that are required at run-time into the main Cafu directory.
545 # Some of them are self-built, others are provided ready-to-use by the vendor.
547 # They should work for the respective OS (.dll on Windows, .so on Linux) with all supported
548 # compilers and build variants (debug, profile, release): All interfaces are pure C, no C++,
549 # with the proper calling conventions etc. Therefore, matching the precise DLL built variant
550 # with that of the main Cafu executable is not necessary, and overwriting (some of) these
551 # DLLs with their debug build variants for debugging should not be a problem.
553 # We use release builds whenever we can, and assume that if the user has disabled them,
554 # debug builds are available (i.e. the code below fails if neither "d" nor "r" is in BVs).
555 if sys.platform=="win32":
556 if envCommon["TARGET_ARCH"]=="x86":
557 envRelease.Install(".", ["#/ExtLibs/Cg/bin/cg.dll", "#/ExtLibs/Cg/bin/cgGL.dll"]);
558 envRelease.Install(".", ["#/ExtLibs/openal-win/libs/Win32/OpenAL32.dll", "#/ExtLibs/openal-win/libs/Win32/wrap_oal.dll"]);
559 envRelease.Install(".", ["#/ExtLibs/fmod/api/fmod.dll"]);
560 else:
561 envRelease.Install(".", ["#/ExtLibs/Cg/bin.x64/cg.dll", "#/ExtLibs/Cg/bin.x64/cgGL.dll"]);
562 envRelease.Install(".", ["#/ExtLibs/openal-win/libs/Win64/OpenAL32.dll", "#/ExtLibs/openal-win/libs/Win64/wrap_oal.dll"]);
564 elif sys.platform.startswith("linux"):
565 if platform.machine()!="x86_64":
566 envRelease.Install(".", ["#/ExtLibs/Cg/lib/libCg.so", "#/ExtLibs/Cg/lib/libCgGL.so"]);
567 envRelease.Install(".", ["#/ExtLibs/fmod/api/libfmod-3.75.so"]);
568 else:
569 envRelease.Install(".", ["#/ExtLibs/Cg/lib.x64/libCg.so", "#/ExtLibs/Cg/lib.x64/libCgGL.so"]);
572 ############################################
573 ### Update the construction environments ###
574 ############################################
576 # Note that modifying the original environments here affects the build of the external libraries above!
577 envDebug_Cafu =envDebug.Clone();
578 envRelease_Cafu=envRelease.Clone();
579 envProfile_Cafu=envProfile.Clone();
581 envDebug_Cafu .Append(CPPDEFINES=[("SCONS_BUILD_DIR", my_build_dir_dbg)]);
582 envRelease_Cafu.Append(CPPDEFINES=[("SCONS_BUILD_DIR", my_build_dir_rel)]);
583 envProfile_Cafu.Append(CPPDEFINES=[("SCONS_BUILD_DIR", my_build_dir_prf)]);
585 envDebug_Cafu .Append(CPPPATH=["#/Libs", "#/ExtLibs"]);
586 envRelease_Cafu.Append(CPPPATH=["#/Libs", "#/ExtLibs"]);
587 envProfile_Cafu.Append(CPPPATH=["#/Libs", "#/ExtLibs"]);
589 envDebug_Cafu .Append(LIBPATH=["#/ExtLibs/"+lib_name+"/"+my_build_dir_dbg for lib_name in ExtLibsList] + ["#/Libs/"+my_build_dir_dbg]);
590 envRelease_Cafu.Append(LIBPATH=["#/ExtLibs/"+lib_name+"/"+my_build_dir_rel for lib_name in ExtLibsList] + ["#/Libs/"+my_build_dir_rel]);
591 envProfile_Cafu.Append(LIBPATH=["#/ExtLibs/"+lib_name+"/"+my_build_dir_prf for lib_name in ExtLibsList] + ["#/Libs/"+my_build_dir_prf]);
593 if compiler in ["vc8", "vc9", "vc10"]:
594 envDebug_Cafu .Append(CCFLAGS=Split("/J /W3 /WX"));
595 envRelease_Cafu.Append(CCFLAGS=Split("/J /W3 /WX"));
596 envProfile_Cafu.Append(CCFLAGS=Split("/J /W3 /WX"));
598 elif compiler in ["vc11", "vc12", "vc14"]:
599 envDebug_Cafu .Append(CCFLAGS=Split("/J /W3 /WX")) # /analyze /analyze:stacksize 80000
600 envRelease_Cafu.Append(CCFLAGS=Split("/J /W3 /WX"))
601 envProfile_Cafu.Append(CCFLAGS=Split("/J /W3 /WX"))
603 elif compiler=="g++":
604 envDebug_Cafu .Append(CCFLAGS=Split("-funsigned-char -Wall -Werror -Wno-char-subscripts"));
605 envRelease_Cafu.Append(CCFLAGS=Split("-funsigned-char -Wall -Werror -Wno-char-subscripts -fno-strict-aliasing"));
606 envProfile_Cafu.Append(CCFLAGS=Split("-funsigned-char -Wall -Werror -Wno-char-subscripts -fno-strict-aliasing"));
608 else:
609 print("Unknown compiler " + compiler + " when updating the build environments.")
610 Exit(1)
613 ###########################
614 ### Build all Cafu code ###
615 ###########################
617 if not os.path.exists(Dir("#/ExtLibs/fbx/lib").abspath):
618 print("Note: The FBX SDK is not present.\n")
620 if os.path.exists("Libs/SConscript"):
621 # Build everything in the Libs/ directory.
622 if "d" in BVs: buildMode = "dbg"; SConscript('Libs/SConscript', exports=[{'env':envDebug_Cafu}, 'buildMode', 'compiler'], variant_dir="Libs/"+my_build_dir_dbg, duplicate=0)
623 if "r" in BVs: buildMode = "rel"; SConscript('Libs/SConscript', exports=[{'env':envRelease_Cafu}, 'buildMode', 'compiler'], variant_dir="Libs/"+my_build_dir_rel, duplicate=0)
624 if "p" in BVs: buildMode = "prf"; SConscript('Libs/SConscript', exports=[{'env':envProfile_Cafu}, 'buildMode', 'compiler'], variant_dir="Libs/"+my_build_dir_prf, duplicate=0)
626 if os.path.exists("SConscript"):
627 # Build the Cafu executables.
628 if "d" in BVs: buildMode = "dbg"; SConscript('SConscript', exports=[{'env':envDebug_Cafu}, 'buildMode', 'compiler'], variant_dir=""+my_build_dir_dbg, duplicate=0)
629 if "r" in BVs: buildMode = "rel"; SConscript('SConscript', exports=[{'env':envRelease_Cafu}, 'buildMode', 'compiler'], variant_dir=""+my_build_dir_rel, duplicate=0)
630 if "p" in BVs: buildMode = "prf"; SConscript('SConscript', exports=[{'env':envProfile_Cafu}, 'buildMode', 'compiler'], variant_dir=""+my_build_dir_prf, duplicate=0)