2023-01-12 20:49:14 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
# Compiling for Windows
|
2022-03-18 17:46:08 +01:00
|
|
|
=====================
|
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
This page describes how to compile Windows editor and export template binaries from source. If you're looking to
|
|
|
|
export your project to Windows instead, read `doc_exporting_for_windows`.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
## Requirements
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
For compiling under Windows, the following is required:
|
|
|
|
|
2023-01-12 20:57:31 +01:00
|
|
|
- `Visual Studio Community ( https://www.visualstudio.com/vs/community/ )`,
|
2022-03-18 17:46:08 +01:00
|
|
|
version 2017 or later. VS 2019 is recommended.
|
|
|
|
**Make sure to read "Installing Visual Studio caveats" below or you
|
|
|
|
will have to run/download the installer again.**
|
2023-01-12 20:39:50 +01:00
|
|
|
- `MinGW-w64 ( http://mingw-w64.org/ )` with GCC can be used as an alternative to
|
2023-01-12 19:43:03 +01:00
|
|
|
Visual Studio. Be sure to install/configure it to use the `posix` thread model.
|
2023-01-12 20:57:31 +01:00
|
|
|
- `Python 3.5+ ( https://www.python.org/downloads/windows/ )`.
|
2023-01-12 19:43:03 +01:00
|
|
|
**Make sure to enable the option to add Python to the `PATH` in the installer.**
|
2023-01-12 20:57:31 +01:00
|
|
|
- `SCons ( https://www.scons.org/ )` build system. Using the latest release is
|
2022-09-10 12:15:58 +02:00
|
|
|
recommended, especially for proper support of recent Visual Studio releases.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
### Note:
|
2023-01-12 20:57:31 +01:00
|
|
|
If you have `Scoop ( https://scoop.sh/ )` installed, you can easily
|
2023-01-12 22:00:14 +01:00
|
|
|
install MinGW and other dependencies using the following command:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
scoop install gcc python scons make
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
### Note:
|
2023-01-12 20:57:31 +01:00
|
|
|
If you have `MSYS2 ( https://www.msys2.org/ )` installed, you can easily
|
2023-01-12 22:00:14 +01:00
|
|
|
install MinGW and other dependencies using the following command:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
pacman -S mingw-w64-x86_64-python3-pip mingw-w64-x86_64-gcc \
|
|
|
|
mingw-w64-i686-python3-pip mingw-w64-i686-gcc make
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
For each MSYS2 MinGW subsystem, you should then run
|
|
|
|
`pip3 install scons` in its shell.
|
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
### See also:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
To get the Godot source code for compiling, see `doc_getting_source`.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
For a general overview of SCons usage for Godot, see `doc_introduction_to_the_buildsystem`.
|
|
|
|
|
|
|
|
## Setting up SCons
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
To install SCons, open the command prompt and run the following command:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
python -m pip install scons
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
If you are prompted with the message
|
2023-01-12 19:43:03 +01:00
|
|
|
`Defaulting to user installation because normal site-packages is not
|
|
|
|
writeable`, you may have to run that command again using elevated
|
2022-03-18 17:46:08 +01:00
|
|
|
permissions. Open a new command prompt as an Administrator then run the command
|
2023-01-12 19:43:03 +01:00
|
|
|
again to ensure that SCons is available from the `PATH`.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
To check whether you have installed Python and SCons correctly, you can
|
2023-01-12 19:43:03 +01:00
|
|
|
type `python --version` and `scons --version` into a command prompt
|
|
|
|
(`cmd.exe`).
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
If the commands above don't work, make sure to add Python to your `PATH`
|
2022-03-18 17:46:08 +01:00
|
|
|
environment variable after installing it, then check again.
|
|
|
|
You can do so by running the Python installer again and enabling the option
|
2023-01-12 19:43:03 +01:00
|
|
|
to add Python to the `PATH`.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2022-09-10 12:15:58 +02:00
|
|
|
If SCons cannot detect your Visual Studio installation, it might be that your
|
|
|
|
SCons version is too old. Update it to the latest version with
|
2023-01-12 19:43:03 +01:00
|
|
|
`python -m pip install --upgrade scons`.
|
2022-09-10 12:15:58 +02:00
|
|
|
|
2023-01-12 20:49:14 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
## Installing Visual Studio caveats
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
If installing Visual Studio 2017 or 2019, make sure to enable **C++** in
|
|
|
|
the list of workflows to install.
|
|
|
|
|
|
|
|
If installing Visual Studio 2015, make sure to run a **Custom**
|
|
|
|
installation instead of **Typical** and select **C++** as a language there.
|
|
|
|
|
|
|
|
If you've already made the mistake of installing Visual Studio without
|
|
|
|
C++ support, run the installer again; it should present you a **Modify** button.
|
|
|
|
Running the installer from *Add/Remove Programs* will only give you
|
|
|
|
a **Repair** option, which won't let you install C++ tools.
|
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
## Downloading Godot's source
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 19:29:11 +01:00
|
|
|
Refer to `doc_getting_source` for detailed instructions.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
The tutorial will assume from now on that you placed the source code in `C:\godot`.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
### Warning:
|
2023-01-12 20:55:57 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
To prevent slowdowns caused by continuous virus scanning during compilation, add the Godot source
|
|
|
|
folder to the list of exceptions in your antivirus software.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
For Windows Defender, hit the :kbd:`Windows` key, type "Windows Defender Settings" then hit :kbd:`Enter`.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
Under **Virus & threat protection**, go to **Virus & threat protection setting** and scroll
|
|
|
|
down to **Exclusions**. Click **Add or remove exclusions** then add the Godot source folder.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
## Compiling
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
### Selecting a compiler
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
SCons will automatically find and use an existing Visual Studio installation.
|
|
|
|
If you do not have Visual Studio installed, it will attempt to use
|
|
|
|
MinGW instead. If you already have Visual Studio installed and want to
|
2023-01-12 19:43:03 +01:00
|
|
|
use MinGW, pass `use_mingw=yes` to the SCons command line. Note that MSVC
|
2022-03-18 17:46:08 +01:00
|
|
|
builds cannot be performed from the MSYS2 or MinGW shells. Use either
|
2023-01-12 19:43:03 +01:00
|
|
|
`cmd.exe` or PowerShell instead.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
During development, using the Visual Studio compiler is usually a better idea,
|
|
|
|
as it links the Godot binary much faster than MinGW. However, MinGW can
|
|
|
|
produce more optimized binaries using link-time optimization (see below),
|
|
|
|
making it a better choice for production use.
|
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
### Running SCons
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
After opening a command prompt, change to the root directory of
|
2023-01-12 22:00:14 +01:00
|
|
|
the engine source code (using `cd`) and type:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
C:\godot> scons platform=windows
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
You can specify a number of CPU threads to use to speed up the build:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
C:\godot> scons -j6 platform=windows
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
In general, it is OK to have at least as many threads compiling Godot as you
|
2023-01-12 19:43:03 +01:00
|
|
|
have cores in your CPU, if not one or two more. Feel free to add the `-j`
|
2022-03-18 17:46:08 +01:00
|
|
|
option to any SCons command you see below.
|
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
Note: When compiling with multiple CPU threads, SCons may warn about pywin32 being missing. You can safely ignore this warning.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
If all goes well, the resulting binary executable will be placed in
|
2023-01-12 19:43:03 +01:00
|
|
|
`C:\godot\bin\` with the name `godot.windows.tools.32.exe` or
|
|
|
|
`godot.windows.tools.64.exe`. By default, SCons will build a binary matching
|
|
|
|
your CPU architecture, but this can be overridden using `bits=64` or
|
|
|
|
`bits=32`.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
This executable file contains the whole engine and runs without any
|
|
|
|
dependencies. Running it will bring up the Project Manager.
|
|
|
|
|
2023-01-12 20:55:57 +01:00
|
|
|
Note:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
If you are compiling Godot for production use, then you can make the final executable smaller and faster by adding the
|
|
|
|
SCons option `target=release_debug`.
|
|
|
|
|
|
|
|
If you are compiling Godot with MinGW, you can make the binary even smaller and faster by adding the SCons
|
|
|
|
option `use_lto=yes`. As link-time optimization is a memory-intensive process, this will require about
|
|
|
|
7 GB of available RAM while compiling.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 20:55:57 +01:00
|
|
|
Note:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
If you want to use separate editor settings for your own Godot builds and official releases, you can enable
|
|
|
|
`doc_data_paths_self_contained_mode` by creating a file called `._sc_` or `sc_` in the `bin/` folder.
|
|
|
|
|
|
|
|
## Development in Visual Studio
|
2022-09-10 12:15:58 +02:00
|
|
|
|
|
|
|
Using an IDE is not required to compile Godot, as SCons takes care of everything.
|
|
|
|
But if you intend to do engine development or debugging of the engine's C++ code,
|
|
|
|
you may be interested in configuring a code editor or an IDE.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2022-09-10 12:15:58 +02:00
|
|
|
Folder-based editors don't require any particular setup to start working with Godot's
|
|
|
|
codebase. To edit projects with Visual Studio they need to be set up as a solution.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
You can create a Visual Studio solution via SCons by running SCons with
|
2023-01-12 22:00:14 +01:00
|
|
|
the `vsproj=yes` parameter, like this:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
scons p=windows vsproj=yes
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
You will be able to open Godot's source in a Visual Studio solution now,
|
|
|
|
and able to build Godot using Visual Studio's **Build** button.
|
|
|
|
|
2023-01-12 20:55:57 +01:00
|
|
|
See also:
|
|
|
|
See `doc_configuring_an_ide_vs` for further details.
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
## Cross-compiling for Windows from other operating systems
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
If you are a Linux or macOS user, you need to install
|
2023-01-12 20:39:50 +01:00
|
|
|
`MinGW-w64 ( https://mingw-w64.org/doku.php )`, which typically comes in 32-bit
|
2022-03-18 17:46:08 +01:00
|
|
|
and 64-bit variants. The package names may differ based on your distribution,
|
|
|
|
here are some known ones:
|
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
**Arch Linux**
|
|
|
|
|
|
|
|
Install `mingw-w64-gcc` from the AUR: https://aur.archlinux.org/packages/mingw-w64-gcc/
|
|
|
|
|
|
|
|
**Debian** / **Ubuntu**
|
|
|
|
|
|
|
|
```
|
|
|
|
apt install mingw-w64
|
|
|
|
```
|
|
|
|
|
|
|
|
**Fedora**
|
|
|
|
|
|
|
|
```
|
|
|
|
dnf install mingw64-gcc-c++ mingw64-winpthreads-static mingw32-gcc-c++ mingw32-winpthreads-static
|
|
|
|
```
|
|
|
|
|
|
|
|
**macOS**
|
|
|
|
|
|
|
|
```
|
|
|
|
brew install mingw-w64
|
|
|
|
```
|
|
|
|
|
|
|
|
**Mageia**
|
|
|
|
|
|
|
|
```
|
|
|
|
urpmi mingw64-gcc-c++ mingw64-winpthreads-static mingw32-gcc-c++ mingw32-winpthreads-static
|
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
Before attempting the compilation, SCons will check for
|
2023-01-12 22:00:14 +01:00
|
|
|
the following binaries in your `PATH` environment variable:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
i686-w64-mingw32-gcc
|
|
|
|
x86_64-w64-mingw32-gcc
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 19:43:03 +01:00
|
|
|
If the binaries are not located in the `PATH` (e.g. `/usr/bin`),
|
2022-03-18 17:46:08 +01:00
|
|
|
you can define the following environment variables to give a hint to
|
2023-01-12 22:00:14 +01:00
|
|
|
the build system:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
export MINGW32_PREFIX="/path/to/i686-w64-mingw32-"
|
|
|
|
export MINGW64_PREFIX="/path/to/x86_64-w64-mingw32-"
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
To make sure you are doing things correctly, executing the following in
|
|
|
|
the shell should result in a working compiler (the version output may
|
2023-01-12 22:00:14 +01:00
|
|
|
differ based on your system):
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
${MINGW32_PREFIX}gcc --version
|
|
|
|
# i686-w64-mingw32-gcc (GCC) 6.1.0 20160427 (Mageia MinGW 6.1.0-1.mga6)
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
### Troubleshooting
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
Cross-compiling from some Ubuntu versions may lead to
|
2023-01-12 20:57:31 +01:00
|
|
|
`this bug ( https://github.com/godotengine/godot/issues/9258 )`,
|
2022-03-18 17:46:08 +01:00
|
|
|
due to a default configuration lacking support for POSIX threading.
|
|
|
|
|
|
|
|
You can change that configuration following those instructions,
|
2023-01-12 22:00:14 +01:00
|
|
|
for 64-bit:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
sudo update-alternatives --config x86_64-w64-mingw32-gcc
|
|
|
|
<choose x86_64-w64-mingw32-gcc-posix from the list>
|
|
|
|
sudo update-alternatives --config x86_64-w64-mingw32-g++
|
|
|
|
<choose x86_64-w64-mingw32-g++-posix from the list>
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
And for 32-bit:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
sudo update-alternatives --config i686-w64-mingw32-gcc
|
|
|
|
<choose i686-w64-mingw32-gcc-posix from the list>
|
|
|
|
sudo update-alternatives --config i686-w64-mingw32-g++
|
|
|
|
<choose i686-w64-mingw32-g++-posix from the list>
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-04-06 23:41:51 +02:00
|
|
|
### Creating Windows export templates
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
Windows export templates are created by compiling Godot without the editor,
|
2023-01-12 22:00:14 +01:00
|
|
|
with the following flags:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
C:\godot> scons platform=windows tools=no target=release_debug bits=32
|
|
|
|
C:\godot> scons platform=windows tools=no target=release bits=32
|
|
|
|
C:\godot> scons platform=windows tools=no target=release_debug bits=64
|
|
|
|
C:\godot> scons platform=windows tools=no target=release bits=64
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
If you plan on replacing the standard export templates, copy these to the
|
2023-01-12 20:47:54 +01:00
|
|
|
following location, replacing `( version )` with the version identifier
|
2023-01-12 22:00:14 +01:00
|
|
|
(such as `3.1.1.stable` or `3.2.dev`):
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
%USERPROFILE%\AppData\Roaming\Godot\templates\<version>\
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
With the following names:
|
2022-03-18 17:46:08 +01:00
|
|
|
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
windows_32_debug.exe
|
|
|
|
windows_32_release.exe
|
|
|
|
windows_64_debug.exe
|
|
|
|
windows_64_release.exe
|
2023-01-12 22:00:14 +01:00
|
|
|
```
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
However, if you are using custom modules or custom engine code, you
|
|
|
|
may instead want to configure your binaries as custom export templates
|
|
|
|
here:
|
|
|
|
|
2023-01-12 20:16:00 +01:00
|
|
|
![](img/wintemplates.png)
|
2022-03-18 17:46:08 +01:00
|
|
|
|
|
|
|
You don't need to copy them in this case, just reference the resulting
|
2023-01-12 19:43:03 +01:00
|
|
|
files in the `bin\` directory of your Godot source folder, so the next
|
2022-03-18 17:46:08 +01:00
|
|
|
time you build, you will automatically have the custom templates referenced.
|