I use SDL2 in my game. I always was using custom FindSDL2.cmake, because there is no one in standard CMake set. However, some time ago posts about FindSDL2 did appeared. Example: Reddit post.
If your cmake is new enough and it has FindSDL2.cmake file, you can do this:
find_package(SDL2 REQUIRED)
But when I download latest CMake (3.13.2), it doesn't include FindSDL2.cmake
.
What happened to it?
FindSDL2 has never appeared in CMake.
Following the reject reason in pull request #149, SDL2 ships with a SDL2Config.cmake
, which provides a cmake package.
The documentation for find_package
states that find_package(SDL2)
will behave as follows:
FindSDL2.cmake
, use that if it exists. (module mode)SDL2Config.cmake
or sdl2-config.cmake
. (config mode)In short, make sure that your SDL2 package has installed the SDL2Config.cmake
file and that is on your CMAKE_PREFIX_PATH
. The documentation lists the exact paths and prefixes it looks under.
Once you managed to find_package(SDL2)
, the following targets are available for use in target_link_libraries
:
SDL2::SDL2main
SDL2::SDL2
SDL2::SDL2-static