I used the .cmake
files from https://github.com/brendan-w/collector/tree/master/cmake, and I put them in the same directory as my CMakeLists.txt, then I used the code:
set(CMAKE_MODULE_PATH FindSDL2.cmake FindSDL2_image.cmake)
find_package(SDL2 REQUIRED)
but I'm getting the error:
CMake Error at CMakeLists.txt:26 (find_package):
By not providing "FindSDL2.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "SDL2", but
CMake did not find one.
Could not find a package configuration file provided by "SDL2" with any of
the following names:
SDL2Config.cmake
sdl2-config.cmake
Add the installation prefix of "SDL2" to CMAKE_PREFIX_PATH or set
"SDL2_DIR" to a directory containing one of the above files. If "SDL2"
provides a separate development package or SDK, be sure it has been
installed.
The CMAKE_MODULE_PATH
variable contains a list of paths to your CMake modules (FindSDL2.cmake
, FindSDL2_image.cmake
, etc. are your modules). You should append the full path to these modules on your machine to this variable:
list(APPEND CMAKE_MODULE_PATH /path/to/your/SDL2/modules)
find_package(SDL2 REQUIRED)
More recently, SDL2 provides a CMake configuration file, that can be used to help CMake find your SDL2 installation. Your error message explicitly describes this, and states the package configuration names (SDL2Config.cmake
and sdl2-config.cmake
). To allow CMake to find SDL2 using this method instead, use CMAKE_PREFIX_PATH
:
list(APPEND CMAKE_PREFIX_PATH /path/to/your/SDL2/config/files)
find_package(SDL2 REQUIRED)
Once CMake finds the package, it will define some SDL2_*
variables that can be used in your CMake project:
...
add_executable(MySDL2Executable main.cpp)
include_directories(MySDL2Executable PRIVATE ${SDL2_INCLUDE_DIRS})
target_link_libraries(MySDL2Executable PRIVATE ${SDL2_LIBRARIES})
Note, these variable names may differ based on your SDL2 version. Consult the CMake module files or package configuration files themselves for the list of SDL2_*
variable names that are defined.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With