12/1/2021

Clion Sdl2

SDL2 is the newest version of the Simple Directmedia Layer API. It can be usedtogether with CMake to build a cross platform multimedia application. In thisblog post I will describe the necessary steps to use SDL2 with CMake on bothLinux (Ubuntu 17.04) and Windows.

Clion

At this point everything is ready. Fire up the CLion and create an empty project. Edit CMakeLists and run CMake by reloading changes. As we are dynamically loading SDL2 and SDLgpu, we need to put SDL2.dll and libSDL2gpu.dll under Windows/system32 or our project’s build directory (right near to exe). Test with a simple main. SDL2 on Clion, Could not find configuration file 'SDL2Config.cmake' Follow. Florian Poinsignon Created September 16, 2020 21:52. Hello, I am trying to.

You need to create a CMakeLists.txt file for your project that includes SDL2and compiles a simple program.

You can use the following code:

Linux

Setting up SDL2 with CMake under Ubuntu Linux is pretty easy. All you need to dois install the required dependencies first.

Now you can use cmake to generate your Makefiles and build your project. Toinclude SDL2 headers you just use #include 'SDL.h'. The correct include pathshave been set up by cmake. For Linux nothing else is required.

Clion Sdl2 For Kids

Windows

For Windows you have to download the development packageSDL2-devel-2.0.5-VC.zip and extract it to some location on your hard disk.

You can create Visual Studio project files with the CMake GUI under windows butwhen you hit configure it will fail because it will not find the SDL2 Library.

In the configuration window you will see a SDL2_DIR variable. You will have topoint that to the location where you extracted the SDL2 development package.

Before you can reconfigure you also have to create a file sdl2-config.cmakewhere you extracted the development libraries and put the following content:

After that you now should be able to reconfigure successfully and generate theVisual Studio project files.

Alternative

An alternative to the config file is a FindSDL2.cmake module.CMake comes with one that works for SDL1.2, it can be adapted to work with SDL2.Here is the full content for the one that I am using:

In order to use it you have to place it somewhere in your project for instance into a cmake subdirectory.Then you have to modify the CMake module path so that it can be found.

Test App

Clion Cmake Sdl2

You can create a test application to verify that everything works. You could forinstance use the following code for that which renders a black window.

Clion Sdl2 For Windows

If you also want to use SDL2_image check out my other post Using SDL2_image with CMake.

Clion Sdl2 Windows

There is also a complete project in my github repository here.