To easily integrate the SDL2 library, I developed cross-platform modern CMake modules for finding and using the SDL2 library as well as other related libraries:
So the only things that you should do in order to integrate the SDL2 library are:
- Clone SDL2 CMake modules inside your project:
git clone https://github.com/aminosbh/sdl2-cmake-modules cmake/sdl2
- Add the following lines in your main
CMakeLists.txt
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake/sdl2)
find_package(SDL2 REQUIRED)
target_link_libraries(${PROJECT_NAME} SDL2::Main)
Note: If CMake didn't find the SDL2 library (in Windows), we can specify the CMake option SDL2_PATH
as follows:
cmake .. -DSDL2_PATH="/path/to/sdl2"
For more details, please read the README.md file.
This is a list of SDL2 samples and projects: https://github.com/aminosbh/sdl-samples-and-projects