cmake_minimum_required(VERSION 3.20) project(hdk-sdl VERSION 0.0.1 LANGUAGES CXX DESCRIPTION "header only shared_ptr wrappers around SDL3 structs and functions" ) # Note: The src/ directory contains Doxygen documentation-only .cpp files. # This is a header-only library; src/ files are not compiled into any targets. # hdk-sdl OPTIONS option(HDK_SDL_TESTS "Build hdk-sdl tests" ${HDK_TESTS}) option(HDK_SDL_EXAMPLES "Build hdk-sdl examples" ${HDK_EXAMPLES}) option(HDK_SDL_INSTALL_TARGETS "Enable hdk-sdl install/export stubs" ON) option(HDK_SDL_SYSTEM_SDL3 "Use system SDL3 instead of FetchContent for building" OFF) option(HDK_SDL_BUNDLE_SDL3 "Build and bundle SDL3 as a static lib with hdk-sdl install" OFF) if(HDK_SDL_SYSTEM_SDL3 AND HDK_SDL_BUNDLE_SDL3) message(FATAL_ERROR "HDK_SDL_SYSTEM_SDL3 and HDK_SDL_BUNDLE_SDL3 are mutually exclusive") endif() if(HDK_SDL_EXAMPLES) add_subdirectory(examples) endif() # FOR SDL Building if(NOT HDK_SDL_SYSTEM_SDL3) set(SDL_TEST OFF CACHE BOOL "Disable SDL tests" FORCE) set(SDL_EXAMPLES OFF CACHE BOOL "Disable SDL examples" FORCE) set(SDL_INSTALL OFF CACHE BOOL "Disable SDL install" FORCE) # NOTE: Possibly disable SDL_PIPEWIRE and/or SDL_PIPEWIRE_SHARED? if(HDK_SDL_BUNDLE_SDL3) set(SDL_STATIC ON CACHE BOOL "Build SDL3 as static library for bundling" FORCE) set(SDL_SHARED OFF CACHE BOOL "Disable SDL3 shared library for bundling" FORCE) endif() include(FetchContent) FetchContent_Declare( SDL3 GIT_REPOSITORY https://github.com/libsdl-org/SDL.git GIT_TAG release-3.4.8 ) FetchContent_MakeAvailable(SDL3) else() find_package(SDL3 REQUIRED) endif() include(GNUInstallDirs) add_library(hdk-sdl INTERFACE) target_link_libraries(hdk-sdl INTERFACE $ $ $ $ ) target_include_directories(hdk-sdl INTERFACE $ $ ) target_compile_features(hdk-sdl INTERFACE cxx_std_17) if(HDK_SDL_INSTALL_TARGETS) include(CMakePackageConfigHelpers) install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) # Choose config file based on bundle mode if(HDK_SDL_BUNDLE_SDL3) set(_hdk_sdl_config_file hdk-sdlConfig-bundled.cmake.in) else() set(_hdk_sdl_config_file hdk-sdlConfig.cmake.in) endif() configure_package_config_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/${_hdk_sdl_config_file} ${CMAKE_CURRENT_BINARY_DIR}/hdk-sdlConfig.cmake INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hdk-sdl PATH_VARS CMAKE_INSTALL_INCLUDEDIR CMAKE_INSTALL_LIBDIR ) write_basic_package_version_file( ${CMAKE_CURRENT_BINARY_DIR}/hdk-sdlConfigVersion.cmake VERSION ${PROJECT_VERSION} COMPATIBILITY SameMajorVersion ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/hdk-sdlConfig.cmake ${CMAKE_CURRENT_BINARY_DIR}/hdk-sdlConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hdk-sdl ) # Bundled SDL3 install rules if(HDK_SDL_BUNDLE_SDL3) install(FILES $ DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hdk-sdl/sdl3-static ) install(DIRECTORY ${sdl3_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) configure_file( ${CMAKE_CURRENT_SOURCE_DIR}/cmake/hdk-sdlBundledSDL3Targets.cmake.in ${CMAKE_CURRENT_BINARY_DIR}/hdk-sdlBundledSDL3Targets.cmake @ONLY ) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/hdk-sdlBundledSDL3Targets.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/hdk-sdl ) endif() endif() if(HDK_SDL_TESTS) add_subdirectory(test) endif()