Correct configuration of an SDL/C++ project in Kdevelop

Hello, I haven’t found anything in the wiki or on the internet on how to correctly configure a project in SDL/C++, using Kdevelop?
Does anyone know a tutorial or a very secret video that explains very well how to configure it?
greetings :smiley:

Well, the main thing is that you need a CMakeLists.txt that is correctly configured for this. The problem is that it’s very difficult to find the right way to do this on the internet, for whatever reason people simply don’t document it anywhere and upstream SDL doesn’t have instructions for this either, so I had to look in the actual CMake configuration files…

You can see my closed pull request for Centurion here, it details how to use it with CMake: Add CMakeLists example by herzenschein · Pull Request #132 · albin-johansson/centurion · GitHub (I was planning to upstream the instructions to SDL at some point, but oh well)

This should work as a good example to start with:

cmake_minimum_required(VERSION 3.20)

find_package(SDL2 REQUIRED)
find_package(SDL2_image REQUIRED)
find_package(SDL2_mixer REQUIRED)
find_package(SDL2_ttf REQUIRED)

target_sources(yourapp PRIVATE

target_link_libraries(yourapp PRIVATE

If you use C++ source files (.cpp), CMake will automatically detect it’s a C++ project rather than C. And because of the CMakeLists.txt, KDevelop should detect the project correctly.