compiling_for_windows.rst 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  1. .. _doc_compiling_for_windows:
  2. Compiling for Windows
  3. =====================
  4. .. highlight:: shell
  5. Requirements
  6. ------------
  7. For compiling under Windows, the following is required:
  8. - `Visual Studio Community <https://www.visualstudio.com/vs/community/>`_,
  9. version 2015 (14.0) or later.
  10. **Make sure to read "Installing Visual Studio caveats" below or you
  11. will have to run/download the installer again.**
  12. - MinGW-w64 can be used as an alternative to Visual Studio.
  13. - `Python 3.5+ (recommended) or Python 2.7+. <https://www.python.org/downloads/windows/>`_
  14. - `SCons <https://www.scons.org>`_ build system.
  15. - *Optional* - `yasm <https://yasm.tortall.net/>`_ (for WebM SIMD optimizations)
  16. .. note:: If you have `Scoop <https://scoop.sh/>`_ installed, you can easily
  17. install MinGW and other dependencies using the following command::
  18. scoop install gcc python scons
  19. .. seealso:: For a general overview of SCons usage for Godot, see
  20. :ref:`doc_introduction_to_the_buildsystem`.
  21. Setting up SCons
  22. ----------------
  23. First, make sure to enable the option to add Python to the ``PATH`` in
  24. the Python installer. The SCons installer should then detect and use
  25. the existing Python installation.
  26. To check whether you have installed Python and SCons correctly, you can
  27. type ``python --version`` and ``scons --version`` into a command prompt
  28. (``cmd.exe``).
  29. If the commands above don't work, make sure to add Python to your ``PATH``
  30. environment variable after installing it, then check again.
  31. You can do so by running the Python installer again and enabling the option
  32. to add Python to the ``PATH``.
  33. .. _doc_compiling_for_windows_install_vs:
  34. Installing Visual Studio caveats
  35. --------------------------------
  36. If installing Visual Studio 2017 or 2019, make sure to enable **C++** in
  37. the list of workflows to install.
  38. If installing Visual Studio 2015, make sure to run a **Custom**
  39. installation instead of **Typical** and select **C++** as a language there.
  40. If you've already made the mistake of installing Visual Studio without
  41. C++ support, run the installer again; it should present you a **Modify** button.
  42. Running the installer from *Add/Remove Programs* will only give you
  43. a **Repair** option, which won't let you install C++ tools.
  44. Downloading Godot's source
  45. --------------------------
  46. Godot's source code is `hosted on GitHub <https://github.com/godotengine/godot>`_.
  47. Downloading it (cloning) using `Git <https://git-scm.com/>`_ is recommended.
  48. The tutorial will assume from now on that you placed the source code in
  49. ``C:\godot``.
  50. Compiling
  51. ---------
  52. Selecting a compiler
  53. ~~~~~~~~~~~~~~~~~~~~
  54. SCons will automatically find and use an existing Visual Studio installation.
  55. If you do not have Visual Studio installed, it will attempt to use
  56. MinGW instead. If you already have Visual Studio installed and want to
  57. use MinGW, pass ``use_mingw=yes`` to the SCons command line.
  58. During development, using the Visual Studio compiler is usually a better idea,
  59. as it links the Godot binary much faster than MinGW. However, MinGW can
  60. produce more optimized binaries using link-time optimization (see below),
  61. making it a better choice for production use.
  62. Running SCons
  63. ~~~~~~~~~~~~~
  64. After opening a command prompt, change to the root directory of
  65. the engine source code (using ``cd``) and type::
  66. C:\godot> scons platform=windows
  67. You can specify a number of CPU threads to use to speed up the build::
  68. C:\godot> scons -j6 platform=windows
  69. In general, it is OK to have at least as many threads compiling Godot as
  70. you have cores in your CPU, if not one or two more. Feel free to add the
  71. -j option to any SCons command you see below.
  72. .. note:: When compiling with multiple CPU threads, SCons may warn about
  73. pywin32 being missing. You can safely ignore this warning.
  74. If all goes well, the resulting binary executable will be placed in
  75. ``C:\godot\bin\`` with the name ``godot.windows.tools.32.exe`` or
  76. ``godot.windows.tools.64.exe``.
  77. .. note:: By default, SCons will build a binary matching your CPU architecture,
  78. but this can be overriden using ``bits=64`` or ``bits=32``.
  79. This executable file contains the whole engine and runs without any
  80. dependencies. Running it will bring up the Project Manager.
  81. .. note:: If you are compiling Godot for production use, then you can
  82. make the final executable smaller and faster by adding the
  83. SCons option ``target=release_debug``.
  84. If you are compiling Godot with MinGW, you can make the binary
  85. even smaller and faster by adding the SCons option ``use_lto=yes``.
  86. As link-time optimization is a memory-intensive process,
  87. this will require about 3 GB of available RAM while compiling.
  88. Development in Visual Studio or other IDEs
  89. ------------------------------------------
  90. For most projects, using only scripting is enough but when development
  91. in C++ is needed, for creating modules or extending the engine, working
  92. with an IDE is usually desirable.
  93. You can create a Visual Studio solution via SCons by running SCons with
  94. the ``vsproj=yes`` parameter, like this::
  95. scons p=windows vsproj=yes
  96. You will be able to open Godot's source in a Visual Studio solution now,
  97. and able to build Godot using Visual Studio's **Build** button.
  98. If you need to edit the build commands, they are located in
  99. "Godot" project settings, NMAKE sheet. SCons is called at the end of
  100. the commands. If you make a mistake, copy the command from one of the
  101. other build configurations (debug, release_debug, release) or
  102. architectures (Win32/x64); they are equivalent.
  103. Cross-compiling for Windows from other operating systems
  104. --------------------------------------------------------
  105. If you are a Linux or macOS user, you need to install
  106. `MinGW-w64 <https://mingw-w64.org/doku.php>`_, which typically comes in 32-bit
  107. and 64-bit variants. The package names may differ based on your distribution,
  108. here are some known ones:
  109. +----------------+--------------------------------------------------------------+
  110. | **Arch Linux** | Install `mingw-w64-gcc from the AUR`_. |
  111. +----------------+--------------------------------------------------------------+
  112. | **Debian** / | :: |
  113. | **Ubuntu** | |
  114. | | apt install mingw-w64 |
  115. +----------------+--------------------------------------------------------------+
  116. | **Fedora** | :: |
  117. | | |
  118. | | dnf install mingw64-gcc-c++ mingw64-winpthreads-static \ |
  119. | | mingw32-gcc-c++ mingw32-winpthreads-static |
  120. +----------------+--------------------------------------------------------------+
  121. | **macOS** | :: |
  122. | | |
  123. | | brew install mingw-w64 |
  124. +----------------+--------------------------------------------------------------+
  125. | **Mageia** | :: |
  126. | | |
  127. | | urpmi mingw64-gcc-c++ mingw64-winpthreads-static \ |
  128. | | mingw32-gcc-c++ mingw32-winpthreads-static |
  129. +----------------+--------------------------------------------------------------+
  130. .. _mingw-w64-gcc from the AUR: https://aur.archlinux.org/packages/mingw-w64-gcc/
  131. Before attempting the compilation, SCons will check for
  132. the following binaries in your ``PATH`` environment variable::
  133. i686-w64-mingw32-gcc
  134. x86_64-w64-mingw32-gcc
  135. If the binaries are not located in the ``PATH`` (e.g. ``/usr/bin``),
  136. you can define the following environment variables to give a hint to
  137. the build system::
  138. export MINGW32_PREFIX="/path/to/i686-w64-mingw32-"
  139. export MINGW64_PREFIX="/path/to/x86_64-w64-mingw32-"
  140. To make sure you are doing things correctly, executing the following in
  141. the shell should result in a working compiler (the version output may
  142. differ based on your system)::
  143. user@host:~$ ${MINGW32_PREFIX}gcc --version
  144. i686-w64-mingw32-gcc (GCC) 6.1.0 20160427 (Mageia MinGW 6.1.0-1.mga6)
  145. Troubleshooting
  146. ~~~~~~~~~~~~~~~
  147. Cross-compiling from some Ubuntu versions may lead to
  148. `this bug <https://github.com/godotengine/godot/issues/9258>`_,
  149. due to a default configuration lacking support for POSIX threading.
  150. You can change that configuration following those instructions,
  151. for 64-bit::
  152. sudo update-alternatives --config x86_64-w64-mingw32-gcc
  153. <choose x86_64-w64-mingw32-gcc-posix from the list>
  154. sudo update-alternatives --config x86_64-w64-mingw32-g++
  155. <choose x86_64-w64-mingw32-g++-posix from the list>
  156. And for 32-bit::
  157. sudo update-alternatives --config i686-w64-mingw32-gcc
  158. <choose i686-w64-mingw32-gcc-posix from the list>
  159. sudo update-alternatives --config i686-w64-mingw32-g++
  160. <choose i686-w64-mingw32-g++-posix from the list>
  161. Creating Windows export templates
  162. ---------------------------------
  163. Windows export templates are created by compiling Godot without the editor,
  164. with the following flags::
  165. C:\godot> scons platform=windows tools=no target=release_debug bits=32
  166. C:\godot> scons platform=windows tools=no target=release bits=32
  167. C:\godot> scons platform=windows tools=no target=release_debug bits=64
  168. C:\godot> scons platform=windows tools=no target=release bits=64
  169. If you plan on replacing the standard export templates, copy these to the
  170. following location, replacing ``<version>`` with the version identifier
  171. (such as ``3.1.1.stable`` or ``3.2.dev``)::
  172. %USERPROFILE%\AppData\Roaming\Godot\templates\<version>\
  173. With the following names::
  174. windows_32_debug.exe
  175. windows_32_release.exe
  176. windows_64_debug.exe
  177. windows_64_release.exe
  178. However, if you are using custom modules or custom engine code, you
  179. may instead want to configure your binaries as custom export templates
  180. here:
  181. .. image:: img/wintemplates.png
  182. You don't need to copy them in this case, just reference the resulting
  183. files in the ``bin\`` directory of your Godot source folder, so the next
  184. time you build, you will automatically have the custom templates referenced.