compiling_for_windows.rst 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367
  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 C++, `Visual
  9. Studio Community <https://www.visualstudio.com/en-us/products/visual-studio-community-vs.aspx>`__
  10. (recommended), at least the 2013 version (12.0) up to 2015 (14.0).
  11. **If you're using Express, make sure you get/have a
  12. version that can compile for C++, Desktop**.
  13. - `Python 2.7+ <https://www.python.org/downloads/>`__ (3.0 is
  14. untested as of now). Using the 32-bits installer is recommended.
  15. - `Pywin32 Python Extension <http://sourceforge.net/projects/pywin32>`__
  16. for parallel builds (which increase the build speed by a great factor).
  17. - `SCons <http://www.scons.org>`__ build system.
  18. Setting up SCons
  19. ----------------
  20. Python adds the interpreter (python.exe) to the path. It usually
  21. installs in ``C:\Python`` (or ``C:\Python[Version]``). SCons installs
  22. inside the Python install and provides a batch file called "scons.bat".
  23. The location of this file can be added to the path or it can simply be
  24. copied to ``C:\Python`` together with the interpreter executable.
  25. To check whether you have installed Python and SCons correctly, you can
  26. type ``python --version`` and ``scons --version`` into the standard
  27. Windows Command Prompt (cmd.exe).
  28. Downloading Godot's source
  29. --------------------------
  30. `Godot's <https://github.com/godotengine/godot>`__ source is hosted on
  31. GitHub. Downloading it (cloning) via `Git <https://git-scm.com/>`__ is recommended.
  32. The tutorial will presume from now on that you placed the source into
  33. ``C:\godot``.
  34. Compiling
  35. ---------
  36. SCons will not be able out of the box to compile from the standard
  37. Windows "Command Prompt" (cmd.exe) because SCons and Visual C++ compiler
  38. will not be able to locate environment variables and executables they
  39. need for compilation.
  40. Therefore, you need to start a Visual Studio command prompt. It sets up
  41. environment variables needed by SCons to locate the compiler.
  42. It should be called similar to one of the bellow names (for your
  43. respective version of Visual Studio):
  44. * "Developer Command Prompt for VS2013"
  45. * "VS2013 x64 Native Tools Command Prompt"
  46. * "VS2013 x86 Native Tools Command Prompt"
  47. * "VS2013 x64 Cross Tools Command Prompt"
  48. * "VS2013 x86 Cross Tools Command Prompt"
  49. You should be able to find at least the Developer Command Prompt for
  50. your version of Visual Studio in your start menu.
  51. However Visual Studio sometimes seems to not install some of the above
  52. shortcuts, except the Developer Console at these locations that are
  53. automatically searched by the start menu search option:
  54. ::
  55. Win 7:
  56. C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2015\Visual Studio Tools
  57. C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2013\Visual Studio Tools
  58. If you found the Developer Console, it will do for now to create a 32
  59. bit version of Godot, but if you want the 64 bit version, you might need
  60. to setup the prompts manually for easy access.
  61. If you don't see some of the shortcuts, "How the prompts actually work"
  62. section bellow will explain how to setup these prompts if you need them.
  63. About the Developer/Tools Command Prompts and the Visual C++ compiler
  64. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  65. There is a few things you need to know about these consoles and the
  66. Visual C++ compiler.
  67. Your Visual Studio installation will ship with several Visual C++
  68. compilers, them being more or less identical, however each cl.exe
  69. (Visual C++ compiler) will compile Godot for a different architecture
  70. (32 or 64 bit, ARM compiler is not supported).
  71. The **Developer Command Prompt** will build a 32 bit version of Godot by
  72. using the 32 bit Visual C++ compiler.
  73. **Native Tools** Prompts (mentioned above) are used when you want the
  74. 32bit cl.exe to compile a 32 bit executable (x86 Native Tools
  75. Command Prompt). For the 64 bit cl.exe, it will compile a 64 bit
  76. executable (x64 Native Tools Command Prompt).
  77. The **Cross Tools** are used when your Windows is using one architecture
  78. (32 bit, for example) and you need to compile to a different
  79. architecture (64 bit). As you might be familiar, 32 bit Windows can not
  80. run 64 bit executables, but you still might need to compile for them.
  81. For example:
  82. * "VS2013 x64 Cross Tools Command Prompt" will use a 32 bit cl.exe that
  83. will compile a 64 bit application.
  84. * "VS2013 x86 Cross Tools Command Prompt" will use a 64 bit cl.exe that
  85. will compile a 32 bit application. This one is useful if you are
  86. running a 32 bit Windows.
  87. On a 64 bit Windows, you can run any of above prompts and compilers
  88. (cl.exe executables) because 64 bit windows can run any 32 bit
  89. application. 32 bit Windows can not run 64 bit executables, so the
  90. Visual Studio installer will not even install shortcuts for some of
  91. these prompts.
  92. Note that you need to choose the **Developer Console** or the correct
  93. **Tools Prompt** to build Godot for the correct architecture. Use only
  94. Native Prompts if you are not sure yet what exactly Cross Compile
  95. Prompts do.
  96. Running SCons
  97. ~~~~~~~~~~~~
  98. Once inside the **Developer Console/Tools Console Prompt**, go to the
  99. root directory of the engine source code and type:
  100. ::
  101. C:\godot> scons platform=windows
  102. Tip: if you installed "Pywin32 Python Extension" you can append the -j
  103. command to instruct SCons to run parallel builds like this:
  104. ::
  105. C:\godot> scons -j6 platform=windows
  106. In general, it is OK to have at least as many threads compiling Godot as
  107. you have cores in your CPU, if not one or two more, I use -j6
  108. (six threads) for my 4 core CPU, your mileage may vary. Feel free to add
  109. -j option to any SCons command you see bellow if you setup the
  110. "Pywin32 Python Extension".
  111. If all goes well, the resulting binary executable will be placed in
  112. ``C:\godot\bin\`` with the name of ``godot.windows.tools.32.exe`` or
  113. ``godot.windows.tools.64.exe``. SCons will automatically detect what
  114. compiler architecture the environment (the prompt) is setup for and will
  115. build a corresponding executable.
  116. This executable file contains the whole engine and runs without any
  117. dependencies. Executing it will bring up the project manager.
  118. How the prompts actually work
  119. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  120. The Visual Studio command prompts are just shortcuts that call the
  121. standard Command Prompt and have it run a batch file before giving you
  122. control. The batch file itself is called **vcvarsall.bat** and it sets up
  123. environment variables, including the PATH variable, so that the correct
  124. version of the compiler can be run.The Developer Command Prompt calls a
  125. different file called **VsDevCmd.bat** but none of the other tools that
  126. this batch file enables are needed by Godot/SCons.
  127. Since you are probably using VS2013 or VS2015, if you need to recreate
  128. them manually, use the bellow folders, or place
  129. them on the desktop/taskbar:
  130. ::
  131. C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2015\Visual Studio Tools
  132. C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Visual Studio 2013\Visual Studio Tools
  133. Start the creation of the shortcut by pressing the ``right mouse
  134. button/New/Shortcut`` in an empty place in your desired location.
  135. Then copy one of these commands bellow for the corresponding tool you
  136. need into the "Path" and "Name" sections of the shortcut creation
  137. wizard, and fix the path to the batch file if needed.
  138. * VS2013 is in the "Microsoft Visual Studio 12.0" folder.
  139. * VS2015 is in the "Microsoft Visual Studio 14.0" folder.
  140. * etc.
  141. ::
  142. Name: Developer Command Prompt for VS2013
  143. Path: %comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\Tools\VsDevCmd.bat""
  144. Name: VS2013 x64 Cross Tools Command Prompt
  145. Path: %comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"" x86_amd64
  146. Name: VS2013 x64 Native Tools Command Prompt
  147. Path: %comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"" amd64
  148. Name: VS2013 x86 Native Tools Command Prompt
  149. Path: %comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"" x86
  150. Name: VS2013 x86 Cross Tools Command Prompt
  151. Path: %comspec% /k ""C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat"" amd64_x86
  152. After you create the shortcut, in the shortcut's properties, that you
  153. can access by right clicking with your mouse on the shortcut itself, you
  154. can choose the starting directory of the command prompt ("Start in"
  155. field).
  156. Some of these shortcuts (namely the 64 bit compilers) seem to not be
  157. available in the Express edition of Visual Studio or Visual C++.
  158. In case you are wondering what these prompt shortcuts do, they call the
  159. standard cmd.exe with \\k option and have it run a batch file...
  160. ::
  161. %comspec% - path to cmd.exe
  162. \k - keep alive option of the command prompt
  163. remainder - command to run via cmd.exe
  164. cmd.exe \k(eep cmd.exe alive after commands behind this option run) ""runme.bat"" with_this_option
  165. How to run an automated build of Godot
  166. ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  167. If you need to just run the compilation process via a batch file or
  168. directly in the vanilla Windows Command Prompt you need to do the
  169. following command:
  170. ::
  171. "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86
  172. with one of the following parameters:
  173. * x86 (32 bit cl.exe to compile for the 32 bit architecture)
  174. * amd64 (64 bit cl.exe to compile for the 64 bit architecture)
  175. * x86_amd64 (32 bit cl.exe to compile for the 64 bit architecture)
  176. * amd64_x86 (64 bit cl.exe to compile for the 32 bit architecture)
  177. and after that one, you can run SCons:
  178. ::
  179. scons platform=windows
  180. or you can do them together:
  181. ::
  182. 32 bit Godot
  183. "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" x86 && scons platform=windows
  184. 64 bit Godot
  185. "C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC\vcvarsall.bat" amd64 && scons platform=windows
  186. Development in Visual Studio or other IDEs
  187. ------------------------------------------
  188. For most projects, using only scripting is enough but when development
  189. in C++ is needed, for creating modules or extending the engine, working
  190. with an IDE is usually desirable.
  191. You can create a Visual Studio solution via SCons by running SCons with
  192. the vsproj=yes parameter, like this:
  193. ::
  194. scons p=windows vsproj=yes
  195. You will be able to open Godot's source in a Visual Studio solution now
  196. but, currently, you can not build Godot via Visual Studio, as it does
  197. not work. It can be made to work manually if you are inclined to do so
  198. (.bat file called from NMake settings) but it is beyond the scope of
  199. this article.
  200. Cross-compiling for Windows from other operating systems
  201. ---------------
  202. If you are a Linux or Mac user, you need to install mingw32 and
  203. mingw-w64. Under Ubuntu or Debian, just run the following commands:
  204. ::
  205. apt-get install mingw32 mingw-w64
  206. If you are using another distro, SCons will check for the following
  207. binaries:
  208. ::
  209. i586-mingw32msvc-gcc
  210. i686-w64-mingw32-gcc
  211. If the binaries are named or located somewhere else, export the
  212. following env variables:
  213. ::
  214. export MINGW32_PREFIX="/path/to/i586-mingw32msvc-"
  215. export MINGW64_PREFIX="/path/to/i686-w64-mingw32-"
  216. To make sure you are doing things correctly, executing the following in
  217. the shell should result in a working compiler:
  218. ::
  219. user@host:~$ ${MINGW32_PREFIX}gcc
  220. gcc: fatal error: no input files
  221. Creating Windows export templates
  222. ---------------------------------
  223. Windows export templates are created by compiling Godot as release, with
  224. the following flags:
  225. - (using Mingw32 command prompt, using the bits parameter)
  226. ::
  227. C:\godot> scons platform=windows tools=no target=release bits=32
  228. C:\godot> scons platform=windows tools=no target=release_debug bits=32
  229. - (using Mingw-w64 command prompt, using the bits parameter)
  230. ::
  231. C:\godot> scons platform=windows tools=no target=release bits=64
  232. C:\godot> scons platform=windows tools=no target=release_debug bits=64
  233. - (using the Visual Studio command prompts for the correct
  234. architecture, notice the lack of bits parameter)
  235. ::
  236. C:\godot> scons platform=windows tools=no target=release
  237. C:\godot> scons platform=windows tools=no target=release_debug
  238. If you plan on replacing the standard templates, copy these to:
  239. ::
  240. C:\USERS\YOURUSER\AppData\Roaming\Godot\Templates
  241. With the following names:
  242. ::
  243. windows_32_debug.exe
  244. windows_32_release.exe
  245. windows_64_debug.exe
  246. windows_64_release.exe
  247. However, if you are writing your custom modules or custom C++ code, you
  248. might instead want to configure your binaries as custom export templates
  249. here:
  250. .. image:: /img/wintemplates.png
  251. You don't even need to copy them, you can just reference the resulting
  252. files in the ``bin\`` directory of your Godot source folder, so the next
  253. time you build you automatically have the custom templates referenced.