# Compiling on Windows using MSVC ## Requirements - [Visual Studio 2015 or newer](https://visualstudio.microsoft.com) including "Desktop development with C++" - [CMake](https://cmake.org/download/) - [vcpkg](https://github.com/Microsoft/vcpkg) (included with Visual Studio) - [Git](https://git-scm.com/downloads) ### Visual Studio with C++ 1. Install Visual Studio (VS) from [visualstudio.microsoft.com](https://visualstudio.microsoft.com) 1. In the VS installer, select "Desktop development with C++": ![VS installer showing desktop development with C++ selected](assets/vs-installer.png) 1. Confirm the installation. This will install the C++ compiler used in later steps. VS is also the recommended IDE for Luanti. You may notice that the C++ tools include CMake, but is should also be installed separately for compatibility with Luanti. ### CMake Install from [cmake.org/download](https://cmake.org/download/). Once installed, you should be able to run `cmake-gui` from the start menu: ![cmake-gui in Windows start menu shows app result](./assets/cmake-gui-search.png) ### Installing the dependencies 1. Start up the CMake GUI (Win > search "cmake-gui" > open) 2. Select **Browse Source...** and select `path/to/minetest` (where you've cloned the repo) 3. Select **Browse Build...** and select `path/to/minetest/build` (a new folder that CMake will prompt to create) 4. Select **Configure** 5. Choose the right Visual Studio version and target platform. Currently, Luanti uses Visual Studio 16 2019, but newer VS versions should work as well. The VS version has to match the version of the installed dependencies. 6. Choose **Specify toolchain file for cross-compiling** 7. Click **Next** 8. Select the vcpkg toolchain file e.g. `C:/vcpkg/scripts/buildsystems/vcpkg.cmake` 9. Click Finish 10. Wait until CMake generates the cache file (this may take about 10-30 minutes, depending on your device) 11. If there are any errors, solve them and hit **Configure** 12. Click **Generate** 13. Click **Open Project** ## Compile Luanti There are two ways to compile Luanti: via Visual Studio or via CLI. ### Compile in Visual Studio 14. Compile Luanti inside Visual Studio. - If you get "Unable to start program '...\x64\Debug\ALL_BUILD'. Access is denied", try compiling via the CLI instead. ### Compile via CLI While in the `path/to/minetest` folder, run the following script in PowerShell: ```powershell $vs="Visual Studio 17 2022" # or "Visual Studio 16 2019", etc., whatever matches your system $toolchain_file="C:/vcpkg/scripts/buildsystems/vcpkg.cmake" # ensure this path is correct cmake . -G $vs -DCMAKE_TOOLCHAIN_FILE=$toolchain_file -DCMAKE_BUILD_TYPE=Release -DENABLE_CURSES=OFF cmake --build . --config Release ``` ## Windows Installer using WiX Toolset Requirements: - [Visual Studio 2017](https://visualstudio.microsoft.com/) - [WiX Toolset](https://wixtoolset.org/) In the Visual Studio 2017 Installer select **Optional Features -> WiX Toolset**. Build the binaries as described above, but make sure you unselect `RUN_IN_PLACE`. Open the generated project file with Visual Studio. Right-click **Package** and choose **Generate**. It may take some minutes to generate the installer.