This repository serves as a starting point for those who want to use SFML for a project with Visual Studio Code.
To use this boilerplate, ensure the following are installed on your machine:
- Visual Studio Code with the CMake extension installed.
- MinGW, compatible with the specific SFML library you plan to use (e.g., WinLibs MSVCRT 13.1.0 (64-bit) for SFML 2.6.1 64-bit).
You can make MinGW available in Visual Studio Code by adding an entry to the cmake-tools-kits.json
file. Follow these steps:
Press Ctrl + Shift + P
to open the Command Palette.
Type in: CMake: Edit User-Local CMake Kits
Add the following entry to the cmake-tools-kits.json
file:
(Note: Replace the paths with the actual paths on your machine for gcc.exe
, g++.exe
, and mingw/bin
)
{
"name": "MinGW Custom",
"compilers": {
"C": "C:/tools/mingw/bin/gcc.exe",
"CXX": "C:/tools/mingw/bin/g++.exe"
},
"environmentVariables": {
"PATH": "C:/tools/mingw/bin"
},
"preferredGenerator": {
"name": "MinGW Makefiles"
}
}
- Download the SFML library and place it in the
src
directory. (Folder Name SFML-2.6.1) - Add the main.cpp file from this repo for a smoke test
- Open your project folder with Visual Studio Code
- Press
Ctrl + Shift + P
to open the Command Palette and typeCMake: Quick Start
. - Enter a project name.
- Select
C++ Project Create C++Project
- Select
Executable Create Executable
- Skip CPAck and CTest by just klicking ok without selecting anything
- Press esc to skip the generation of a preset
- Close and start Visual Studio Code
- Press
Ctrl + Shift + P
to open the Command Palette and typeCMake: Quick Start
. - Select the kit
MinGW-for-SFML
.
Finally, edit the CMakeLists.txt file as described in the project files to configure the project properly.