SDL Setup is a basic C++ template project to get started with SDL, using CMake and the Clion IDE.
cmake # install however your platform wants you to
g++/clang++/msvc # toolchain will be explained
sdl2 # library will be explained
Getting started on Windows takes a bit of effort. First off, you will need a proper compiler. The easiest way to get started, is using Visual Studio (MSVC). Run the VS2017 installer, and install the C++ environment.
The preferred way to get SDL installed is using a package manager. Microsoft has recently released vcpkg, which we will be using for these instructions. Other options could be Conan, or Hunter.
- Install vcpkg in whatever dir you want, recommended in C:\. PowerShell:
PS> git clone https://github.com/Microsoft/vcpkg.git
PS> cd vcpkg
PS> .\bootstrap-vcpkg.bat
- Hook up integration
PS> .\vcpkg integrate install
- Install SDL
PS> .\vcpkg install sdl2
Download Clion from their website. If you have not already, get a free student license.
Follow the initial setup. When you have to pick a toolchain, follow these steps:
- Under Environment, pick 'Visual Studio'.
- Under Architecture, pick 'x86'.
- Go to Settings (File -> Settings, or Ctrl+Alt+S). Uncollapse Build, Execution, Deployment. Pick CMake.
In the CMake options, fill in
-DCMAKE_TOOLCHAIN_FILE={ VPCKG DIR }/scripts/buildsystems/vcpkg.cmake
, or-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake
if you followed the default instructions for vcpkg.
Building on Linux is much easier. For this setup, we will be using Ubuntu 18.04/Debian. Install either g++ or clang++ using apt.
sudo apt-get install clang++ g++
Linux does not need a package manager, besides its own. On Ubuntu:
sudo apt-get install libsdl2-dev
Clion is optional, use whatever CMake-compatible IDE, or your favorite text editor if you want to. Building can be done in the terminal.
Clion can be installed using the default settings.
Building on Mac is nearly the same as Linux. MacOS comes with Clang as default, when installing the XCode development tools.
When entering gcc
into the terminal, it will open a prompt asking you if you want to install development tools.
Install them there.
You can use brew to install SDL, and CMake if you want to compile on the terminal.
brew install sdl2
brew install cmake
Clion is optional, use whatever CMake-compatible IDE, or your favorite text editor if you want to. Building can be done in the terminal.
Clion can be installed using the default settings.
- Git clone the repo.
- Open Clion, 'Import Project from Sources'. Navigate to the repo.
- Wait for CMake to finish processing, and try building. Building should be successful.
- Go to the project folder, it should contain a
/bin
folder. - Running the exe will result in an error: you need the appropriate DLL's.
- Go to
{VCPKG DIR}/installed/x86-windows/debug/bin
, copy paste SDL2d.dll to the project/bin folder, and rename to SDL2.dll - Run the executable again. On success, a blank window called 'An SDL2 Window' will pop up, and dissapear after 3 seconds.
Follow Windows steps 1-4: you do not need DLL's. It will work out of the box.
- Git clone the repo.
- Create a
build
folder, cd into it. cmake ..
to generate build files.make
to compile.- Executable can be found in project/bin.
Running the executable should result in a blank 640x480 window, that you can move around and close.