[Arch Linux] Cmake find_package(SDL2 REQUIRED) passes but doesn't find anything


Running Arch Linux with Cmake 3.10.3, after updating SDL from 2.0.8-1 to 2.0.8-8, the find package script stopped working.

Cmake file:
find_package(SDL2 REQUIRED)
message(“SDL2 libraries: ${SDL2_LIBRARIES}”)
message(“SDL2 includes: ${SDL2_INCLUDE_DIRS}”)

Starting to parse CMake project.
SDL2 libraries:
SDL2 includes:
Configuring done
Generating done
CMake Project was parsed successfully.

I can’t seem to find a script called FindSDL2.cmake in the Cmake modules. Any other Arch users having this issue?


Arch Linux switched from buliding SDL2 with autotools to building it with cmake. This utterly breaks how users of SDL2 need to refer to it in their cmake scripts. Unlike the autotools-geenerated SDL2Config.cmake, the cmake-generated SDL2Config.cmake exports SDL2 as a PUBLIC target, that gets IMPORTED into the script that uses find_package(SDL2). In order to use it, you need to use target_link_libraries([YOUR TARGET] SDL2::SDL2). This will also implicitly set the include paths for the sources and make things work magically - or not. In the later case, good luck!