Performance improvement for the StaticConstraint by not initializing the cache upon...
[0ad.git] / build / premake / premake5.lua
blob221317b65c455d0a9ad241f250c437b971b14b8b
1 newoption { trigger = "android", description = "Use non-working Android cross-compiling mode" }
2 newoption { trigger = "atlas", description = "Include Atlas scenario editor projects" }
3 newoption { trigger = "coverage", description = "Enable code coverage data collection (GCC only)" }
4 newoption { trigger = "gles", description = "Use non-working OpenGL ES 2.0 mode" }
5 newoption { trigger = "icc", description = "Use Intel C++ Compiler (Linux only; should use either \"--cc icc\" or --without-pch too, and then set CXX=icpc before calling make)" }
6 newoption { trigger = "jenkins-tests", description = "Configure CxxTest to use the XmlPrinter runner which produces Jenkins-compatible output" }
7 newoption { trigger = "minimal-flags", description = "Only set compiler/linker flags that are really needed. Has no effect on Windows builds" }
8 newoption { trigger = "outpath", description = "Location for generated project files" }
9 newoption { trigger = "with-system-mozjs38", description = "Search standard paths for libmozjs38, instead of using bundled copy" }
10 newoption { trigger = "with-system-nvtt", description = "Search standard paths for nvidia-texture-tools library, instead of using bundled copy" }
11 newoption { trigger = "without-audio", description = "Disable use of OpenAL/Ogg/Vorbis APIs" }
12 newoption { trigger = "without-lobby", description = "Disable the use of gloox and the multiplayer lobby" }
13 newoption { trigger = "without-miniupnpc", description = "Disable use of miniupnpc for port forwarding" }
14 newoption { trigger = "without-nvtt", description = "Disable use of NVTT" }
15 newoption { trigger = "without-pch", description = "Disable generation and usage of precompiled headers" }
16 newoption { trigger = "without-tests", description = "Disable generation of test projects" }
18 -- OS X specific options
19 newoption { trigger = "macosx-bundle", description = "Enable OSX bundle, the argument is the bundle identifier string (e.g. com.wildfiregames.0ad)" }
20 newoption { trigger = "macosx-version-min", description = "Set minimum required version of the OS X API, the build will possibly fail if an older SDK is used, while newer API functions will be weakly linked (i.e. resolved at runtime)" }
21 newoption { trigger = "sysroot", description = "Set compiler system root path, used for building against a non-system SDK. For example /usr/local becomes SYSROOT/user/local" }
23 -- Windows specific options
24 newoption { trigger = "build-shared-glooxwrapper", description = "Rebuild glooxwrapper DLL for Windows. Requires the same compiler version that gloox was built with" }
25 newoption { trigger = "use-shared-glooxwrapper", description = "Use prebuilt glooxwrapper DLL for Windows" }
26 newoption { trigger = "large-address-aware", description = "Make the executable large address aware. Do not use for development, in order to spot memory issues easily" }
28 -- Install options
29 newoption { trigger = "bindir", description = "Directory for executables (typically '/usr/games'); default is to be relocatable" }
30 newoption { trigger = "datadir", description = "Directory for data files (typically '/usr/share/games/0ad'); default is ../data/ relative to executable" }
31 newoption { trigger = "libdir", description = "Directory for libraries (typically '/usr/lib/games/0ad'); default is ./ relative to executable" }
33 -- Root directory of project checkout relative to this .lua file
34 rootdir = "../.."
36 dofile("extern_libs5.lua")
38 -- detect compiler for non-Windows
39 if os.istarget("macosx") then
40 cc = "clang"
41 elseif os.istarget("linux") and _OPTIONS["icc"] then
42 cc = "icc"
43 elseif not os.istarget("windows") then
44 cc = os.getenv("CC")
45 if cc == nil or cc == "" then
46 local hasgcc = os.execute("which gcc > .gccpath")
47 local f = io.open(".gccpath", "r")
48 local gccpath = f:read("*line")
49 f:close()
50 os.execute("rm .gccpath")
51 if gccpath == nil then
52 cc = "clang"
53 else
54 cc = "gcc"
55 end
56 end
57 end
59 -- detect CPU architecture (simplistic, currently only supports x86, amd64 and ARM)
60 arch = "x86"
61 if _OPTIONS["android"] then
62 arch = "arm"
63 elseif os.istarget("windows") then
64 if os.getenv("PROCESSOR_ARCHITECTURE") == "amd64" or os.getenv("PROCESSOR_ARCHITEW6432") == "amd64" then
65 arch = "amd64"
66 end
67 else
68 arch = os.getenv("HOSTTYPE")
69 if arch == "x86_64" or arch == "amd64" then
70 arch = "amd64"
71 else
72 os.execute(cc .. " -dumpmachine > .gccmachine.tmp")
73 local f = io.open(".gccmachine.tmp", "r")
74 local machine = f:read("*line")
75 f:close()
76 if string.find(machine, "x86_64") == 1 or string.find(machine, "amd64") == 1 then
77 arch = "amd64"
78 elseif string.find(machine, "i.86") == 1 then
79 arch = "x86"
80 elseif string.find(machine, "arm") == 1 then
81 arch = "arm"
82 elseif string.find(machine, "aarch64") == 1 then
83 arch = "aarch64"
84 else
85 print("WARNING: Cannot determine architecture from GCC, assuming x86")
86 end
87 end
88 end
90 -- Set up the Workspace
91 workspace "pyrogenesis"
92 targetdir(rootdir.."/binaries/system")
93 libdirs(rootdir.."/binaries/system")
94 if not _OPTIONS["outpath"] then
95 error("You must specify the 'outpath' parameter")
96 end
97 location(_OPTIONS["outpath"])
98 configurations { "Release", "Debug" }
100 source_root = rootdir.."/source/" -- default for most projects - overridden by local in others
102 -- Rationale: projects should not have any additional include paths except for
103 -- those required by external libraries. Instead, we should always write the
104 -- full relative path, e.g. #include "maths/Vector3d.h". This avoids confusion
105 -- ("which file is meant?") and avoids enormous include path lists.
108 -- projects: engine static libs, main exe, atlas, atlas frontends, test.
110 --------------------------------------------------------------------------------
111 -- project helper functions
112 --------------------------------------------------------------------------------
114 function project_set_target(project_name)
116 -- Note: On Windows, ".exe" is added on the end, on unices the name is used directly
118 local obj_dir_prefix = _OPTIONS["outpath"].."/obj/"..project_name.."_"
120 filter "Debug"
121 objdir(obj_dir_prefix.."Debug")
122 targetsuffix("_dbg")
124 filter "Release"
125 objdir(obj_dir_prefix.."Release")
127 filter { }
132 function project_set_build_flags()
134 editandcontinue "Off"
136 if not _OPTIONS["minimal-flags"] then
137 symbols "On"
140 if cc ~= "icc" and (os.istarget("windows") or not _OPTIONS["minimal-flags"]) then
141 -- adds the -Wall compiler flag
142 warnings "Extra" -- this causes far too many warnings/remarks on ICC
145 -- disable Windows debug heap, since it makes malloc/free hugely slower when
146 -- running inside a debugger
147 if os.istarget("windows") then
148 debugenvs { "_NO_DEBUG_HEAP=1" }
151 filter "Debug"
152 defines { "DEBUG" }
154 filter "Release"
155 if os.istarget("windows") or not _OPTIONS["minimal-flags"] then
156 optimize "Speed"
158 defines { "NDEBUG", "CONFIG_FINAL=1" }
160 filter { }
162 if _OPTIONS["gles"] then
163 defines { "CONFIG2_GLES=1" }
166 if _OPTIONS["without-audio"] then
167 defines { "CONFIG2_AUDIO=0" }
170 if _OPTIONS["without-nvtt"] then
171 defines { "CONFIG2_NVTT=0" }
174 if _OPTIONS["without-lobby"] then
175 defines { "CONFIG2_LOBBY=0" }
178 if _OPTIONS["without-miniupnpc"] then
179 defines { "CONFIG2_MINIUPNPC=0" }
182 -- required for the lowlevel library. must be set from all projects that use it, otherwise it assumes it is
183 -- being used as a DLL (which is currently not the case in 0ad)
184 defines { "LIB_STATIC_LINK" }
186 -- various platform-specific build flags
187 if os.istarget("windows") then
189 flags { "MultiProcessorCompile" }
191 -- use native wchar_t type (not typedef to unsigned short)
192 nativewchar "on"
194 else -- *nix
196 -- TODO, FIXME: This check is incorrect because it means that some additional flags will be added inside the "else" branch if the
197 -- compiler is ICC and minimal-flags is specified (ticket: #2994)
198 if cc == "icc" and not _OPTIONS["minimal-flags"] then
199 buildoptions {
200 "-w1",
201 -- "-Wabi",
202 -- "-Wp64", -- complains about OBJECT_TO_JSVAL which is annoying
203 "-Wpointer-arith",
204 "-Wreturn-type",
205 -- "-Wshadow",
206 "-Wuninitialized",
207 "-Wunknown-pragmas",
208 "-Wunused-function",
209 "-wd1292" -- avoid lots of 'attribute "__nonnull__" ignored'
211 filter "Debug"
212 buildoptions { "-O0" } -- ICC defaults to -O2
213 filter { }
214 if os.istarget("macosx") then
215 linkoptions { "-multiply_defined","suppress" }
217 else
218 -- exclude most non-essential build options for minimal-flags
219 if not _OPTIONS["minimal-flags"] then
220 buildoptions {
221 -- enable most of the standard warnings
222 "-Wno-switch", -- enumeration value not handled in switch (this is sometimes useful, but results in lots of noise)
223 "-Wno-reorder", -- order of initialization list in constructors (lots of noise)
224 "-Wno-invalid-offsetof", -- offsetof on non-POD types (see comment in renderer/PatchRData.cpp)
226 "-Wextra",
227 "-Wno-missing-field-initializers", -- (this is common in external headers we can't fix)
229 -- add some other useful warnings that need to be enabled explicitly
230 "-Wunused-parameter",
231 "-Wredundant-decls", -- (useful for finding some multiply-included header files)
232 -- "-Wformat=2", -- (useful sometimes, but a bit noisy, so skip it by default)
233 -- "-Wcast-qual", -- (useful for checking const-correctness, but a bit noisy, so skip it by default)
234 "-Wnon-virtual-dtor", -- (sometimes noisy but finds real bugs)
235 "-Wundef", -- (useful for finding macro name typos)
237 -- enable security features (stack checking etc) that shouldn't have
238 -- a significant effect on performance and can catch bugs
239 "-fstack-protector-all",
240 "-U_FORTIFY_SOURCE", -- (avoid redefinition warning if already defined)
241 "-D_FORTIFY_SOURCE=2",
243 -- always enable strict aliasing (useful in debug builds because of the warnings)
244 "-fstrict-aliasing",
246 -- don't omit frame pointers (for now), because performance will be impacted
247 -- negatively by the way this breaks profilers more than it will be impacted
248 -- positively by the optimisation
249 "-fno-omit-frame-pointer"
252 if not _OPTIONS["without-pch"] then
253 buildoptions {
254 -- do something (?) so that ccache can handle compilation with PCH enabled
255 -- (ccache 3.1+ also requires CCACHE_SLOPPINESS=time_macros for this to work)
256 "-fpch-preprocess"
260 if os.istarget("linux") or os.istarget("bsd") then
261 buildoptions { "-fPIC" }
262 linkoptions { "-Wl,--no-undefined", "-Wl,--as-needed", "-Wl,-z,relro" }
265 if arch == "x86" then
266 buildoptions {
267 -- To support intrinsics like __sync_bool_compare_and_swap on x86
268 -- we need to set -march to something that supports them (i686).
269 -- We use pentium3 to also enable other features like mmx and sse,
270 -- while tuning for generic to have good performance on every
271 -- supported CPU.
272 -- Note that all these features are already supported on amd64.
273 "-march=pentium3 -mtune=generic"
278 buildoptions {
279 -- Enable C++11 standard.
280 "-std=c++0x"
283 if arch == "arm" then
284 -- disable warnings about va_list ABI change and use
285 -- compile-time flags for futher configuration.
286 buildoptions { "-Wno-psabi" }
287 if _OPTIONS["android"] then
288 -- Android uses softfp, so we should too.
289 buildoptions { "-mfloat-abi=softfp" }
293 if _OPTIONS["coverage"] then
294 buildoptions { "-fprofile-arcs", "-ftest-coverage" }
295 links { "gcov" }
298 -- We don't want to require SSE2 everywhere yet, but OS X headers do
299 -- require it (and Intel Macs always have it) so enable it here
300 if os.istarget("macosx") then
301 buildoptions { "-msse2" }
304 -- Check if SDK path should be used
305 if _OPTIONS["sysroot"] then
306 buildoptions { "-isysroot " .. _OPTIONS["sysroot"] }
307 linkoptions { "-Wl,-syslibroot," .. _OPTIONS["sysroot"] }
310 -- On OS X, sometimes we need to specify the minimum API version to use
311 if _OPTIONS["macosx-version-min"] then
312 buildoptions { "-mmacosx-version-min=" .. _OPTIONS["macosx-version-min"] }
313 -- clang and llvm-gcc look at mmacosx-version-min to determine link target
314 -- and CRT version, and use it to set the macosx_version_min linker flag
315 linkoptions { "-mmacosx-version-min=" .. _OPTIONS["macosx-version-min"] }
318 -- Check if we're building a bundle
319 if _OPTIONS["macosx-bundle"] then
320 defines { "BUNDLE_IDENTIFIER=" .. _OPTIONS["macosx-bundle"] }
323 -- On OS X, force using libc++ since it has better C++11 support,
324 -- now required by the game
325 if os.istarget("macosx") then
326 buildoptions { "-stdlib=libc++" }
327 linkoptions { "-stdlib=libc++" }
331 buildoptions {
332 -- Hide symbols in dynamic shared objects by default, for efficiency and for equivalence with
333 -- Windows - they should be exported explicitly with __attribute__ ((visibility ("default")))
334 "-fvisibility=hidden"
337 if _OPTIONS["bindir"] then
338 defines { "INSTALLED_BINDIR=" .. _OPTIONS["bindir"] }
340 if _OPTIONS["datadir"] then
341 defines { "INSTALLED_DATADIR=" .. _OPTIONS["datadir"] }
343 if _OPTIONS["libdir"] then
344 defines { "INSTALLED_LIBDIR=" .. _OPTIONS["libdir"] }
347 if os.istarget("linux") or os.istarget("bsd") then
348 -- To use our local shared libraries, they need to be found in the
349 -- runtime dynamic linker path. Add their path to -rpath.
350 if _OPTIONS["libdir"] then
351 linkoptions {"-Wl,-rpath," .. _OPTIONS["libdir"] }
352 else
353 -- On FreeBSD we need to allow use of $ORIGIN
354 if os.istarget("bsd") then
355 linkoptions { "-Wl,-z,origin" }
358 -- Adding the executable path and taking care of correct escaping
359 if _ACTION == "gmake" then
360 linkoptions { "-Wl,-rpath,'$$ORIGIN'" }
361 elseif _ACTION == "codeblocks" then
362 linkoptions { "-Wl,-R\\\\$$$ORIGIN" }
370 -- add X11 includes paths after all the others so they don't conflict with
371 -- bundled libs
372 function project_add_x11_dirs()
373 if not os.istarget("windows") and not os.istarget("macosx") then
374 -- X11 includes may be installed in one of a gadzillion of five places
375 -- Famous last words: "You can't include too much! ;-)"
376 sysincludedirs {
377 "/usr/X11R6/include/X11",
378 "/usr/X11R6/include",
379 "/usr/local/include/X11",
380 "/usr/local/include",
381 "/usr/include/X11"
383 libdirs { "/usr/X11R6/lib" }
387 -- create a project and set the attributes that are common to all projects.
388 function project_create(project_name, target_type)
390 project(project_name)
391 language "C++"
392 kind(target_type)
394 filter "action:vs2013"
395 toolset "v120_xp"
396 filter "action:vs2015"
397 toolset "v140_xp"
398 filter {}
400 project_set_target(project_name)
401 project_set_build_flags()
405 -- OSX creates a .app bundle if the project type of the main application is set to "WindowedApp".
406 -- We don't want this because this bundle would be broken (it lacks all the resources and external dependencies, Info.plist etc...)
407 -- Windows opens a console in the background if it's set to ConsoleApp, which is not what we want.
408 -- I didn't check if this setting matters for linux, but WindowedApp works there.
409 function get_main_project_target_type()
410 if _OPTIONS["android"] then
411 return "SharedLib"
412 elseif os.istarget("macosx") then
413 return "ConsoleApp"
414 else
415 return "WindowedApp"
420 -- source_root: rel_source_dirs and rel_include_dirs are relative to this directory
421 -- rel_source_dirs: A table of subdirectories. All source files in these directories are added.
422 -- rel_include_dirs: A table of subdirectories to be included.
423 -- extra_params: table including zero or more of the following:
424 -- * no_pch: If specified, no precompiled headers are used for this project.
425 -- * pch_dir: If specified, this directory will be used for precompiled headers instead of the default
426 -- <source_root>/pch/<projectname>/.
427 -- * extra_files: table of filenames (relative to source_root) to add to project
428 -- * extra_links: table of library names to add to link step
429 function project_add_contents(source_root, rel_source_dirs, rel_include_dirs, extra_params)
431 for i,v in pairs(rel_source_dirs) do
432 local prefix = source_root..v.."/"
433 files { prefix.."*.cpp", prefix.."*.h", prefix.."*.inl", prefix.."*.js", prefix.."*.asm", prefix.."*.mm" }
436 -- Put the project-specific PCH directory at the start of the
437 -- include path, so '#include "precompiled.h"' will look in
438 -- there first
439 local pch_dir
440 if not extra_params["pch_dir"] then
441 pch_dir = source_root .. "pch/" .. project().name .. "/"
442 else
443 pch_dir = extra_params["pch_dir"]
445 includedirs { pch_dir }
447 -- Precompiled Headers
448 -- rationale: we need one PCH per static lib, since one global header would
449 -- increase dependencies. To that end, we can either include them as
450 -- "projectdir/precompiled.h", or add "source/PCH/projectdir" to the
451 -- include path and put the PCH there. The latter is better because
452 -- many projects contain several dirs and it's unclear where there the
453 -- PCH should be stored. This way is also a bit easier to use in that
454 -- source files always include "precompiled.h".
455 -- Notes:
456 -- * Visual Assist manages to use the project include path and can
457 -- correctly open these files from the IDE.
458 -- * precompiled.cpp (needed to "Create" the PCH) also goes in
459 -- the abovementioned dir.
460 if (not _OPTIONS["without-pch"] and not extra_params["no_pch"]) then
461 filter "action:vs*"
462 pchheader("precompiled.h")
463 filter "action:xcode*"
464 pchheader("../"..pch_dir.."precompiled.h")
465 filter { "action:not vs*", "action:not xcode*" }
466 pchheader(pch_dir.."precompiled.h")
467 filter {}
468 pchsource(pch_dir.."precompiled.cpp")
469 defines { "USING_PCH" }
470 files { pch_dir.."precompiled.h", pch_dir.."precompiled.cpp" }
471 else
472 flags { "NoPCH" }
475 -- next is source root dir, for absolute (nonrelative) includes
476 -- (e.g. "lib/precompiled.h")
477 includedirs { source_root }
479 for i,v in pairs(rel_include_dirs) do
480 includedirs { source_root .. v }
483 if extra_params["extra_files"] then
484 for i,v in pairs(extra_params["extra_files"]) do
485 -- .rc files are only needed on Windows
486 if path.getextension(v) ~= ".rc" or os.istarget("windows") then
487 files { source_root .. v }
492 if extra_params["extra_links"] then
493 links { extra_params["extra_links"] }
498 -- Add command-line options to set up the manifest dependencies for Windows
499 -- (See lib/sysdep/os/win/manifest.cpp)
500 function project_add_manifest()
501 linkoptions { "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"" }
504 --------------------------------------------------------------------------------
505 -- engine static libraries
506 --------------------------------------------------------------------------------
508 -- the engine is split up into several static libraries. this eases separate
509 -- distribution of those components, reduces dependencies a bit, and can
510 -- also speed up builds.
511 -- more to the point, it is necessary to efficiently support a separate
512 -- test executable that also includes much of the game code.
514 -- names of all static libs created. automatically added to the
515 -- main app project later (see explanation at end of this file)
516 static_lib_names = {}
517 static_lib_names_debug = {}
518 static_lib_names_release = {}
520 -- set up one of the static libraries into which the main engine code is split.
521 -- extra_params:
522 -- no_default_link: If specified, linking won't be done by default.
523 -- For the rest of extra_params, see project_add_contents().
524 -- note: rel_source_dirs and rel_include_dirs are relative to global source_root.
525 function setup_static_lib_project (project_name, rel_source_dirs, extern_libs, extra_params)
527 local target_type = "StaticLib"
528 project_create(project_name, target_type)
529 project_add_contents(source_root, rel_source_dirs, {}, extra_params)
530 project_add_extern_libs(extern_libs, target_type)
531 project_add_x11_dirs()
533 if not extra_params["no_default_link"] then
534 table.insert(static_lib_names, project_name)
537 if os.istarget("windows") then
538 rtti "off"
542 function setup_third_party_static_lib_project (project_name, rel_source_dirs, extern_libs, extra_params)
544 setup_static_lib_project(project_name, rel_source_dirs, extern_libs, extra_params)
545 includedirs { source_root .. "third_party/" .. project_name .. "/include/" }
548 function setup_shared_lib_project (project_name, rel_source_dirs, extern_libs, extra_params)
550 local target_type = "SharedLib"
551 project_create(project_name, target_type)
552 project_add_contents(source_root, rel_source_dirs, {}, extra_params)
553 project_add_extern_libs(extern_libs, target_type)
554 project_add_x11_dirs()
556 if not extra_params["no_default_link"] then
557 table.insert(static_lib_names, project_name)
560 if os.istarget("windows") then
561 rtti "off"
562 links { "delayimp" }
567 -- this is where the source tree is chopped up into static libs.
568 -- can be changed very easily; just copy+paste a new setup_static_lib_project,
569 -- or remove existing ones. static libs are automagically added to
570 -- main_exe link step.
571 function setup_all_libs ()
573 -- relative to global source_root.
574 local source_dirs = {}
575 -- names of external libraries used (see libraries_dir comment)
576 local extern_libs = {}
579 source_dirs = {
580 "network",
582 extern_libs = {
583 "spidermonkey",
584 "enet",
585 "boost", -- dragged in via server->simulation.h->random
587 if not _OPTIONS["without-miniupnpc"] then
588 table.insert(extern_libs, "miniupnpc")
590 setup_static_lib_project("network", source_dirs, extern_libs, {})
592 source_dirs = {
593 "third_party/tinygettext/src",
595 extern_libs = {
596 "iconv",
597 "boost",
599 setup_third_party_static_lib_project("tinygettext", source_dirs, extern_libs, { } )
601 -- it's an external library and we don't want to modify its source to fix warnings, so we just disable them to avoid noise in the compile output
602 filter "action:vs*"
603 buildoptions {
604 "/wd4127",
605 "/wd4309",
606 "/wd4800",
607 "/wd4100",
608 "/wd4996",
609 "/wd4099",
610 "/wd4503"
612 filter {}
615 if not _OPTIONS["without-lobby"] then
616 source_dirs = {
617 "lobby",
618 "lobby/scripting",
619 "i18n",
620 "third_party/encryption"
623 extern_libs = {
624 "spidermonkey",
625 "boost",
626 "enet",
627 "gloox",
628 "icu",
629 "iconv",
630 "tinygettext"
632 setup_static_lib_project("lobby", source_dirs, extern_libs, {})
634 if _OPTIONS["use-shared-glooxwrapper"] and not _OPTIONS["build-shared-glooxwrapper"] then
635 table.insert(static_lib_names_debug, "glooxwrapper_dbg")
636 table.insert(static_lib_names_release, "glooxwrapper")
637 else
638 source_dirs = {
639 "lobby/glooxwrapper",
641 extern_libs = {
642 "boost",
643 "gloox",
645 if _OPTIONS["build-shared-glooxwrapper"] then
646 setup_shared_lib_project("glooxwrapper", source_dirs, extern_libs, {})
647 else
648 setup_static_lib_project("glooxwrapper", source_dirs, extern_libs, {})
651 else
652 source_dirs = {
653 "lobby/scripting",
654 "third_party/encryption"
656 extern_libs = {
657 "spidermonkey",
658 "boost"
660 setup_static_lib_project("lobby", source_dirs, extern_libs, {})
661 files { source_root.."lobby/Globals.cpp" }
665 source_dirs = {
666 "simulation2",
667 "simulation2/components",
668 "simulation2/helpers",
669 "simulation2/scripting",
670 "simulation2/serialization",
671 "simulation2/system",
672 "simulation2/testcomponents",
674 extern_libs = {
675 "boost",
676 "opengl",
677 "spidermonkey",
679 setup_static_lib_project("simulation2", source_dirs, extern_libs, {})
682 source_dirs = {
683 "scriptinterface",
684 "scriptinterface/third_party"
686 extern_libs = {
687 "boost",
688 "spidermonkey",
689 "valgrind",
690 "sdl",
692 setup_static_lib_project("scriptinterface", source_dirs, extern_libs, {})
695 source_dirs = {
696 "ps",
697 "ps/scripting",
698 "network/scripting",
699 "ps/GameSetup",
700 "ps/XML",
701 "soundmanager",
702 "soundmanager/data",
703 "soundmanager/items",
704 "soundmanager/scripting",
705 "maths",
706 "maths/scripting",
707 "i18n",
708 "i18n/scripting",
709 "third_party/cppformat",
711 extern_libs = {
712 "spidermonkey",
713 "sdl", -- key definitions
714 "libxml2",
715 "opengl",
716 "zlib",
717 "boost",
718 "enet",
719 "libcurl",
720 "tinygettext",
721 "icu",
722 "iconv",
725 if not _OPTIONS["without-audio"] then
726 table.insert(extern_libs, "openal")
727 table.insert(extern_libs, "vorbis")
730 setup_static_lib_project("engine", source_dirs, extern_libs, {})
733 source_dirs = {
734 "graphics",
735 "graphics/scripting",
736 "renderer",
737 "renderer/scripting",
738 "third_party/mikktspace"
740 extern_libs = {
741 "opengl",
742 "sdl", -- key definitions
743 "spidermonkey", -- for graphics/scripting
744 "boost"
746 if not _OPTIONS["without-nvtt"] then
747 table.insert(extern_libs, "nvtt")
749 setup_static_lib_project("graphics", source_dirs, extern_libs, {})
752 source_dirs = {
753 "tools/atlas/GameInterface",
754 "tools/atlas/GameInterface/Handlers"
756 extern_libs = {
757 "boost",
758 "sdl", -- key definitions
759 "opengl",
760 "spidermonkey"
762 setup_static_lib_project("atlas", source_dirs, extern_libs, {})
765 source_dirs = {
766 "gui",
767 "gui/scripting",
768 "i18n"
770 extern_libs = {
771 "spidermonkey",
772 "sdl", -- key definitions
773 "opengl",
774 "boost",
775 "enet",
776 "tinygettext",
777 "icu",
778 "iconv",
780 if not _OPTIONS["without-audio"] then
781 table.insert(extern_libs, "openal")
783 setup_static_lib_project("gui", source_dirs, extern_libs, {})
786 source_dirs = {
787 "lib",
788 "lib/adts",
789 "lib/allocators",
790 "lib/external_libraries",
791 "lib/file",
792 "lib/file/archive",
793 "lib/file/common",
794 "lib/file/io",
795 "lib/file/vfs",
796 "lib/pch",
797 "lib/posix",
798 "lib/res",
799 "lib/res/graphics",
800 "lib/sysdep",
801 "lib/tex"
803 extern_libs = {
804 "boost",
805 "sdl",
806 "openal",
807 "opengl",
808 "libpng",
809 "zlib",
810 "valgrind",
811 "cxxtest",
814 -- CPU architecture-specific
815 if arch == "amd64" then
816 table.insert(source_dirs, "lib/sysdep/arch/amd64");
817 table.insert(source_dirs, "lib/sysdep/arch/x86_x64");
818 elseif arch == "x86" then
819 table.insert(source_dirs, "lib/sysdep/arch/ia32");
820 table.insert(source_dirs, "lib/sysdep/arch/x86_x64");
821 elseif arch == "arm" then
822 table.insert(source_dirs, "lib/sysdep/arch/arm");
823 elseif arch == "aarch64" then
824 table.insert(source_dirs, "lib/sysdep/arch/aarch64");
827 -- OS-specific
828 sysdep_dirs = {
829 linux = { "lib/sysdep/os/linux", "lib/sysdep/os/unix" },
830 -- note: RC file must be added to main_exe project.
831 -- note: don't add "lib/sysdep/os/win/aken.cpp" because that must be compiled with the DDK.
832 windows = { "lib/sysdep/os/win", "lib/sysdep/os/win/wposix", "lib/sysdep/os/win/whrt" },
833 macosx = { "lib/sysdep/os/osx", "lib/sysdep/os/unix" },
834 bsd = { "lib/sysdep/os/bsd", "lib/sysdep/os/unix", "lib/sysdep/os/unix/x" },
836 for i,v in pairs(sysdep_dirs[os.target()]) do
837 table.insert(source_dirs, v);
840 if os.istarget("linux") then
841 if _OPTIONS["android"] then
842 table.insert(source_dirs, "lib/sysdep/os/android")
843 else
844 table.insert(source_dirs, "lib/sysdep/os/unix/x")
848 -- On OSX, disable precompiled headers because C++ files and Objective-C++ files are
849 -- mixed in this project. To fix that, we would need per-file basis configuration which
850 -- is not yet supported by the gmake action in premake. We should look into using gmake2.
851 extra_params = {}
852 if os.istarget("macosx") then
853 extra_params = { no_pch = 1 }
856 -- runtime-library-specific
857 if _ACTION == "vs2013" or _ACTION == "vs2015" then
858 table.insert(source_dirs, "lib/sysdep/rtl/msc");
859 else
860 table.insert(source_dirs, "lib/sysdep/rtl/gcc");
863 setup_static_lib_project("lowlevel", source_dirs, extern_libs, extra_params)
866 -- Third-party libraries that are built as part of the main project,
867 -- not built externally and then linked
868 source_dirs = {
869 "third_party/mongoose",
871 extern_libs = {
873 setup_static_lib_project("mongoose", source_dirs, extern_libs, { no_pch = 1 })
876 -- CxxTest mock function support
877 extern_libs = {
878 "boost",
879 "cxxtest",
882 -- 'real' implementations, to be linked against the main executable
883 -- (files are added manually and not with setup_static_lib_project
884 -- because not all files in the directory are included)
885 setup_static_lib_project("mocks_real", {}, extern_libs, { no_default_link = 1, no_pch = 1 })
886 files { "mocks/*.h", source_root.."mocks/*_real.cpp" }
887 -- 'test' implementations, to be linked against the test executable
888 setup_static_lib_project("mocks_test", {}, extern_libs, { no_default_link = 1, no_pch = 1 })
889 files { source_root.."mocks/*.h", source_root.."mocks/*_test.cpp" }
892 --------------------------------------------------------------------------------
893 -- main EXE
894 --------------------------------------------------------------------------------
896 -- used for main EXE as well as test
897 used_extern_libs = {
898 "opengl",
899 "sdl",
901 "libpng",
902 "zlib",
904 "spidermonkey",
905 "libxml2",
907 "boost",
908 "cxxtest",
909 "comsuppw",
910 "enet",
911 "libcurl",
912 "tinygettext",
913 "icu",
914 "iconv",
916 "valgrind",
919 if not os.istarget("windows") and not _OPTIONS["android"] and not os.istarget("macosx") then
920 -- X11 should only be linked on *nix
921 table.insert(used_extern_libs, "x11")
922 table.insert(used_extern_libs, "xcursor")
925 if not _OPTIONS["without-audio"] then
926 table.insert(used_extern_libs, "openal")
927 table.insert(used_extern_libs, "vorbis")
930 if not _OPTIONS["without-nvtt"] then
931 table.insert(used_extern_libs, "nvtt")
934 if not _OPTIONS["without-lobby"] then
935 table.insert(used_extern_libs, "gloox")
938 if not _OPTIONS["without-miniupnpc"] then
939 table.insert(used_extern_libs, "miniupnpc")
942 -- Bundles static libs together with main.cpp and builds game executable.
943 function setup_main_exe ()
945 local target_type = get_main_project_target_type()
946 project_create("pyrogenesis", target_type)
948 filter "system:not macosx"
949 linkgroups 'On'
950 filter {}
952 links { "mocks_real" }
954 local extra_params = {
955 extra_files = { "main.cpp" },
956 no_pch = 1
958 project_add_contents(source_root, {}, {}, extra_params)
959 project_add_extern_libs(used_extern_libs, target_type)
960 project_add_x11_dirs()
962 dependson { "Collada" }
964 -- Platform Specifics
965 if os.istarget("windows") then
967 files { source_root.."lib/sysdep/os/win/icon.rc" }
968 -- from "lowlevel" static lib; must be added here to be linked in
969 files { source_root.."lib/sysdep/os/win/error_dialog.rc" }
971 rtti "off"
973 linkoptions {
974 -- wraps main thread in a __try block(see wseh.cpp). replace with mainCRTStartup if that's undesired.
975 "/ENTRY:wseh_EntryPoint",
977 -- see wstartup.h
978 "/INCLUDE:_wstartup_InitAndRegisterShutdown",
980 -- allow manual unload of delay-loaded DLLs
981 "/DELAY:UNLOAD",
984 -- allow the executable to use more than 2GB of RAM.
985 -- this should not be enabled during development, so that memory issues are easily spotted.
986 if _OPTIONS["large-address-aware"] then
987 linkoptions { "/LARGEADDRESSAWARE" }
990 -- see manifest.cpp
991 project_add_manifest()
993 elseif os.istarget("linux") or os.istarget("bsd") then
995 if not _OPTIONS["android"] and not (os.getversion().description == "OpenBSD") then
996 links { "rt" }
999 if _OPTIONS["android"] then
1000 -- NDK's STANDALONE-TOOLCHAIN.html says this is required
1001 linkoptions { "-Wl,--fix-cortex-a8" }
1003 links { "log" }
1006 if os.istarget("linux") or os.getversion().description == "GNU/kFreeBSD" then
1007 links {
1008 -- Dynamic libraries (needed for linking for gold)
1009 "dl",
1011 elseif os.istarget("bsd") then
1012 links {
1013 -- Needed for backtrace* on BSDs
1014 "execinfo",
1018 -- Threading support
1019 buildoptions { "-pthread" }
1020 if not _OPTIONS["android"] then
1021 linkoptions { "-pthread" }
1024 -- For debug_resolve_symbol
1025 filter "Debug"
1026 linkoptions { "-rdynamic" }
1027 filter { }
1029 elseif os.istarget("macosx") then
1031 links { "pthread" }
1032 links { "ApplicationServices.framework", "Cocoa.framework", "CoreFoundation.framework" }
1038 --------------------------------------------------------------------------------
1039 -- atlas
1040 --------------------------------------------------------------------------------
1042 -- setup a typical Atlas component project
1043 -- extra_params, rel_source_dirs and rel_include_dirs: as in project_add_contents;
1044 function setup_atlas_project(project_name, target_type, rel_source_dirs, rel_include_dirs, extern_libs, extra_params)
1046 local source_root = rootdir.."/source/tools/atlas/" .. project_name .. "/"
1047 project_create(project_name, target_type)
1049 -- if not specified, the default for atlas pch files is in the project root.
1050 if not extra_params["pch_dir"] then
1051 extra_params["pch_dir"] = source_root
1054 project_add_contents(source_root, rel_source_dirs, rel_include_dirs, extra_params)
1055 project_add_extern_libs(extern_libs, target_type)
1056 project_add_x11_dirs()
1058 -- Platform Specifics
1059 if os.istarget("windows") then
1060 -- Link to required libraries
1061 links { "winmm", "comctl32", "rpcrt4", "delayimp", "ws2_32" }
1063 elseif os.istarget("linux") or os.istarget("bsd") then
1064 buildoptions { "-rdynamic", "-fPIC" }
1065 linkoptions { "-fPIC", "-rdynamic" }
1067 -- warnings triggered by wxWidgets
1068 buildoptions { "-Wno-unused-local-typedefs" }
1070 elseif os.istarget("macosx") then
1071 -- install_name settings aren't really supported yet by premake, but there are plans for the future.
1072 -- we currently use this hack to work around some bugs with wrong install_names.
1073 if target_type == "SharedLib" then
1074 if _OPTIONS["macosx-bundle"] then
1075 -- If we're building a bundle, it will be in ../Frameworks
1076 filter "Debug"
1077 linkoptions { "-install_name @executable_path/../Frameworks/lib"..project_name.."_dbg.dylib" }
1078 filter "Release"
1079 linkoptions { "-install_name @executable_path/../Frameworks/lib"..project_name..".dylib" }
1080 filter { }
1081 else
1082 filter "Debug"
1083 linkoptions { "-install_name @executable_path/lib"..project_name.."_dbg.dylib" }
1084 filter "Release"
1085 linkoptions { "-install_name @executable_path/lib"..project_name..".dylib" }
1086 filter { }
1094 -- build all Atlas component projects
1095 function setup_atlas_projects()
1097 setup_atlas_project("AtlasObject", "StaticLib",
1098 { -- src
1099 ".",
1100 "../../../third_party/jsonspirit"
1102 },{ -- include
1103 "../../../third_party/jsonspirit"
1104 },{ -- extern_libs
1105 "boost",
1106 "iconv",
1107 "libxml2",
1108 "wxwidgets"
1109 },{ -- extra_params
1110 no_pch = 1
1113 atlas_src = {
1114 "ActorEditor",
1115 "CustomControls/Buttons",
1116 "CustomControls/Canvas",
1117 "CustomControls/ColorDialog",
1118 "CustomControls/DraggableListCtrl",
1119 "CustomControls/EditableListCtrl",
1120 "CustomControls/FileHistory",
1121 "CustomControls/HighResTimer",
1122 "CustomControls/MapDialog",
1123 "CustomControls/SnapSplitterWindow",
1124 "CustomControls/VirtualDirTreeCtrl",
1125 "CustomControls/Windows",
1126 "General",
1127 "General/VideoRecorder",
1128 "Misc",
1129 "ScenarioEditor",
1130 "ScenarioEditor/Sections/Common",
1131 "ScenarioEditor/Sections/Cinema",
1132 "ScenarioEditor/Sections/Environment",
1133 "ScenarioEditor/Sections/Map",
1134 "ScenarioEditor/Sections/Object",
1135 "ScenarioEditor/Sections/Player",
1136 "ScenarioEditor/Sections/Terrain",
1137 "ScenarioEditor/Tools",
1138 "ScenarioEditor/Tools/Common",
1140 atlas_extra_links = {
1141 "AtlasObject"
1144 atlas_extern_libs = {
1145 "boost",
1146 "comsuppw",
1147 "iconv",
1148 "libxml2",
1149 "sdl", -- key definitions
1150 "wxwidgets",
1151 "zlib",
1153 if not os.istarget("windows") and not os.istarget("macosx") then
1154 -- X11 should only be linked on *nix
1155 table.insert(atlas_extern_libs, "x11")
1158 setup_atlas_project("AtlasUI", "SharedLib", atlas_src,
1159 { -- include
1160 "..",
1161 "CustomControls",
1162 "Misc"
1164 atlas_extern_libs,
1165 { -- extra_params
1166 pch_dir = rootdir.."/source/tools/atlas/AtlasUI/Misc/",
1167 no_pch = false,
1168 extra_links = atlas_extra_links,
1169 extra_files = { "Misc/atlas.rc" }
1174 -- Atlas 'frontend' tool-launching projects
1175 function setup_atlas_frontend_project (project_name)
1177 local target_type = get_main_project_target_type()
1178 project_create(project_name, target_type)
1179 project_add_x11_dirs()
1181 local source_root = rootdir.."/source/tools/atlas/AtlasFrontends/"
1182 files { source_root..project_name..".cpp" }
1184 if os.istarget("windows") then
1185 files { source_root..project_name..".rc" }
1188 includedirs { source_root .. ".." }
1190 -- Platform Specifics
1191 if os.istarget("windows") then
1192 -- see manifest.cpp
1193 project_add_manifest()
1195 else -- Non-Windows, = Unix
1196 links { "AtlasObject" }
1199 links { "AtlasUI" }
1203 function setup_atlas_frontends()
1204 setup_atlas_frontend_project("ActorEditor")
1208 --------------------------------------------------------------------------------
1209 -- collada
1210 --------------------------------------------------------------------------------
1212 function setup_collada_project(project_name, target_type, rel_source_dirs, rel_include_dirs, extern_libs, extra_params)
1214 project_create(project_name, target_type)
1215 local source_root = source_root.."collada/"
1216 extra_params["pch_dir"] = source_root
1217 project_add_contents(source_root, rel_source_dirs, rel_include_dirs, extra_params)
1218 project_add_extern_libs(extern_libs, target_type)
1219 project_add_x11_dirs()
1221 -- Platform Specifics
1222 if os.istarget("windows") then
1223 characterset "MBCS"
1224 elseif os.istarget("linux") then
1225 defines { "LINUX" }
1227 links {
1228 "dl",
1231 -- FCollada is not aliasing-safe, so disallow dangerous optimisations
1232 -- (TODO: It'd be nice to fix FCollada, but that looks hard)
1233 buildoptions { "-fno-strict-aliasing" }
1235 buildoptions { "-rdynamic" }
1236 linkoptions { "-rdynamic" }
1238 elseif os.istarget("bsd") then
1239 if os.getversion().description == "OpenBSD" then
1240 links { "c", }
1243 if os.getversion().description == "GNU/kFreeBSD" then
1244 links {
1245 "dl",
1249 buildoptions { "-fno-strict-aliasing" }
1251 buildoptions { "-rdynamic" }
1252 linkoptions { "-rdynamic" }
1254 elseif os.istarget("macosx") then
1255 -- define MACOS-something?
1257 -- install_name settings aren't really supported yet by premake, but there are plans for the future.
1258 -- we currently use this hack to work around some bugs with wrong install_names.
1259 if target_type == "SharedLib" then
1260 if _OPTIONS["macosx-bundle"] then
1261 -- If we're building a bundle, it will be in ../Frameworks
1262 linkoptions { "-install_name @executable_path/../Frameworks/lib"..project_name..".dylib" }
1263 else
1264 linkoptions { "-install_name @executable_path/lib"..project_name..".dylib" }
1268 buildoptions { "-fno-strict-aliasing" }
1269 -- On OSX, fcollada uses a few utility functions from coreservices
1270 links { "CoreServices.framework" }
1275 -- build all Collada component projects
1276 function setup_collada_projects()
1278 setup_collada_project("Collada", "SharedLib",
1279 { -- src
1281 },{ -- include
1282 },{ -- extern_libs
1283 "fcollada",
1284 "iconv",
1285 "libxml2"
1286 },{ -- extra_params
1292 --------------------------------------------------------------------------------
1293 -- tests
1294 --------------------------------------------------------------------------------
1296 function setup_tests()
1298 local cxxtest = require "cxxtest"
1300 if os.istarget("windows") then
1301 cxxtest.setpath(rootdir.."/build/bin/cxxtestgen.exe")
1302 else
1303 cxxtest.setpath(rootdir.."/libraries/source/cxxtest-4.4/bin/cxxtestgen")
1306 local runner = "ErrorPrinter"
1307 if _OPTIONS["jenkins-tests"] then
1308 runner = "XmlPrinter"
1311 local includefiles = {
1312 -- Precompiled headers - the header is added to all generated .cpp files
1313 -- note that the header isn't actually precompiled here, only #included
1314 -- so that the build stage can use it as a precompiled header.
1315 "precompiled.h",
1316 -- This is required to build against SDL 2.0.4 on Windows.
1317 "lib/external_libraries/libsdl.h",
1320 cxxtest.init(source_root, true, runner, includefiles)
1322 local target_type = get_main_project_target_type()
1323 project_create("test", target_type)
1325 -- Find header files in 'test' subdirectories
1326 local all_files = os.matchfiles(source_root .. "**/tests/*.h")
1327 local test_files = {}
1328 for i,v in pairs(all_files) do
1329 -- Don't include sysdep tests on the wrong sys
1330 -- Don't include Atlas tests unless Atlas is being built
1331 if not (string.find(v, "/sysdep/os/win/") and not os.istarget("windows")) and
1332 not (string.find(v, "/tools/atlas/") and not _OPTIONS["atlas"]) and
1333 not (string.find(v, "/sysdep/arch/x86_x64/") and ((arch ~= "amd64") or (arch ~= "x86")))
1334 then
1335 table.insert(test_files, v)
1339 cxxtest.configure_project(test_files)
1341 filter "system:not macosx"
1342 linkgroups 'On'
1343 filter {}
1345 links { static_lib_names }
1346 filter "Debug"
1347 links { static_lib_names_debug }
1348 filter "Release"
1349 links { static_lib_names_release }
1350 filter { }
1352 links { "mocks_test" }
1353 if _OPTIONS["atlas"] then
1354 links { "AtlasObject" }
1355 project_add_extern_libs({"wxwidgets"}, target_type)
1357 extra_params = {
1358 extra_files = { "test_setup.cpp" },
1361 project_add_contents(source_root, {}, {}, extra_params)
1362 project_add_extern_libs(used_extern_libs, target_type)
1363 project_add_x11_dirs()
1365 dependson { "Collada" }
1367 -- TODO: should fix the duplication between this OS-specific linking
1368 -- code, and the similar version in setup_main_exe
1370 if os.istarget("windows") then
1371 -- from "lowlevel" static lib; must be added here to be linked in
1372 files { source_root.."lib/sysdep/os/win/error_dialog.rc" }
1374 rtti "off"
1376 -- see wstartup.h
1377 linkoptions { "/INCLUDE:_wstartup_InitAndRegisterShutdown" }
1378 -- Enables console for the TEST project on Windows
1379 linkoptions { "/SUBSYSTEM:CONSOLE" }
1381 project_add_manifest()
1383 elseif os.istarget("linux") or os.istarget("bsd") then
1385 if not _OPTIONS["android"] and not (os.getversion().description == "OpenBSD") then
1386 links { "rt" }
1389 if _OPTIONS["android"] then
1390 -- NDK's STANDALONE-TOOLCHAIN.html says this is required
1391 linkoptions { "-Wl,--fix-cortex-a8" }
1394 if os.istarget("linux") or os.getversion().description == "GNU/kFreeBSD" then
1395 links {
1396 -- Dynamic libraries (needed for linking for gold)
1397 "dl",
1399 elseif os.istarget("bsd") then
1400 links {
1401 -- Needed for backtrace* on BSDs
1402 "execinfo",
1406 -- Threading support
1407 buildoptions { "-pthread" }
1408 if not _OPTIONS["android"] then
1409 linkoptions { "-pthread" }
1412 -- For debug_resolve_symbol
1413 filter "Debug"
1414 linkoptions { "-rdynamic" }
1415 filter { }
1417 includedirs { source_root .. "pch/test/" }
1421 -- must come first, so that VC sets it as the default project and therefore
1422 -- allows running via F5 without the "where is the EXE" dialog.
1423 setup_main_exe()
1425 setup_all_libs()
1427 -- add the static libs to the main EXE project. only now (after
1428 -- setup_all_libs has run) are the lib names known. cannot move
1429 -- setup_main_exe to run after setup_all_libs (see comment above).
1430 -- we also don't want to hardcode the names - that would require more
1431 -- work when changing the static lib breakdown.
1432 project("pyrogenesis") -- Set the main project active
1433 links { static_lib_names }
1434 filter "Debug"
1435 links { static_lib_names_debug }
1436 filter "Release"
1437 links { static_lib_names_release }
1438 filter { }
1440 if _OPTIONS["atlas"] then
1441 setup_atlas_projects()
1442 setup_atlas_frontends()
1445 setup_collada_projects()
1447 if not _OPTIONS["without-tests"] then
1448 setup_tests()