# SDL2 dependency management # Uses CPM.cmake for consistent cross-platform builds include(cmake/CPM.cmake) include(cmake/dependencies.lock) message(STATUS "Setting up SDL2 ${SDL2_VERSION} with CPM.cmake") # Try to use system packages first if requested if(YAZE_USE_SYSTEM_DEPS) find_package(SDL2 QUIET) if(SDL2_FOUND) message(STATUS "Using system SDL2") add_library(yaze_sdl2 INTERFACE IMPORTED) target_link_libraries(yaze_sdl2 INTERFACE SDL2::SDL2) if(TARGET SDL2::SDL2main) target_link_libraries(yaze_sdl2 INTERFACE SDL2::SDL2main) endif() set(YAZE_SDL2_TARGETS yaze_sdl2 PARENT_SCOPE) return() endif() endif() # Use CPM to fetch SDL2 CPMAddPackage( NAME SDL2 VERSION ${SDL2_VERSION} GITHUB_REPOSITORY libsdl-org/SDL GIT_TAG release-${SDL2_VERSION} OPTIONS "SDL_SHARED OFF" "SDL_STATIC ON" "SDL_TEST OFF" "SDL_INSTALL OFF" "SDL_CMAKE_DEBUG_POSTFIX d" ) # Verify SDL2 targets are available if(NOT TARGET SDL2::SDL2) message(FATAL_ERROR "SDL2 target not found after CPM fetch") endif() # Create convenience targets for the rest of the project add_library(yaze_sdl2 INTERFACE) target_link_libraries(yaze_sdl2 INTERFACE SDL2::SDL2) # Add platform-specific libraries if(WIN32) target_link_libraries(yaze_sdl2 INTERFACE winmm imm32 version setupapi wbemuuid ) target_compile_definitions(yaze_sdl2 INTERFACE SDL_MAIN_HANDLED) elseif(APPLE) target_link_libraries(yaze_sdl2 INTERFACE "-framework Cocoa" "-framework IOKit" "-framework CoreVideo" "-framework ForceFeedback" ) target_compile_definitions(yaze_sdl2 INTERFACE SDL_MAIN_HANDLED) elseif(UNIX) find_package(PkgConfig REQUIRED) pkg_check_modules(GTK3 REQUIRED gtk+-3.0) target_link_libraries(yaze_sdl2 INTERFACE ${GTK3_LIBRARIES}) target_include_directories(yaze_sdl2 INTERFACE ${GTK3_INCLUDE_DIRS}) target_compile_options(yaze_sdl2 INTERFACE ${GTK3_CFLAGS_OTHER}) endif() # Export SDL2 targets for use in other CMake files set(YAZE_SDL2_TARGETS yaze_sdl2) message(STATUS "SDL2 setup complete")