Template for Clion/Cmake and SDL2 Setup
It's been so hard to find a decent guide about how to set up Clion and SDL2, so I made one for my future self and for some random person on internet who find this. I hope it helps you.
We are going to use the bundled MinGw 64 bits version that comes with Clion, if you use 32 bits version you should replace the CMakeLists.txt file with the proper directories paths.
Note: This project was tested on Windows 64 bits.
All the files needed to make it work are already uploaded. You just need to open with it Clion and start coding.
git clone https://github.com/llanillo/clion-cmake-sdl2-template
Download the latest SDL Development Libraries (MinGW version)
Download the SDL2 Cmake Scripts
Create a cmake/modules directory in your project root and unzip all cmake scripts there.
Unzip the SDL Development libraries in your project root, rename the folder to 'SDL2'
Mark the SDL2 folder as excluded in Clion (Optional)
Download the CMakeLists.txt from this repository and copy it to your project.
(Optional) Rename the project editing line 2 (PROJECT_NAME) in line 2.
Copy the SDL2.dll from the SDL2 folder into your cmake-build-debug folder:
Modify the main.cpp signature to look like:
int main (int argc, char* args[])
If your exit code is 0 and Clion detects your SDL2 headers then you are good to go.
Download the SDL Image Development Release
Inside your SDL2 Image folder (downloaded from step 1), select the version you are using for SDL2 and copy it to your SDL2 folder in your project (It won't override anything)
Put the SDL2_image.dll from the SDL2 Image folder into your cmake-build-debug folder.
Add to the CMakeList:
set(SDL2_IMAGE_PATH "SDL2/x86_64-w64-mingw32")
find_package(SDL2_image REQUIRED)
Modify the SDL2_IMAGE_PATH if you are using the 32 bit version