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-mozjs", description
= "Search standard paths for libmozjs91, 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
= "with-valgrind", description
= "Enable Valgrind support (non-Windows only)" }
12 newoption
{ trigger
= "without-audio", description
= "Disable use of OpenAL/Ogg/Vorbis APIs" }
13 newoption
{ trigger
= "without-lobby", description
= "Disable the use of gloox and the multiplayer lobby" }
14 newoption
{ trigger
= "without-miniupnpc", description
= "Disable use of miniupnpc for port forwarding" }
15 newoption
{ trigger
= "without-nvtt", description
= "Disable use of NVTT" }
16 newoption
{ trigger
= "without-pch", description
= "Disable generation and usage of precompiled headers" }
17 newoption
{ trigger
= "without-tests", description
= "Disable generation of test projects" }
19 -- Linux/BSD specific options
20 newoption
{ trigger
= "prefer-local-libs", description
= "Prefer locally built libs. Any local libraries used must also be listed within a file within /etc/ld.so.conf.d so the dynamic linker can find them at runtime." }
22 -- OS X specific options
23 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)" }
24 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" }
26 -- Windows specific options
27 newoption
{ trigger
= "build-shared-glooxwrapper", description
= "Rebuild glooxwrapper DLL for Windows. Requires the same compiler version that gloox was built with" }
28 newoption
{ trigger
= "use-shared-glooxwrapper", description
= "Use prebuilt glooxwrapper DLL for Windows" }
29 newoption
{ trigger
= "large-address-aware", description
= "Make the executable large address aware. Do not use for development, in order to spot memory issues easily" }
32 newoption
{ trigger
= "bindir", description
= "Directory for executables (typically '/usr/games'); default is to be relocatable" }
33 newoption
{ trigger
= "datadir", description
= "Directory for data files (typically '/usr/share/games/0ad'); default is ../data/ relative to executable" }
34 newoption
{ trigger
= "libdir", description
= "Directory for libraries (typically '/usr/lib/games/0ad'); default is ./ relative to executable" }
36 -- Root directory of project checkout relative to this .lua file
39 dofile("extern_libs5.lua")
41 -- detect compiler for non-Windows
42 if os
.istarget("macosx") then
44 elseif os
.istarget("linux") and _OPTIONS
["icc"] then
46 elseif os
.istarget("bsd") and os
.getversion().description
== "FreeBSD" then
48 elseif not os
.istarget("windows") then
50 if cc
== nil or cc
== "" then
51 local hasgcc
= os
.execute("which gcc > .gccpath")
52 local f
= io
.open(".gccpath", "r")
53 local gccpath
= f
:read("*line")
55 os
.execute("rm .gccpath")
56 if gccpath
== nil then
64 -- detect CPU architecture (simplistic)
65 -- The user can target an architecture with HOSTTYPE, but the game still selects some know value.
69 if _OPTIONS
["android"] then
71 elseif os
.istarget("windows") then
72 if os
.getenv("HOSTTYPE") then
73 arch
= os
.getenv("HOSTTYPE")
74 elseif os
.getenv("PROCESSOR_ARCHITECTURE") == "amd64" or os
.getenv("PROCESSOR_ARCHITEW6432") == "amd64" then
78 local machine
= "x86_64"
79 if os
.getenv("HOSTTYPE") and os
.getenv("HOSTTYPE") ~= '' then
80 machine
= os
.getenv("HOSTTYPE")
82 os
.execute(cc
.. " -dumpmachine > .gccmachine.tmp")
83 local f
= io
.open(".gccmachine.tmp", "r")
84 machine
= f
:read("*line")
87 -- Special handling on mac os where xcode needs special flags.
88 if os
.istarget("macosx") then
89 if string.find(machine
, "arm64") then
96 elseif string.find(machine
, "x86_64") == 1 or string.find(machine
, "amd64") == 1 then
98 elseif string.find(machine
, "i.86") == 1 then
100 elseif string.find(machine
, "arm") == 1 then
102 elseif string.find(machine
, "aarch64") == 1 then
104 elseif string.find(machine
, "e2k") == 1 then
106 elseif string.find(machine
, "ppc64") == 1 or string.find(machine
, "powerpc64") == 1 then
109 print("WARNING: Cannot determine architecture from GCC, assuming x86")
113 -- Test whether we need to link libexecinfo.
114 -- This is mostly the case on musl systems, as well as on BSD systems : only glibc provides the
115 -- backtrace symbols we require in the libc, for other libcs we use the libexecinfo library.
116 local link_execinfo
= false
117 if os
.istarget("bsd") then
119 elseif os
.istarget("linux") then
120 local _
, link_errorCode
= os
.outputof(cc
.. " ./tests/execinfo.c -o /dev/null")
121 if link_errorCode
~= 0 then
126 -- Set up the Workspace
127 workspace
"pyrogenesis"
128 targetdir(rootdir
.."/binaries/system")
129 libdirs(rootdir
.."/binaries/system")
130 if not _OPTIONS
["outpath"] then
131 error("You must specify the 'outpath' parameter")
133 location(_OPTIONS
["outpath"])
134 configurations
{ "Release", "Debug" }
136 source_root
= rootdir
.."/source/" -- default for most projects - overridden by local in others
138 -- Rationale: projects should not have any additional include paths except for
139 -- those required by external libraries. Instead, we should always write the
140 -- full relative path, e.g. #include "maths/Vector3d.h". This avoids confusion
141 -- ("which file is meant?") and avoids enormous include path lists.
144 -- projects: engine static libs, main exe, atlas, atlas frontends, test.
146 --------------------------------------------------------------------------------
147 -- project helper functions
148 --------------------------------------------------------------------------------
150 function project_set_target(project_name
)
152 -- Note: On Windows, ".exe" is added on the end, on unices the name is used directly
154 local obj_dir_prefix
= _OPTIONS
["outpath"].."/obj/"..project_name
.."_"
157 objdir(obj_dir_prefix
.."Debug")
161 objdir(obj_dir_prefix
.."Release")
168 function project_set_build_flags()
170 editandcontinue
"Off"
172 if not _OPTIONS
["minimal-flags"] then
176 if cc
~= "icc" and (os
.istarget("windows") or not _OPTIONS
["minimal-flags"]) then
177 -- adds the -Wall compiler flag
178 warnings
"Extra" -- this causes far too many warnings/remarks on ICC
181 -- disable Windows debug heap, since it makes malloc/free hugely slower when
182 -- running inside a debugger
183 if os
.istarget("windows") then
184 debugenvs
{ "_NO_DEBUG_HEAP=1" }
191 if os
.istarget("windows") or not _OPTIONS
["minimal-flags"] then
194 defines
{ "NDEBUG", "CONFIG_FINAL=1" }
198 if _OPTIONS
["gles"] then
199 defines
{ "CONFIG2_GLES=1" }
202 if _OPTIONS
["without-audio"] then
203 defines
{ "CONFIG2_AUDIO=0" }
206 if _OPTIONS
["without-nvtt"] then
207 defines
{ "CONFIG2_NVTT=0" }
210 if _OPTIONS
["without-lobby"] then
211 defines
{ "CONFIG2_LOBBY=0" }
214 if _OPTIONS
["without-miniupnpc"] then
215 defines
{ "CONFIG2_MINIUPNPC=0" }
218 -- Enable C++17 standard.
220 buildoptions
{ "/std:c++17" }
221 filter
"action:not vs*"
222 buildoptions
{ "-std=c++17" }
225 -- various platform-specific build flags
226 if os
.istarget("windows") then
228 flags
{ "MultiProcessorCompile" }
230 -- Since KB4088875 Windows 7 has a soft requirement for SSE2.
231 -- Windows 8+ and Firefox ESR52 make it hard requirement.
232 -- Finally since VS2012 it's enabled implicitely when not set.
233 vectorextensions
"SSE2"
235 -- use native wchar_t type (not typedef to unsigned short)
240 -- TODO, FIXME: This check is incorrect because it means that some additional flags will be added inside the "else" branch if the
241 -- compiler is ICC and minimal-flags is specified (ticket: #2994)
242 if cc
== "icc" and not _OPTIONS
["minimal-flags"] then
246 -- "-Wp64", -- complains about OBJECT_TO_JSVAL which is annoying
253 "-wd1292" -- avoid lots of 'attribute "__nonnull__" ignored'
256 buildoptions
{ "-O0" } -- ICC defaults to -O2
258 if os
.istarget("macosx") then
259 linkoptions
{ "-multiply_defined","suppress" }
262 -- exclude most non-essential build options for minimal-flags
263 if not _OPTIONS
["minimal-flags"] then
265 -- enable most of the standard warnings
266 "-Wno-switch", -- enumeration value not handled in switch (this is sometimes useful, but results in lots of noise)
267 "-Wno-reorder", -- order of initialization list in constructors (lots of noise)
268 "-Wno-invalid-offsetof", -- offsetof on non-POD types (see comment in renderer/PatchRData.cpp)
271 "-Wno-missing-field-initializers", -- (this is common in external headers we can't fix)
273 -- add some other useful warnings that need to be enabled explicitly
274 "-Wunused-parameter",
275 "-Wredundant-decls", -- (useful for finding some multiply-included header files)
276 -- "-Wformat=2", -- (useful sometimes, but a bit noisy, so skip it by default)
277 -- "-Wcast-qual", -- (useful for checking const-correctness, but a bit noisy, so skip it by default)
278 "-Wnon-virtual-dtor", -- (sometimes noisy but finds real bugs)
279 "-Wundef", -- (useful for finding macro name typos)
281 -- enable security features (stack checking etc) that shouldn't have
282 -- a significant effect on performance and can catch bugs
283 "-fstack-protector-all",
284 "-U_FORTIFY_SOURCE", -- (avoid redefinition warning if already defined)
285 "-D_FORTIFY_SOURCE=2",
287 -- always enable strict aliasing (useful in debug builds because of the warnings)
290 -- don't omit frame pointers (for now), because performance will be impacted
291 -- negatively by the way this breaks profilers more than it will be impacted
292 -- positively by the optimisation
293 "-fno-omit-frame-pointer"
296 if not _OPTIONS
["without-pch"] then
298 -- do something (?) so that ccache can handle compilation with PCH enabled
299 -- (ccache 3.1+ also requires CCACHE_SLOPPINESS=time_macros for this to work)
304 if os
.istarget("linux") or os
.istarget("bsd") then
305 buildoptions
{ "-fPIC" }
306 linkoptions
{ "-Wl,--no-undefined", "-Wl,--as-needed", "-Wl,-z,relro" }
309 if arch
== "x86" then
311 -- To support intrinsics like __sync_bool_compare_and_swap on x86
312 -- we need to set -march to something that supports them (i686).
313 -- We use pentium3 to also enable other features like mmx and sse,
314 -- while tuning for generic to have good performance on every
316 -- Note that all these features are already supported on amd64.
317 "-march=pentium3 -mtune=generic",
318 -- This allows x86 operating systems to handle the 2GB+ public mod.
319 "-D_FILE_OFFSET_BITS=64"
324 if arch
== "arm" then
325 -- disable warnings about va_list ABI change and use
326 -- compile-time flags for futher configuration.
327 buildoptions
{ "-Wno-psabi" }
328 if _OPTIONS
["android"] then
329 -- Android uses softfp, so we should too.
330 buildoptions
{ "-mfloat-abi=softfp" }
334 if _OPTIONS
["coverage"] then
335 buildoptions
{ "-fprofile-arcs", "-ftest-coverage" }
339 -- MacOS 10.12 only supports intel processors with SSE 4.1, so enable that.
340 if os
.istarget("macosx") and arch
== "amd64" then
341 buildoptions
{ "-msse4.1" }
344 -- Check if SDK path should be used
345 if _OPTIONS
["sysroot"] then
346 buildoptions
{ "-isysroot " .. _OPTIONS
["sysroot"] }
347 linkoptions
{ "-Wl,-syslibroot," .. _OPTIONS
["sysroot"] }
350 -- On OS X, sometimes we need to specify the minimum API version to use
351 if _OPTIONS
["macosx-version-min"] then
352 buildoptions
{ "-mmacosx-version-min=" .. _OPTIONS
["macosx-version-min"] }
353 -- clang and llvm-gcc look at mmacosx-version-min to determine link target
354 -- and CRT version, and use it to set the macosx_version_min linker flag
355 linkoptions
{ "-mmacosx-version-min=" .. _OPTIONS
["macosx-version-min"] }
358 -- Only libc++ is supported on MacOS
359 if os
.istarget("macosx") then
360 buildoptions
{ "-stdlib=libc++" }
361 linkoptions
{ "-stdlib=libc++" }
366 -- Hide symbols in dynamic shared objects by default, for efficiency and for equivalence with
367 -- Windows - they should be exported explicitly with __attribute__ ((visibility ("default")))
368 "-fvisibility=hidden"
371 if _OPTIONS
["bindir"] then
372 defines
{ "INSTALLED_BINDIR=" .. _OPTIONS
["bindir"] }
374 if _OPTIONS
["datadir"] then
375 defines
{ "INSTALLED_DATADIR=" .. _OPTIONS
["datadir"] }
377 if _OPTIONS
["libdir"] then
378 defines
{ "INSTALLED_LIBDIR=" .. _OPTIONS
["libdir"] }
381 if os
.istarget("linux") or os
.istarget("bsd") then
382 if _OPTIONS
["prefer-local-libs"] then
383 libdirs
{ "/usr/local/lib" }
386 -- To use our local shared libraries, they need to be found in the
387 -- runtime dynamic linker path. Add their path to -rpath.
388 if _OPTIONS
["libdir"] then
389 linkoptions
{"-Wl,-rpath," .. _OPTIONS
["libdir"] }
391 -- On FreeBSD we need to allow use of $ORIGIN
392 if os
.istarget("bsd") then
393 linkoptions
{ "-Wl,-z,origin" }
396 -- Adding the executable path and taking care of correct escaping
397 if _ACTION
== "gmake" then
398 linkoptions
{ "-Wl,-rpath,'$$ORIGIN'" }
399 elseif _ACTION
== "codeblocks" then
400 linkoptions
{ "-Wl,-R\\\\$$$ORIGIN" }
408 -- create a project and set the attributes that are common to all projects.
409 function project_create(project_name
, target_type
)
411 project(project_name
)
415 filter
"action:vs2017"
420 buildoptions
"/utf-8"
423 project_set_target(project_name
)
424 project_set_build_flags()
428 -- OSX creates a .app bundle if the project type of the main application is set to "WindowedApp".
429 -- We don't want this because this bundle would be broken (it lacks all the resources and external dependencies, Info.plist etc...)
430 -- Windows opens a console in the background if it's set to ConsoleApp, which is not what we want.
431 -- I didn't check if this setting matters for linux, but WindowedApp works there.
432 function get_main_project_target_type()
433 if _OPTIONS
["android"] then
435 elseif os
.istarget("macosx") then
443 -- source_root: rel_source_dirs and rel_include_dirs are relative to this directory
444 -- rel_source_dirs: A table of subdirectories. All source files in these directories are added.
445 -- rel_include_dirs: A table of subdirectories to be included.
446 -- extra_params: table including zero or more of the following:
447 -- * no_pch: If specified, no precompiled headers are used for this project.
448 -- * pch_dir: If specified, this directory will be used for precompiled headers instead of the default
449 -- <source_root>/pch/<projectname>/.
450 -- * extra_files: table of filenames (relative to source_root) to add to project
451 -- * extra_links: table of library names to add to link step
452 function project_add_contents(source_root
, rel_source_dirs
, rel_include_dirs
, extra_params
)
454 for i
,v
in pairs(rel_source_dirs
) do
455 local prefix
= source_root
..v
.."/"
456 files
{ prefix
.."*.cpp", prefix
.."*.h", prefix
.."*.inl", prefix
.."*.js", prefix
.."*.asm", prefix
.."*.mm" }
459 -- Put the project-specific PCH directory at the start of the
460 -- include path, so '#include "precompiled.h"' will look in
463 if not extra_params
["pch_dir"] then
464 pch_dir
= source_root
.. "pch/" .. project().name
.. "/"
466 pch_dir
= extra_params
["pch_dir"]
468 includedirs
{ pch_dir
}
470 -- Precompiled Headers
471 -- rationale: we need one PCH per static lib, since one global header would
472 -- increase dependencies. To that end, we can either include them as
473 -- "projectdir/precompiled.h", or add "source/PCH/projectdir" to the
474 -- include path and put the PCH there. The latter is better because
475 -- many projects contain several dirs and it's unclear where there the
476 -- PCH should be stored. This way is also a bit easier to use in that
477 -- source files always include "precompiled.h".
479 -- * Visual Assist manages to use the project include path and can
480 -- correctly open these files from the IDE.
481 -- * precompiled.cpp (needed to "Create" the PCH) also goes in
482 -- the abovementioned dir.
483 if (not _OPTIONS
["without-pch"] and not extra_params
["no_pch"]) then
485 pchheader("precompiled.h")
486 filter
"action:xcode*"
487 pchheader("../"..pch_dir
.."precompiled.h")
488 filter
{ "action:not vs*", "action:not xcode*" }
489 pchheader(pch_dir
.."precompiled.h")
491 pchsource(pch_dir
.."precompiled.cpp")
492 defines
{ "CONFIG_ENABLE_PCH=1" }
493 files
{ pch_dir
.."precompiled.h", pch_dir
.."precompiled.cpp" }
495 defines
{ "CONFIG_ENABLE_PCH=0" }
499 -- next is source root dir, for absolute (nonrelative) includes
500 -- (e.g. "lib/precompiled.h")
501 includedirs
{ source_root
}
503 for i
,v
in pairs(rel_include_dirs
) do
504 includedirs
{ source_root
.. v
}
507 if extra_params
["extra_files"] then
508 for i
,v
in pairs(extra_params
["extra_files"]) do
509 -- .rc files are only needed on Windows
510 if path
.getextension(v
) ~= ".rc" or os
.istarget("windows") then
511 files
{ source_root
.. v
}
516 if extra_params
["extra_links"] then
517 links
{ extra_params
["extra_links"] }
522 -- Add command-line options to set up the manifest dependencies for Windows
523 -- (See lib/sysdep/os/win/manifest.cpp)
524 function project_add_manifest()
525 linkoptions
{ "\"/manifestdependency:type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='X86' publicKeyToken='6595b64144ccf1df'\"" }
528 --------------------------------------------------------------------------------
529 -- engine static libraries
530 --------------------------------------------------------------------------------
532 -- the engine is split up into several static libraries. this eases separate
533 -- distribution of those components, reduces dependencies a bit, and can
534 -- also speed up builds.
535 -- more to the point, it is necessary to efficiently support a separate
536 -- test executable that also includes much of the game code.
538 -- names of all static libs created. automatically added to the
539 -- main app project later (see explanation at end of this file)
540 static_lib_names
= {}
541 static_lib_names_debug
= {}
542 static_lib_names_release
= {}
544 -- set up one of the static libraries into which the main engine code is split.
546 -- no_default_link: If specified, linking won't be done by default.
547 -- For the rest of extra_params, see project_add_contents().
548 -- note: rel_source_dirs and rel_include_dirs are relative to global source_root.
549 function setup_static_lib_project (project_name
, rel_source_dirs
, extern_libs
, extra_params
)
551 local target_type
= "StaticLib"
552 project_create(project_name
, target_type
)
553 project_add_contents(source_root
, rel_source_dirs
, {}, extra_params
)
554 project_add_extern_libs(extern_libs
, target_type
)
556 if not extra_params
["no_default_link"] then
557 table.insert(static_lib_names
, project_name
)
560 -- Deactivate Run Time Type Information. Performance of dynamic_cast is very poor.
561 -- The exception to this principle is Atlas UI, which is not a static library.
564 if os
.istarget("macosx") then
565 architecture(macos_arch
)
566 buildoptions
{ "-arch " .. macos_arch
}
567 linkoptions
{ "-arch " .. macos_arch
}
568 xcodebuildsettings
{ ARCHS
= macos_arch
}
569 if _OPTIONS
["macosx-version-min"] then
570 xcodebuildsettings
{ MACOSX_DEPLOYMENT_TARGET
= _OPTIONS
["macosx-version-min"] }
575 function setup_third_party_static_lib_project (project_name
, rel_source_dirs
, extern_libs
, extra_params
)
577 setup_static_lib_project(project_name
, rel_source_dirs
, extern_libs
, extra_params
)
578 includedirs
{ source_root
.. "third_party/" .. project_name
.. "/include/" }
581 function setup_shared_lib_project (project_name
, rel_source_dirs
, extern_libs
, extra_params
)
583 local target_type
= "SharedLib"
584 project_create(project_name
, target_type
)
585 project_add_contents(source_root
, rel_source_dirs
, {}, extra_params
)
586 project_add_extern_libs(extern_libs
, target_type
)
588 if not extra_params
["no_default_link"] then
589 table.insert(static_lib_names
, project_name
)
592 if os
.istarget("windows") then
594 elseif os
.istarget("macosx") then
595 architecture(macos_arch
)
596 buildoptions
{ "-arch " .. macos_arch
}
597 linkoptions
{ "-arch " .. macos_arch
}
598 xcodebuildsettings
{ ARCHS
= macos_arch
}
599 if _OPTIONS
["macosx-version-min"] then
600 xcodebuildsettings
{ MACOSX_DEPLOYMENT_TARGET
= _OPTIONS
["macosx-version-min"] }
606 -- this is where the source tree is chopped up into static libs.
607 -- can be changed very easily; just copy+paste a new setup_static_lib_project,
608 -- or remove existing ones. static libs are automagically added to
609 -- main_exe link step.
610 function setup_all_libs ()
612 -- relative to global source_root.
613 local source_dirs
= {}
614 -- names of external libraries used (see libraries_dir comment)
615 local extern_libs
= {}
625 "boost", -- dragged in via server->simulation.h->random and NetSession.h->lockfree
628 if not _OPTIONS
["without-miniupnpc"] then
629 table.insert(extern_libs
, "miniupnpc")
631 setup_static_lib_project("network", source_dirs
, extern_libs
, {})
637 "boost", -- dragged in via simulation.h and scriptinterface.h
641 setup_static_lib_project("rlinterface", source_dirs
, extern_libs
, { no_pch
= 1 })
644 "third_party/tinygettext/src",
651 setup_third_party_static_lib_project("tinygettext", source_dirs
, extern_libs
, { } )
653 -- 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
667 if not _OPTIONS
["without-lobby"] then
672 "third_party/encryption"
686 setup_static_lib_project("lobby", source_dirs
, extern_libs
, {})
688 if _OPTIONS
["use-shared-glooxwrapper"] and not _OPTIONS
["build-shared-glooxwrapper"] then
689 table.insert(static_lib_names_debug
, "glooxwrapper_dbg")
690 table.insert(static_lib_names_release
, "glooxwrapper")
693 "lobby/glooxwrapper",
700 if _OPTIONS
["build-shared-glooxwrapper"] then
701 setup_shared_lib_project("glooxwrapper", source_dirs
, extern_libs
, {})
703 setup_static_lib_project("glooxwrapper", source_dirs
, extern_libs
, {})
709 "third_party/encryption"
717 setup_static_lib_project("lobby", source_dirs
, extern_libs
, {})
718 files
{ source_root
.."lobby/Globals.cpp" }
724 "simulation2/components",
725 "simulation2/helpers",
726 "simulation2/scripting",
727 "simulation2/serialization",
728 "simulation2/system",
729 "simulation2/testcomponents",
736 setup_static_lib_project("simulation2", source_dirs
, extern_libs
, {})
741 "scriptinterface/third_party"
750 setup_static_lib_project("scriptinterface", source_dirs
, extern_libs
, {})
762 "soundmanager/items",
763 "soundmanager/scripting",
771 "sdl", -- key definitions
785 if not _OPTIONS
["without-audio"] then
786 table.insert(extern_libs
, "openal")
787 table.insert(extern_libs
, "vorbis")
790 setup_static_lib_project("engine", source_dirs
, extern_libs
, {})
795 "graphics/scripting",
798 "renderer/backend/dummy",
799 "renderer/backend/gl",
800 "renderer/backend/vulkan",
801 "renderer/scripting",
802 "third_party/mikktspace",
803 "third_party/ogre3d_preprocessor",
807 "sdl", -- key definitions
808 "spidermonkey", -- for graphics/scripting
814 if not _OPTIONS
["without-nvtt"] then
815 table.insert(extern_libs
, "nvtt")
817 setup_static_lib_project("graphics", source_dirs
, extern_libs
, {})
821 "tools/atlas/GameInterface",
822 "tools/atlas/GameInterface/Handlers"
826 "sdl", -- key definitions
830 setup_static_lib_project("atlas", source_dirs
, extern_libs
, {})
843 "sdl", -- key definitions
851 if not _OPTIONS
["without-audio"] then
852 table.insert(extern_libs
, "openal")
854 setup_static_lib_project("gui", source_dirs
, extern_libs
, {})
861 "lib/external_libraries",
885 -- CPU architecture-specific
886 if arch
== "amd64" then
887 table.insert(source_dirs
, "lib/sysdep/arch/amd64");
888 table.insert(source_dirs
, "lib/sysdep/arch/x86_x64");
889 elseif arch
== "x86" then
890 table.insert(source_dirs
, "lib/sysdep/arch/ia32");
891 table.insert(source_dirs
, "lib/sysdep/arch/x86_x64");
892 elseif arch
== "arm" then
893 table.insert(source_dirs
, "lib/sysdep/arch/arm");
894 elseif arch
== "aarch64" then
895 table.insert(source_dirs
, "lib/sysdep/arch/aarch64");
896 elseif arch
== "e2k" then
897 table.insert(source_dirs
, "lib/sysdep/arch/e2k");
898 elseif arch
== "ppc64" then
899 table.insert(source_dirs
, "lib/sysdep/arch/ppc64");
904 linux
= { "lib/sysdep/os/linux", "lib/sysdep/os/unix" },
905 -- note: RC file must be added to main_exe project.
906 -- note: don't add "lib/sysdep/os/win/aken.cpp" because that must be compiled with the DDK.
907 windows
= { "lib/sysdep/os/win", "lib/sysdep/os/win/wposix", "lib/sysdep/os/win/whrt" },
908 macosx
= { "lib/sysdep/os/osx", "lib/sysdep/os/unix" },
909 bsd
= { "lib/sysdep/os/bsd", "lib/sysdep/os/unix", "lib/sysdep/os/unix/x" },
911 for i
,v
in pairs(sysdep_dirs
[os
.target()]) do
912 table.insert(source_dirs
, v
);
915 if os
.istarget("linux") then
916 if _OPTIONS
["android"] then
917 table.insert(source_dirs
, "lib/sysdep/os/android")
919 table.insert(source_dirs
, "lib/sysdep/os/unix/x")
923 -- On OSX, disable precompiled headers because C++ files and Objective-C++ files are
924 -- mixed in this project. To fix that, we would need per-file basis configuration which
925 -- is not yet supported by the gmake action in premake. We should look into using gmake2.
927 if os
.istarget("macosx") then
928 extra_params
= { no_pch
= 1 }
931 -- runtime-library-specific
932 if _ACTION
== "vs2017" then
933 table.insert(source_dirs
, "lib/sysdep/rtl/msc");
935 table.insert(source_dirs
, "lib/sysdep/rtl/gcc");
938 setup_static_lib_project("lowlevel", source_dirs
, extern_libs
, extra_params
)
941 extern_libs
= { "glad" }
942 if not os
.istarget("windows") and not _OPTIONS
["android"] and not os
.istarget("macosx") then
943 -- X11 should only be linked on *nix
944 table.insert(used_extern_libs
, "x11")
946 setup_static_lib_project("gladwrapper", {}, used_extern_libs
, { no_pch
= 1 })
947 glad_path
= libraries_source_dir
.."glad/"
948 sysincludedirs
{ glad_path
.."include" }
949 files
{ glad_path
.."src/vulkan.cpp" }
950 if _OPTIONS
["gles"] then
951 files
{ glad_path
.."src/gles2.cpp" }
953 files
{ glad_path
.."src/gl.cpp" }
954 if os
.istarget("windows") then
955 files
{ glad_path
.."src/wgl.cpp" }
956 elseif os
.istarget("linux") or os
.istarget("bsd") then
957 files
{ glad_path
.."src/egl.cpp", glad_path
.."src/glx.cpp" }
962 -- Third-party libraries that are built as part of the main project,
963 -- not built externally and then linked
965 "third_party/mongoose",
969 setup_static_lib_project("mongoose", source_dirs
, extern_libs
, { no_pch
= 1 })
972 -- CxxTest mock function support
978 -- 'real' implementations, to be linked against the main executable
979 -- (files are added manually and not with setup_static_lib_project
980 -- because not all files in the directory are included)
981 setup_static_lib_project("mocks_real", {}, extern_libs
, { no_default_link
= 1, no_pch
= 1 })
982 files
{ "mocks/*.h", source_root
.."mocks/*_real.cpp" }
983 -- 'test' implementations, to be linked against the test executable
984 setup_static_lib_project("mocks_test", {}, extern_libs
, { no_default_link
= 1, no_pch
= 1 })
985 files
{ source_root
.."mocks/*.h", source_root
.."mocks/*_test.cpp" }
988 --------------------------------------------------------------------------------
990 --------------------------------------------------------------------------------
992 -- used for main EXE as well as test
1017 if not os
.istarget("windows") and not _OPTIONS
["android"] and not os
.istarget("macosx") then
1018 -- X11 should only be linked on *nix
1019 table.insert(used_extern_libs
, "x11")
1022 if not _OPTIONS
["without-audio"] then
1023 table.insert(used_extern_libs
, "openal")
1024 table.insert(used_extern_libs
, "vorbis")
1027 if not _OPTIONS
["without-nvtt"] then
1028 table.insert(used_extern_libs
, "nvtt")
1031 if not _OPTIONS
["without-lobby"] then
1032 table.insert(used_extern_libs
, "gloox")
1035 if not _OPTIONS
["without-miniupnpc"] then
1036 table.insert(used_extern_libs
, "miniupnpc")
1039 -- Bundles static libs together with main.cpp and builds game executable.
1040 function setup_main_exe ()
1042 local target_type
= get_main_project_target_type()
1043 project_create("pyrogenesis", target_type
)
1045 filter
"system:not macosx"
1049 links
{ "mocks_real" }
1051 local extra_params
= {
1052 extra_files
= { "main.cpp" },
1055 project_add_contents(source_root
, {}, {}, extra_params
)
1056 project_add_extern_libs(used_extern_libs
, target_type
)
1058 dependson
{ "Collada" }
1062 -- Platform Specifics
1063 if os
.istarget("windows") then
1065 files
{ source_root
.."lib/sysdep/os/win/icon.rc" }
1066 -- from "lowlevel" static lib; must be added here to be linked in
1067 files
{ source_root
.."lib/sysdep/os/win/error_dialog.rc" }
1070 -- wraps main thread in a __try block(see wseh.cpp). replace with mainCRTStartup if that's undesired.
1071 "/ENTRY:wseh_EntryPoint",
1074 "/INCLUDE:_wstartup_InitAndRegisterShutdown",
1076 -- allow manual unload of delay-loaded DLLs
1080 -- allow the executable to use more than 2GB of RAM.
1081 -- this should not be enabled during development, so that memory issues are easily spotted.
1082 if _OPTIONS
["large-address-aware"] then
1083 linkoptions
{ "/LARGEADDRESSAWARE" }
1087 project_add_manifest()
1089 elseif os
.istarget("linux") or os
.istarget("bsd") then
1091 if not _OPTIONS
["android"] and not (os
.getversion().description
== "OpenBSD") then
1095 if _OPTIONS
["android"] then
1096 -- NDK's STANDALONE-TOOLCHAIN.html says this is required
1097 linkoptions
{ "-Wl,--fix-cortex-a8" }
1102 if link_execinfo
then
1108 if os
.istarget("linux") or os
.getversion().description
== "GNU/kFreeBSD" then
1110 -- Dynamic libraries (needed for linking for gold)
1115 -- Threading support
1116 buildoptions
{ "-pthread" }
1117 if not _OPTIONS
["android"] then
1118 linkoptions
{ "-pthread" }
1121 -- For debug_resolve_symbol
1123 linkoptions
{ "-rdynamic" }
1126 elseif os
.istarget("macosx") then
1129 links
{ "ApplicationServices.framework", "Cocoa.framework", "CoreFoundation.framework" }
1131 architecture(macos_arch
)
1132 buildoptions
{ "-arch " .. macos_arch
}
1133 linkoptions
{ "-arch " .. macos_arch
}
1134 xcodebuildsettings
{ ARCHS
= macos_arch
}
1135 if _OPTIONS
["macosx-version-min"] then
1136 xcodebuildsettings
{ MACOSX_DEPLOYMENT_TARGET
= _OPTIONS
["macosx-version-min"] }
1142 --------------------------------------------------------------------------------
1144 --------------------------------------------------------------------------------
1146 -- setup a typical Atlas component project
1147 -- extra_params, rel_source_dirs and rel_include_dirs: as in project_add_contents;
1148 function setup_atlas_project(project_name
, target_type
, rel_source_dirs
, rel_include_dirs
, extern_libs
, extra_params
)
1150 local source_root
= rootdir
.."/source/tools/atlas/" .. project_name
.. "/"
1151 project_create(project_name
, target_type
)
1153 -- if not specified, the default for atlas pch files is in the project root.
1154 if not extra_params
["pch_dir"] then
1155 extra_params
["pch_dir"] = source_root
1158 project_add_contents(source_root
, rel_source_dirs
, rel_include_dirs
, extra_params
)
1159 project_add_extern_libs(extern_libs
, target_type
)
1161 -- Platform Specifics
1162 if os
.istarget("windows") then
1163 -- Link to required libraries
1164 links
{ "winmm", "delayimp" }
1166 elseif os
.istarget("macosx") then
1167 architecture(macos_arch
)
1168 buildoptions
{ "-arch " .. macos_arch
}
1169 linkoptions
{ "-arch " .. macos_arch
}
1170 xcodebuildsettings
{ ARCHS
= macos_arch
}
1171 if _OPTIONS
["macosx-version-min"] then
1172 xcodebuildsettings
{ MACOSX_DEPLOYMENT_TARGET
= _OPTIONS
["macosx-version-min"] }
1174 elseif os
.istarget("linux") or os
.istarget("bsd") then
1175 if os
.getversion().description
== "FreeBSD" then
1176 buildoptions
{ "-fPIC" }
1177 linkoptions
{ "-fPIC" }
1179 buildoptions
{ "-rdynamic", "-fPIC" }
1180 linkoptions
{ "-fPIC", "-rdynamic" }
1183 -- warnings triggered by wxWidgets
1184 buildoptions
{ "-Wno-unused-local-typedefs" }
1190 -- build all Atlas component projects
1191 function setup_atlas_projects()
1193 setup_atlas_project("AtlasObject", "StaticLib",
1196 "../../../third_party/jsonspirit"
1199 "../../../third_party/jsonspirit"
1210 "CustomControls/Buttons",
1211 "CustomControls/Canvas",
1212 "CustomControls/ColorDialog",
1213 "CustomControls/DraggableListCtrl",
1214 "CustomControls/EditableListCtrl",
1215 "CustomControls/FileHistory",
1216 "CustomControls/HighResTimer",
1217 "CustomControls/MapDialog",
1218 "CustomControls/MapResizeDialog",
1219 "CustomControls/SnapSplitterWindow",
1220 "CustomControls/VirtualDirTreeCtrl",
1221 "CustomControls/Windows",
1223 "General/VideoRecorder",
1226 "ScenarioEditor/Sections/Common",
1227 "ScenarioEditor/Sections/Cinema",
1228 "ScenarioEditor/Sections/Environment",
1229 "ScenarioEditor/Sections/Map",
1230 "ScenarioEditor/Sections/Object",
1231 "ScenarioEditor/Sections/Player",
1232 "ScenarioEditor/Sections/Terrain",
1233 "ScenarioEditor/Tools",
1234 "ScenarioEditor/Tools/Common",
1236 atlas_extra_links
= {
1240 atlas_extern_libs
= {
1245 "sdl", -- key definitions
1249 if not os
.istarget("windows") and not os
.istarget("macosx") then
1250 -- X11 should only be linked on *nix
1251 table.insert(atlas_extern_libs
, "x11")
1254 setup_atlas_project("AtlasUI", "SharedLib", atlas_src
,
1259 "../../../third_party/jsonspirit"
1263 pch_dir
= rootdir
.."/source/tools/atlas/AtlasUI/Misc/",
1265 extra_links
= atlas_extra_links
,
1266 extra_files
= { "Misc/atlas.rc" }
1271 -- Atlas 'frontend' tool-launching projects
1272 function setup_atlas_frontend_project (project_name
)
1274 local target_type
= get_main_project_target_type()
1275 project_create(project_name
, target_type
)
1277 local source_root
= rootdir
.."/source/tools/atlas/AtlasFrontends/"
1278 files
{ source_root
..project_name
..".cpp" }
1280 if os
.istarget("windows") then
1281 files
{ source_root
..project_name
..".rc" }
1284 includedirs
{ source_root
.. ".." }
1286 -- Platform Specifics
1287 if os
.istarget("windows") then
1289 project_add_manifest()
1291 else -- Non-Windows, = Unix
1292 links
{ "AtlasObject" }
1293 if os
.istarget("macosx") then
1294 architecture(macos_arch
)
1295 buildoptions
{ "-arch " .. macos_arch
}
1296 linkoptions
{ "-arch " .. macos_arch
}
1297 xcodebuildsettings
{ ARCHS
= macos_arch
}
1305 function setup_atlas_frontends()
1306 setup_atlas_frontend_project("ActorEditor")
1310 --------------------------------------------------------------------------------
1312 --------------------------------------------------------------------------------
1314 function setup_collada_project(project_name
, target_type
, rel_source_dirs
, rel_include_dirs
, extern_libs
, extra_params
)
1316 project_create(project_name
, target_type
)
1317 local source_root
= source_root
.."collada/"
1318 extra_params
["pch_dir"] = source_root
1319 project_add_contents(source_root
, rel_source_dirs
, rel_include_dirs
, extra_params
)
1320 project_add_extern_libs(extern_libs
, target_type
)
1322 -- Platform Specifics
1323 if os
.istarget("windows") then
1325 elseif os
.istarget("linux") then
1332 -- FCollada is not aliasing-safe, so disallow dangerous optimisations
1333 -- (TODO: It'd be nice to fix FCollada, but that looks hard)
1334 buildoptions
{ "-fno-strict-aliasing" }
1335 if os
.getversion().description
~= "FreeBSD" then
1336 buildoptions
{ "-rdynamic" }
1337 linkoptions
{ "-rdynamic" }
1340 elseif os
.istarget("bsd") then
1341 if os
.getversion().description
== "OpenBSD" then
1345 if os
.getversion().description
== "GNU/kFreeBSD" then
1351 buildoptions
{ "-fno-strict-aliasing" }
1353 buildoptions
{ "-rdynamic" }
1354 linkoptions
{ "-rdynamic" }
1356 elseif os
.istarget("macosx") then
1357 -- define MACOS-something?
1359 buildoptions
{ "-fno-strict-aliasing" }
1360 -- On OSX, fcollada uses a few utility functions from coreservices
1361 links
{ "CoreServices.framework" }
1363 architecture(macos_arch
)
1364 buildoptions
{ "-arch " .. macos_arch
}
1365 linkoptions
{ "-arch " .. macos_arch
}
1366 xcodebuildsettings
{ ARCHS
= macos_arch
}
1371 -- build all Collada component projects
1372 function setup_collada_projects()
1374 setup_collada_project("Collada", "SharedLib",
1388 --------------------------------------------------------------------------------
1390 --------------------------------------------------------------------------------
1392 function setup_tests()
1394 local cxxtest
= require
"cxxtest"
1396 if os
.istarget("windows") then
1397 cxxtest
.setpath(rootdir
.."/build/bin/cxxtestgen.exe")
1399 cxxtest
.setpath(rootdir
.."/libraries/source/cxxtest-4.4/bin/cxxtestgen")
1402 local runner
= "ErrorPrinter"
1403 if _OPTIONS
["jenkins-tests"] then
1404 runner
= "XmlPrinter"
1407 local includefiles
= {
1408 -- Precompiled headers - the header is added to all generated .cpp files
1409 -- note that the header isn't actually precompiled here, only #included
1410 -- so that the build stage can use it as a precompiled header.
1412 -- This is required to build against SDL 2.0.4 on Windows.
1413 "lib/external_libraries/libsdl.h",
1416 cxxtest
.init(source_root
, true, runner
, includefiles
)
1418 local target_type
= get_main_project_target_type()
1419 project_create("test", target_type
)
1421 -- Find header files in 'test' subdirectories
1422 local all_files
= os
.matchfiles(source_root
.. "**/tests/*.h")
1423 local test_files
= {}
1424 for i
,v
in pairs(all_files
) do
1425 -- Don't include sysdep tests on the wrong sys
1426 -- Don't include Atlas tests unless Atlas is being built
1427 if not (string.find(v
, "/sysdep/os/win/") and not os
.istarget("windows")) and
1428 not (string.find(v
, "/tools/atlas/") and not _OPTIONS
["atlas"]) and
1429 not (string.find(v
, "/sysdep/arch/x86_x64/") and ((arch
~= "amd64") or (arch
~= "x86")))
1431 table.insert(test_files
, v
)
1435 cxxtest
.configure_project(test_files
)
1437 filter
"system:not macosx"
1441 links
{ static_lib_names
}
1443 links
{ static_lib_names_debug
}
1445 links
{ static_lib_names_release
}
1448 links
{ "mocks_test" }
1449 if _OPTIONS
["atlas"] then
1450 links
{ "AtlasObject" }
1453 extra_files
= { "test_setup.cpp" },
1456 project_add_contents(source_root
, {}, {}, extra_params
)
1457 project_add_extern_libs(used_extern_libs
, target_type
)
1459 dependson
{ "Collada" }
1463 -- TODO: should fix the duplication between this OS-specific linking
1464 -- code, and the similar version in setup_main_exe
1466 if os
.istarget("windows") then
1467 -- from "lowlevel" static lib; must be added here to be linked in
1468 files
{ source_root
.."lib/sysdep/os/win/error_dialog.rc" }
1471 linkoptions
{ "/INCLUDE:_wstartup_InitAndRegisterShutdown" }
1472 -- Enables console for the TEST project on Windows
1473 linkoptions
{ "/SUBSYSTEM:CONSOLE" }
1475 project_add_manifest()
1477 elseif os
.istarget("linux") or os
.istarget("bsd") then
1479 if link_execinfo
then
1484 if not _OPTIONS
["android"] and not (os
.getversion().description
== "OpenBSD") then
1488 if _OPTIONS
["android"] then
1489 -- NDK's STANDALONE-TOOLCHAIN.html says this is required
1490 linkoptions
{ "-Wl,--fix-cortex-a8" }
1493 if os
.istarget("linux") or os
.getversion().description
== "GNU/kFreeBSD" then
1495 -- Dynamic libraries (needed for linking for gold)
1500 -- Threading support
1501 buildoptions
{ "-pthread" }
1502 if not _OPTIONS
["android"] then
1503 linkoptions
{ "-pthread" }
1506 -- For debug_resolve_symbol
1508 linkoptions
{ "-rdynamic" }
1511 includedirs
{ source_root
.. "pch/test/" }
1513 elseif os
.istarget("macosx") then
1514 architecture(macos_arch
)
1515 buildoptions
{ "-arch " .. macos_arch
}
1516 linkoptions
{ "-arch " .. macos_arch
}
1517 xcodebuildsettings
{ ARCHS
= macos_arch
}
1518 if _OPTIONS
["macosx-version-min"] then
1519 xcodebuildsettings
{ MACOSX_DEPLOYMENT_TARGET
= _OPTIONS
["macosx-version-min"] }
1524 -- must come first, so that VC sets it as the default project and therefore
1525 -- allows running via F5 without the "where is the EXE" dialog.
1530 -- add the static libs to the main EXE project. only now (after
1531 -- setup_all_libs has run) are the lib names known. cannot move
1532 -- setup_main_exe to run after setup_all_libs (see comment above).
1533 -- we also don't want to hardcode the names - that would require more
1534 -- work when changing the static lib breakdown.
1535 project("pyrogenesis") -- Set the main project active
1536 links
{ static_lib_names
}
1538 links
{ static_lib_names_debug
}
1540 links
{ static_lib_names_release
}
1543 if _OPTIONS
["atlas"] then
1544 setup_atlas_projects()
1545 setup_atlas_frontends()
1548 setup_collada_projects()
1550 if not _OPTIONS
["without-tests"] then