1 import os, platform, sys
5 Import('env', 'buildMode', 'compiler')
8 envMapCompilers = env.Clone()
10 envMapCompilers.Append(CPPPATH=['ExtLibs/lua/src'])
11 envMapCompilers.Append(LIBS=Split("SceneGraph MatSys SoundSys ClipSys cfsLib ClipSys cfs_jpeg bulletdynamics bulletcollision bulletmath lua minizip lightwave png z"))
13 if sys.platform=="win32":
14 envMapCompilers.Append(LIBS=Split("wsock32"))
15 elif sys.platform.startswith("linux"):
16 pass # envMapCompilers.Append(LIBS=Split(""))
18 CommonWorldObject = envMapCompilers.StaticObject("Common/World.cpp")
20 envMapCompilers.Program('CaBSP/CaBSP', # I had preferred writing 'CaBSP' instead of 'CaBSP/CaBSP' here, but then under Linux we would get both a directory *and* an executeable with name 'CaBSP' in the build directory, which is not allowed/possible.
21 Split("CaBSP/CaBSP.cpp CaBSP/BspTreeBuilder/BspTreeBuilder.cpp") + CommonWorldObject)
23 envMapCompilers.Program('CaPVS/CaPVS',
24 Split("CaPVS/CaPVS.cpp CaPVS/CaPVSWorld.cpp") + CommonWorldObject)
26 envMapCompilers.Program('CaLight/CaLight',
27 Split("CaLight/CaLight.cpp CaLight/CaLightWorld.cpp") + CommonWorldObject)
29 envMapCompilers.Program('CaSHL/CaSHL',
30 Split("CaSHL/CaSHL.cpp CaSHL/CaSHLWorld.cpp") + CommonWorldObject)
34 envTools = env.Clone()
35 envTools.Append(CPPPATH=['ExtLibs/glfw/include', 'ExtLibs/tclap/include'])
37 if sys.platform=="win32":
38 # shell32 is required by glfw, which uses DragQueryFile() etc.
39 envTools.Append(LIBS=Split("SceneGraph MatSys ClipSys cfsLib cfs_jpeg bulletcollision bulletmath glfw lua minizip lightwave png z")
40 + Split("gdi32 opengl32 user32 shell32"))
41 elif sys.platform.startswith("linux"):
42 envTools.Append(CPPPATH=['/usr/include/freetype2']) # As of 2009-09-10, this line is to become unnecessary in the future, see /usr/include/ftbuild.h for details.
43 envTools.Append(LINKFLAGS=['-Wl,-rpath,.']) # Have dlopen() consider "." when searching for SOs (e.g. libCg.so).
44 envTools.Append(LINKFLAGS=['-Wl,--export-dynamic']) # Have our symbols available for dynamically loaded SOs (e.g. the renderer DLLs).
46 envTools.Append(LIBS=Split("SceneGraph MatSys ClipSys cfsLib cfs_jpeg bulletcollision bulletmath glfw lua minizip lightwave png z")
47 + Split("GL X11 Xrandr Xinerama Xxf86vm Xcursor dl pthread"))
49 envTools.Program("MakeFont", "CaTools/MakeFont.cpp", LIBS=envTools["LIBS"]+["freetype"])
50 envTools.Program('CaSanity', ['CaTools/CaSanity.cpp'] + CommonWorldObject)
51 envTools.Program('MaterialViewer', "CaTools/MaterialViewer.cpp")
52 envTools.Program('TerrainViewer', "CaTools/TerrainViewer.cpp")
57 envCafu.Append(CPPPATH=['ExtLibs/lua/src'])
58 envCafu.Append(CPPPATH=['ExtLibs/bullet/src'])
59 envCafu.Append(CPPPATH=['ExtLibs/glfw/include'])
60 envCafu.Append(CPPPATH=['ExtLibs/tclap/include'])
61 envCafu.Append(LIBS=Split("SceneGraph MatSys SoundSys ClipSys cfsLib cfs_jpeg bulletdynamics bulletcollision bulletmath glfw lightwave lua minizip png z"))
63 if sys.platform=="win32":
64 WinResource = envCafu.RES("Ca3DE/Cafu.rc")
65 envCafu.Append(LIBS=Split("gdi32 opengl32 user32 shell32 wsock32")) # opengl32 is for glReadPixels.
67 elif sys.platform.startswith("linux"):
70 # -Wl,-rpath,. is so that also the . directory is searched for dynamic libraries when they're opened.
71 # -Wl,--export-dynamic is so that the exe exports its symbols so that the MatSys, SoundSys and game .so libs can in turn resolve theirs.
72 envCafu.Append(LINKFLAGS=['-Wl,-rpath,.', '-Wl,--export-dynamic'])
74 # pthread is needed because some libraries that we load (possibly indirectly), e.g. the libCg.so and libopenal.so, use functions
75 # from the pthread library, but have not been linked themselves against it. They rely on the executable to be linked appropriately
76 # in order to resolve the pthread symbols. Paul Pluzhnikov states in a newsgroup posting (see [1]) that even if the .so libs were
77 # linked against libpthread.so, the main exe still *must* link with -lpthread, too, because:
78 # "Note that dlopen()ing an MT library from non-MT executable is not supported on most platforms, certainly not on Linux."
79 # [1] http://groups.google.de/group/gnu.gcc.help/browse_thread/thread/1e8f8dfd6027d7fa/
80 # rt is required in order to resolve clock_gettime() in openal-soft.
81 envCafu.Append(LIBS=Split("GL X11 Xrandr Xinerama Xxf86vm Xcursor rt dl pthread"))
83 appCafu = envCafu.Program('Ca3DE/Cafu',
85 Glob("Ca3DE/Client/*.cpp") +
86 Glob("Ca3DE/Server/*.cpp") +
87 CommonWorldObject + ["Common/CompGameEntity.cpp", "Common/WorldMan.cpp"] + WinResource)
91 # Create a common construction environment for our wxWidgets-based programs (Cafu and CaWE).
94 if sys.platform=="win32":
95 wxPath="#/ExtLibs/wxWidgets";
97 # TODO: Move this into the SConstruct file (including the wx include path above).
98 # Note that we only (want to) determine the right library path matching the used compiler here.
99 # The specific wx-version used (e.g. latest stable vs. trunk) is still determined locally (here),
100 # BUT if this is moved into the SConstruct file, also the wx-version (wxPath above) must be fixed there.
101 LibPath="/lib/"+compiler
103 # Append wxWidgets-specific suffixes matching the TARGET_CPU setting for the Makefiles.
104 if wxEnv["TARGET_ARCH"] in ["x86_64", "amd64", "emt64"]: LibPath += "_x64"
105 elif wxEnv["TARGET_ARCH"] in ["ia64"]: LibPath += "_ia64"
109 wxEnv.Append(LIBPATH=[wxPath+LibPath])
111 # Note that at this time, we link *two* copies of libpng to the programs: That of wxWidgets, and our own.
112 # See http://thread.gmane.org/gmane.comp.lib.wxwidgets.general/80245 for some details.
113 # A similar consideration applies to libjpeg, and possibly to zlib in the future...
115 wxEnv.Append(CPPPATH=[wxPath+LibPath+"/mswud"])
116 wxEnv.Append(LIBS=Split("wxbase30ud wxbase30ud_net wxjpegd wxpngd wxmsw30ud_adv wxmsw30ud_core wxmsw30ud_gl wxmsw30ud_aui wxmsw30ud_propgrid wxregexud"))
118 wxEnv.Append(CPPPATH=[wxPath+LibPath+"/mswu"])
119 wxEnv.Append(LIBS=Split("wxbase30u wxbase30u_net wxjpeg wxpng wxmsw30u_adv wxmsw30u_core wxmsw30u_gl wxmsw30u_aui wxmsw30u_propgrid wxregexu"))
121 wxEnv.Append(CPPPATH=[wxPath+'/include']) # This must be appended *after* the LibPath-specific paths.
122 wxEnv.Append(LIBS=Split("advapi32 comctl32 comdlg32 gdi32 ole32 oleaut32 opengl32 rpcrt4 shell32 user32 winspool wsock32"))
124 elif sys.platform.startswith("linux"):
125 wxEnv.ParseConfig(Dir("#/ExtLibs/wxWidgets").abspath + "/build-gtk/wx-config --cxxflags --libs std,aui,gl,propgrid | sed 's/-l\\S*jpeg\\S*\\ //g'")
126 wxEnv.Append(LIBS=Split("cairo pangocairo-1.0 X11"))
130 envCaWE = wxEnv.Clone()
131 envCaWE.Append(CPPPATH=['ExtLibs/lua/src', 'ExtLibs/bullet/src', 'ExtLibs/noise/src'])
132 envCaWE.Append(LIBS=Split("SceneGraph MatSys SoundSys ClipSys cfsLib ClipSys ModelLoaders cfs_jpeg bulletdynamics bulletcollision bulletmath noise lua minizip lightwave freetype png z"))
134 SourceFilesList = (Glob("CaWE/*.cpp")
135 + Glob("CaWE/FontWizard/*.cpp")
136 + Glob("CaWE/GuiEditor/*.cpp") + Glob("CaWE/GuiEditor/Commands/*.cpp")
137 + Glob("CaWE/MapEditor/*.cpp") + Glob("CaWE/MapEditor/Commands/*.cpp")
138 + Glob("CaWE/MaterialBrowser/*.cpp")
139 + Glob("CaWE/ModelEditor/*.cpp")+Glob("CaWE/ModelEditor/Commands/*.cpp")
140 + Glob("CaWE/MapEditor/wxExt/*.cpp")
141 + Glob("CaWE/MapEditor/wxFB/*.cpp"))
143 if sys.platform=="win32":
144 SourceFilesList += envCaWE.RES("CaWE/CaWE.rc")
145 # The next two lines are mirrored in Libs/SConscript.
146 fbx_lib_path = "#/ExtLibs/fbx/lib/" + \
147 {"vc8": "vs2005", "vc9": "vs2008", "vc10": "vs2010", "vc11": "vs2012", "vc12": "vs2013", "vc14": "vs2015"}[compiler]
149 if os.path.exists(Dir(fbx_lib_path).abspath):
150 envCaWE.Append(LIBPATH=[fbx_lib_path + "/" +
151 ("x64" if envCaWE["TARGET_ARCH"] in ["x86_64", "amd64", "emt64"] else "x86") + "/" +
152 ("debug" if buildMode == "dbg" else "release")])
153 envCaWE.Append(LIBS=["libfbxsdk-md"])
155 elif sys.platform.startswith("linux"):
156 envCaWE.Append(CPPPATH=['/usr/include/freetype2']) # As of 2009-09-10, this line is to become unnecessary in the future, see /usr/include/ftbuild.h for details.
157 envCaWE.Append(LINKFLAGS=['-Wl,-rpath,.']) # Have dlopen() consider "." when searching for SOs (e.g. libCg.so).
158 envCaWE.Append(LINKFLAGS=['-Wl,--export-dynamic']) # Have our symbols available for dynamically loaded SOs (e.g. the renderer DLLs).
160 if os.path.exists(Dir("#/ExtLibs/fbx/lib").abspath):
161 fbx_lib_path = "#/ExtLibs/fbx/lib/gcc4/{}/{}".format(
162 "x64" if platform.machine() == "x86_64" else "x86",
163 "debug" if buildMode == "dbg" else "release")
164 # envCaWE.Append(LIBPATH=[fbx_lib_path])
165 # envCaWE.Append(LIBS=["fbxsdk"]) # This links libfbxsdk.so
166 envCaWE.Append(LIBS=[File(fbx_lib_path + "/libfbxsdk.a")]) # link statically
168 CaWE_exe = envCaWE.Program('CaWE/CaWE', SourceFilesList + CommonWorldObject)
170 # If CaWE_exe is cleaned, clean wxWidgets along with it. This is done here
171 # because Clean() requires a target that files to be cleaned are associated with.
172 envCaWE.Clean(CaWE_exe, [
173 "#/ExtLibs/wxWidgets/build/msw/" + compiler + "_mswu",
174 "#/ExtLibs/wxWidgets/build/msw/" + compiler + "_mswud",
175 "#/ExtLibs/wxWidgets/lib/" + compiler + "_lib",
176 "#/ExtLibs/wxWidgets/build-gtk",
181 def UpdateDocTemplates(target, source, env):
183 Runs `.../CaWE --update-doxygen` in order to update the `Doxygen/scripting/tmpl/*.hpp` files.
185 subprocess.call([str(source[0]), "--update-doxygen"])
187 # For all target files (`Doxygen/scripting/tmpl/*.hpp`), make sure that they
188 # - don't contain the string "// WARNING" (e.g. about mismatches),
189 # - don't contain any lines that the related files in `../src/` don't have.
192 path, basename = os.path.split(tmplPath)
193 srcPath = os.path.join(os.path.dirname(path), "src", basename)
195 with open(tmplPath, 'r') as tmplFile:
196 with open(srcPath, 'r') as srcFile:
197 srcLines = srcFile.readlines()
200 for tmplLine in tmplFile:
201 if "// WARNING" in tmplLine:
202 raise Exception('Found a "// WARNING ..." comment in file "{0}".'.format(tmplPath))
204 while tmplLine != srcLines[srcLineNr]:
206 if srcLineNr >= len(srcLines):
207 raise Exception('A line in template file "{0}" does not exist in the related source '
208 'file:\n\n{1}\nUse e.g. BeyondCompare to review the situation.'.format(tmplPath, tmplLine))
213 if buildMode == "dbg":
214 # Unfortunately, the list of target files must be known in advance: it is not possible
215 # to run `.../CaWE --update-doxygen` first and then see what it produced. For details,
216 # see https://pairlist4.pair.net/pipermail/scons-users/2015-February/003409.html
218 "GameComponents.hpp", "GameEntities.hpp", "GameWorld.hpp",
219 "GuiComponents.hpp", "GuiGui.hpp", "GuiWindows.hpp"
222 envCaWE.Command(["#/Doxygen/scripting/tmpl/" + f for f in TargetFiles], CaWE_exe, UpdateDocTemplates)