| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496 | .. _doc_introduction_to_the_buildsystem:Introduction to the buildsystem===============================.. highlight:: shellGodot is a primarily C++ project and it :ref:`uses the SCons build system. <doc_faq_why_scons>`We love SCons for how maintainable and easy to set up it makes our buildsystem. And thanks tothat compiling Godot from source can be as simple as running:::    sconsThis produces an editor build for your current platform, operating system, and architecture.You can change what gets built by specifying a target, a platform, and/or an architecture.For example, to build an export template used for running exported games, you can run:::    scons target=template_releaseIf you plan to debug or develop the engine, then you might want to enable the ``dev_build``option to enable dev-only debugging code:::    scons dev_build=yesFollowing sections in the article will explain these and other universal options in more detail. Butbefore you can compile Godot, you need to install a few prerequisites. Please refer to the platformdocumentation to learn more:- :ref:`doc_compiling_for_android`- :ref:`doc_compiling_for_ios`- :ref:`doc_compiling_for_linuxbsd`- :ref:`doc_compiling_for_macos`- :ref:`doc_compiling_for_web`- :ref:`doc_compiling_for_windows`These articles cover in great detail both how to setup your environment to compile Godot on a specificplatform, and how to compile for that platform. Please feel free to go back and forth between them andthis article to reference platform-specific and universal configuration options.Using multi-threading---------------------The build process may take a while, depending on how powerful your system is. By default, Godot'sSCons setup is configured to use all CPU threads but one (to keep the system responsive duringcompilation). If the system has 4 CPU threads or fewer, it will use all threads by default.If you want to adjust how many CPU threads SCons will use, use the ``-j<threads>``parameter to specify how many threads will be used for the build.Example for using 12 threads:::    scons -j12Platform selection------------------Godot's build system will begin by detecting the platforms it can buildfor. If not detected, the platform will simply not appear on the list ofavailable platforms. The build requirements for each platform aredescribed in the rest of this tutorial section.SCons is invoked by just calling ``scons``. If no platform is specified,SCons will detect the target platform automatically based on the host platform.It will then start building for the target platform right away.To list the available target platforms, use ``scons platform=list``:.. code:: text    scons platform=list    scons: Reading SConscript files ...    The following platforms are available:        android        ios        linuxbsd        macos        web        windows    Please run SCons again and select a valid platform: platform=<string>To build for a platform (for example, ``linuxbsd``), run with the ``platform=``(or ``p=`` to make it short) argument:::    scons platform=linuxbsd.. _doc_introduction_to_the_buildsystem_resulting_binary:Resulting binary----------------The resulting binaries will be placed in the ``bin/`` subdirectory,generally with this naming convention:::    godot.<platform>.<target>[.dev][.double].<arch>[.<extra_suffix>][.<ext>]For the previous build attempt, the result would look like this:.. code-block:: console    ls bin    bin/godot.linuxbsd.editor.x86_64This means that the binary is for Linux *or* \*BSD (*not* both), is not optimized, has thewhole editor compiled in, and is meant for 64 bits.A Windows binary with the same configuration will look like this:.. code-block:: doscon    C:\godot> dir bin/    godot.windows.editor.64.exeCopy that binary to any location you like, as it contains the Project Manager,editor and all means to execute the game. However, it lacks the data to exportit to the different platforms. For that the export templates are needed (whichcan be either downloaded from `godotengine.org <https://godotengine.org/>`__, oryou can build them yourself).Aside from that, there are a few standard options that can be set in allbuild targets, and which will be explained below... _doc_introduction_to_the_buildsystem_target:Target------The ``target`` option controls if the editor is compiled and debug flags are used.Optimization levels (``optimize``) and whether each build contains debug symbols(``debug_symbols``) is controlled separately from the target. Each mode means:-  ``target=editor``: Build an editor binary (defines ``TOOLS_ENABLED`` and ``DEBUG_ENABLED``)-  ``target=template_debug``: Build a debug export template (defines ``DEBUG_ENABLED``)-  ``target=template_release``: Build a release export templateThe editor is enabled by default in all PC targets (Linux, Windows, macOS),disabled for everything else. Disabling the editor produces a binary that canrun projects but does not include the editor or the Project Manager.The list of :ref:`command line arguments <doc_command_line_tutorial>`available varies depending on the build type.::    scons platform=<platform> target=editor|template_debug|template_release.. _doc_introduction_to_the_buildsystem_development_and_production_aliases:Development and production aliases----------------------------------When creating builds for development (running debugging/:ref:`profiling <doc_using_cpp_profilers>`tools), you often have different goals compared to production builds(making binaries as fast and small as possible).Godot provides two aliases for this purpose:- ``dev_mode=yes`` is an alias for ``verbose=yes warnings=extra werror=yes  tests=yes``. This enables warnings-as-errors behavior (similar to Godot's  continuous integration setup) and also builds :ref:`unit tests  <doc_unit_testing>` so you can run them locally.- ``production=yes`` is an alias for ``use_static_cpp=yes debug_symbols=no  lto=auto``. Statically linking libstdc++ allows for better binary portability  when compiling for Linux. This alias also enables link-time optimization when  compiling for Linux, Web and Windows with MinGW, but keeps LTO disabled when  compiling for macOS, iOS or Windows with MSVC. This is because LTO on those  platforms is very slow to link or has issues with the generated code.You can manually override options from those aliases by specifying them on thesame command line with different values. For example, you can use ``sconsproduction=yes debug_symbols=yes`` to create production-optimized binaries withdebugging symbols included.Dev build---------.. note::    ``dev_build`` should **not** be confused with ``dev_mode``, which is an    alias for several development-related options (see above).When doing engine development the ``dev_build`` option can be used togetherwith ``target`` to enable dev-specific code. ``dev_build`` defines ``DEV_ENABLED``,disables optimization (``-O0``/``/0d``), enables generating debug symbols, anddoes not define ``NDEBUG`` (so ``assert()`` works in thirdparty libraries).::    scons platform=<platform> dev_build=yesThis flag appends the ``.dev`` suffix (for development) to the generatedbinary name... seealso::    There are additional SCons options to enable *sanitizers*, which are tools    you can enable at compile-time to better debug certain engine issues.    See :ref:`doc_using_sanitizers` for more information... _doc_introduction_to_the_buildsystem_debugging_symbols:Debugging symbols-----------------By default, ``debug_symbols=no`` is used, which means **no** debugging symbolsare included in compiled binaries. Use ``debug_symbols=yes`` to include debugsymbols within compiled binaries, which allows debuggers and profilers to workcorrectly. Debugging symbols are also required for Godot's crash stacktraces todisplay with references to source code files and lines.The downside is that debugging symbols are large files (significantly largerthan the binaries themselves). As a result, official binaries currently do notinclude debugging symbols. This means you need to compile Godot yourself to haveaccess to debugging symbols.When using ``debug_symbols=yes``, you can also use``separate_debug_symbols=yes`` to put debug information in a separate file witha ``.debug`` suffix. This allows distributing both files independently. Notethat on Windows, when compiling with MSVC, debugging information is *always*written to a separate ``.pdb`` file regardless of ``separate_debug_symbols``... tip::    Use the ``strip <path/to/binary>`` command to remove debugging symbols from    a binary you've already compiled.Optimization level------------------Several compiler optimization levels can be chosen from:- ``optimize=speed_trace`` *(default when targeting non-Web platforms)*: Favors  execution speed at the cost of larger binary size. Optimizations may sometimes  negatively impact debugger usage (stack traces may be less accurate. If this  occurs to you, use ``optimize=debug`` instead.- ``optimize=speed``: Favors even more execution speed, at the cost of even  larger binary size compared to ``optimize=speed_trace``. Even less friendly to  debugging compared to ``optimize=debug``, as this uses the most aggressive  optimizations available.- ``optimize=size`` *(default when targeting the Web platform)*: Favors small  binaries at the cost of slower execution speed.- ``optimize=size_extra``: Favors even smaller binaries, at the cost of even  slower execution speed compared to ``optimize=size``.- ``optimize=debug``: Only enables optimizations that do not impact debugging in  any way. This results in faster binaries than ``optimize=none``, but slower  binaries than ``optimize=speed_trace``.- ``optimize=none``: Do not perform any optimization. This provides the fastest  build times, but the slowest execution times.- ``optimize=custom`` *(advanced users only)*: Do not pass optimization  arguments to the C/C++ compilers. You will have to pass arguments manually  using the ``cflags``, ``ccflags`` and ``cxxflags`` SCons options.Architecture------------The ``arch`` option is meant to control the CPU or OS version intended to run thebinaries. It is focused mostly on desktop platforms and ignored everywhereelse.Supported values for the ``arch`` option are **auto**, **x86_32**, **x86_64**,**arm32**, **arm64**, **rv64**, **ppc32**, **ppc64** and **wasm32**.::    scons platform=<platform> arch={auto|x86_32|x86_64|arm32|arm64|rv64|ppc32|ppc64|wasm32}This flag appends the value of ``arch`` to resulting binaries whenrelevant.  The default value ``arch=auto`` detects the architecturethat matches the host platform... _doc_buildsystem_custom_modules:Custom modules--------------It's possible to compile modules residing outside of Godot's directorytree, along with the built-in modules.A ``custom_modules`` build option can be passed to the command line beforecompiling. The option represents a comma-separated list of directory pathscontaining a collection of independent C++ modules that can be seen as C++packages, just like the built-in ``modules/`` directory.For instance, it's possible to provide both relative, absolute, and userdirectory paths containing such modules:::    scons custom_modules="../modules,/abs/path/to/modules,~/src/godot_modules".. note::    If there's any custom module with the exact directory name as a built-in    module, the engine will only compile the custom one. This logic can be used    to override built-in module implementations... seealso::    :ref:`doc_custom_modules_in_cpp`Cleaning generated files------------------------Sometimes, you may encounter an error due to generated files being present. Youcan remove them by using ``scons --clean <options>``, where ``<options>`` is thelist of build options you've used to build Godot previously.Alternatively, you can use ``git clean -fixd`` which will clean build artifactsfor all platforms and configurations. Beware, as this will remove all untrackedand ignored files in the repository. Don't run this command if you haveuncommitted work!Other build options-------------------There are several other build options that you can use to configure theway Godot should be built (compiler, debug options, etc.) as well as thefeatures to include/disable.Check the output of ``scons --help`` for details about each option forthe version you are willing to compile... _doc_overriding_build_options:Overriding the build options~~~~~~~~~~~~~~~~~~~~~~~~~~~~Using a file^^^^^^^^^^^^The default ``custom.py`` file can be created at the root of the Godot Enginesource to initialize any SCons build options passed via the command line:.. code-block:: python    :caption: custom.py    optimize = "size"    module_mono_enabled = "yes"    use_llvm = "yes"    extra_suffix = "game_title"You can also disable some of the built-in modules before compiling, saving sometime it takes to build the engine. See :ref:`doc_optimizing_for_size` page for more details... seealso::    You can use the online    `Godot build options generator <https://godot-build-options-generator.github.io/>`__    to generate a ``custom.py`` file containing SCons options.    You can then save this file and place it at the root of your Godot source directory.Another custom file can be specified explicitly with the ``profile`` commandline option, both overriding the default build configuration:.. code-block:: shell    scons profile=path/to/custom.py.. note:: Build options set from the file can be overridden by the command line          options.It's also possible to override the options conditionally:.. code-block:: python    :caption: custom.py    import version    # Override options specific for Godot 3.x and 4.x versions.    if version.major == 3:        pass    elif version.major == 4:        passUsing the SCONSFLAGS^^^^^^^^^^^^^^^^^^^^``SCONSFLAGS`` is an environment variable which is used by the SCons to set theoptions automatically without having to supply them via the command line.For instance, you may want to force a number of CPU threads with theaforementioned ``-j`` option for all future builds:.. tabs:: .. code-tab:: bash Linux/macOS     export SCONSFLAGS="-j4" .. code-tab:: bat Windows (cmd)     set SCONSFLAGS=-j4 .. code-tab:: powershell Windows (PowerShell)     $env:SCONSFLAGS="-j4"SCU (single compilation unit) build^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^Regular builds tend to be bottlenecked by including large numbers of headersin each compilation translation unit. Primarily to speed up development (ratherthan for production builds), Godot offers a "single compilation unit" build(aka "Unity / Jumbo" build).For the folders accelerated by this option, multiple ``.cpp`` files arecompiled in each translation unit, so headers can be shared between multiplefiles, which can dramatically decrease build times.To perform an SCU build, use the ``scu_build=yes`` SCons option... note:: When developing a Pull Request using SCU builds, be sure to make a          regular build prior to submitting the PR. This is because SCU builds          by nature include headers from earlier ``.cpp`` files in the          translation unit, therefore won't catch all the includes you will          need in a regular build. The CI will catch these errors, but it will          usually be faster to catch them on a local build on your machine.Export templates----------------Official export templates are downloaded from the Godot Engine site:`godotengine.org <https://godotengine.org/>`__. However, you might wantto build them yourself (in case you want newer ones, you are using custommodules, or simply don't trust your own shadow).If you download the official export templates package and unzip it, youwill notice that most files are optimized binaries or packages for eachplatform:.. code-block:: none    android_debug.apk    android_release.apk    android_source.zip    ios.zip    linux_debug.arm32    linux_debug.arm64    linux_debug.x86_32    linux_debug.x86_64    linux_release.arm32    linux_release.arm64    linux_release.x86_32    linux_release.x86_64    macos.zip    version.txt    web_debug.zip    web_dlink_debug.zip    web_dlink_nothreads_debug.zip    web_dlink_nothreads_release.zip    web_dlink_release.zip    web_nothreads_debug.zip    web_nothreads_release.zip    web_release.zip    windows_debug_x86_32_console.exe    windows_debug_x86_32.exe    windows_debug_x86_64_console.exe    windows_debug_x86_64.exe    windows_debug_arm64_console.exe    windows_debug_arm64.exe    windows_release_x86_32_console.exe    windows_release_x86_32.exe    windows_release_x86_64_console.exe    windows_release_x86_64.exe    windows_release_arm64_console.exe    windows_release_arm64.exeTo create those yourself, follow the instructions detailed for eachplatform in this same tutorial section. Each platform explains how tocreate its own template.The ``version.txt`` file should contain the corresponding Godot versionidentifier. This file is used to install export templates in a version-specificdirectory to avoid conflicts. For instance, if you are building export templatesfor Godot 3.1.1, ``version.txt`` should contain ``3.1.1.stable`` on the firstline (and nothing else). This version identifier is based on the ``major``,``minor``, ``patch`` (if present) and ``status`` lines of the`version.py file in the Godot Git repository <https://github.com/godotengine/godot/blob/master/version.py>`__.If you are developing for multiple platforms, macOS is definitely the mostconvenient host platform for cross-compilation, since you can cross-compile forevery target. Linux and Windows come in second place,but Linux has the advantage of being the easier platform to set this up.
 |