# Try to find SDL2 in common locations find_path(SDL2_INCLUDE_DIR SDL.h PATHS /usr/include/SDL2 /usr/local/include/SDL2 $ENV{SDL2_DIR}/include PATH_SUFFIXES SDL2 ) find_library(SDL2_LIBRARY NAMES SDL2 PATHS /usr/lib /usr/local/lib $ENV{SDL2_DIR}/lib ) if(SDL2_INCLUDE_DIR AND SDL2_LIBRARY) set(SDL2_FOUND TRUE) set(SDL2_LIBRARIES ${SDL2_LIBRARY}) set(SDL2_INCLUDE_DIRS ${SDL2_INCLUDE_DIR}) endif() # If not found, use FetchContent to acquire SDL2 if(NOT SDL2_FOUND) include(FetchContent) FetchContent_Declare( SDL2 GIT_REPOSITORY https://github.com/libsdl-org/SDL.git GIT_TAG release-2.28.5 # Change to desired version ) FetchContent_MakeAvailable(SDL2) set(SDL2_FOUND TRUE) set(SDL2_LIBRARIES SDL2) set(SDL2_INCLUDE_DIRS ${sdl2_SOURCE_DIR}/include) endif() # Provide variables for downstream usage if(SDL2_FOUND) set(SDL2_INCLUDE_DIR ${SDL2_INCLUDE_DIRS} CACHE PATH "SDL2 include directory") set(SDL2_LIBRARY ${SDL2_LIBRARIES} CACHE FILEPATH "SDL2 library") endif()