diff --git a/CMakeLists.txt b/CMakeLists.txt index c289ad043..47d0fa62b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.0.0) +cmake_minimum_required(VERSION 3.16) if(CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_CURRENT_BINARY_DIR) message(FATAL_ERROR "Prevented in-tree build. Please create a build directory outside of the SDL source code and run \"cmake -S ${CMAKE_SOURCE_DIR} -B .\" from there") @@ -13,26 +13,6 @@ else() set(SDL3_SUBPROJECT ON) endif() -set(SDL_EXTRA_LIBS) -set(SDL_EXTRA_LDFLAGS) - -set(SDL_CMAKE_DEPENDS) -set(SDL_PC_PRIVATE_REQUIRES) - -# The sdl-build-options interface library collects all PRIVATE build options for the SDL libraries -add_library(sdl-build-options INTERFACE) - -# The sdl-shared-build-options interface library collects all PRIVATE build options for the SDL shared library -add_library(sdl-shared-build-options INTERFACE) - -# The sdl-global-options interface library collects all PRIVATE build options for the SDL libraries + test + ... -add_library(sdl-global-options INTERFACE) - -if(WINDOWS_STORE) - target_compile_definitions(sdl-build-options INTERFACE "SDL_BUILDING_WINRT=1") - target_compile_options(sdl-build-options INTERFACE "-ZW") -endif() - # CMake 3.0 expands the "if(${A})" in "set(OFF 1);set(A OFF);if(${A})" to "if(1)" # CMake 3.24+ emits a warning when not set. unset(OFF) @@ -55,31 +35,25 @@ include(CMakeParseArguments) include(CMakePushCheckState) include(GNUInstallDirs) +if(NOT DEFINED OpenGL_GL_PREFERENCE) + set(OpenGL_GL_PREFERENCE GLVND) +endif() + find_package(PkgConfig) list(APPEND CMAKE_MODULE_PATH "${SDL3_SOURCE_DIR}/cmake") -include(${SDL3_SOURCE_DIR}/cmake/macros.cmake) -include(${SDL3_SOURCE_DIR}/cmake/sdlmanpages.cmake) -include(${SDL3_SOURCE_DIR}/cmake/sdlchecks.cmake) -include(${SDL3_SOURCE_DIR}/cmake/sdlfind.cmake) -include(${SDL3_SOURCE_DIR}/cmake/sdlplatform.cmake) -include(${SDL3_SOURCE_DIR}/cmake/CheckCPUArchitecture.cmake) -include(${SDL3_SOURCE_DIR}/cmake/GetGitRevisionDescription.cmake) -include(${SDL3_SOURCE_DIR}/cmake/3rdparty.cmake) +include("${SDL3_SOURCE_DIR}/cmake/macros.cmake") +include("${SDL3_SOURCE_DIR}/cmake/sdlchecks.cmake") +include("${SDL3_SOURCE_DIR}/cmake/sdlcompilers.cmake") +include("${SDL3_SOURCE_DIR}/cmake/sdlmanpages.cmake") +include("${SDL3_SOURCE_DIR}/cmake/sdlplatform.cmake") +include("${SDL3_SOURCE_DIR}/cmake/sdltargets.cmake") +include("${SDL3_SOURCE_DIR}/cmake/CheckCPUArchitecture.cmake") +include("${SDL3_SOURCE_DIR}/cmake/GetGitRevisionDescription.cmake") +include("${SDL3_SOURCE_DIR}/cmake/3rdparty.cmake") -check_symbol_exists("__GLIBC__" "stdlib.h" LIBC_IS_GLIBC) -if(LIBC_IS_GLIBC AND CMAKE_SIZEOF_VOID_P EQUAL 4) - # Enable large file support on 32-bit glibc, so that we can access files with large inode numbers - target_compile_definitions(sdl-build-options INTERFACE "_FILE_OFFSET_BITS=64") - # Enable 64-bit time_t on 32-bit glibc, so that time stamps remain correct beyond January 2038 - target_compile_definitions(sdl-build-options INTERFACE "_TIME_BITS=64") -endif() - -if(CMAKE_VERSION VERSION_LESS "3.26") - set(build_local_interface "BUILD_INTERFACE") -else() - set(build_local_interface "BUILD_LOCAL_INTERFACE") -endif() +SDL_DetectCompiler() +SDL_DetectCPUArchitecture() # Increment this if there is an incompatible change - but if that happens, # we should rename the library from SDL3 to SDL4, at which point this would @@ -100,32 +74,21 @@ else() math(EXPR SDL_DYLIB_CURRENT_VERSION_MAJOR "${SDL_DYLIB_COMPAT_VERSION_MAJOR}") set(SDL_DYLIB_CURRENT_VERSION_MINOR "0") endif() -set(SDL_DYLIB_COMPAT_VERSION_PATCH "0") +set(SDL_DYLIB_CURRENT_VERSION_PATCH "0") set(SDL_DYLIB_COMPAT_VERSION_PATCH "0") -set(SDL_DYLIB_CURRENT_VERSION "${SDL_DYLIB_CURRENT_VERSION_MAJOR}.${SDL_DYLIB_CURRENT_VERSION_MINOR}.${SDL_DYLIB_COMPAT_VERSION_PATCH}") +set(SDL_DYLIB_CURRENT_VERSION "${SDL_DYLIB_CURRENT_VERSION_MAJOR}.${SDL_DYLIB_CURRENT_VERSION_MINOR}.${SDL_DYLIB_CURRENT_VERSION_PATCH}") set(SDL_DYLIB_COMPAT_VERSION "${SDL_DYLIB_COMPAT_VERSION_MAJOR}.${SDL_DYLIB_COMPAT_VERSION_MINOR}.${SDL_DYLIB_COMPAT_VERSION_PATCH}") -#message("SDL_SO_VERSION=${SDL_SO_VERSION} SDL_DYLIB_CURRENT_VERSION=${SDL_DYLIB_CURRENT_VERSION} SDL_DYLIB_COMPAT_VERSION=${SDL_DYLIB_COMPAT_VERSION}") +message(DEBUG "SDL_SO_VERSION=${SDL_SO_VERSION} SDL_DYLIB_CURRENT_VERSION=${SDL_DYLIB_CURRENT_VERSION} SDL_DYLIB_COMPAT_VERSION=${SDL_DYLIB_COMPAT_VERSION}") set(SDL_FRAMEWORK_VERSION "A") -SDL_DetectCPUArchitecture() - -# Check for 64 or 32 bit -if(CMAKE_SIZEOF_VOID_P EQUAL 8) - set(ARCH_64 TRUE) - set(PROCESSOR_ARCH "x64") -else() - set(ARCH_64 FALSE) - set(PROCESSOR_ARCH "x86") -endif() - set(SDL_CHECK_REQUIRED_INCLUDES "" CACHE STRING "Extra includes (for CMAKE_REQUIRED_INCLUDES)") set(SDL_CHECK_REQUIRED_LINK_OPTIONS "" CACHE STRING "Extra link options (for CMAKE_REQUIRED_LINK_OPTIONS)") mark_as_advanced(SDL_CHECK_REQUIRED_INCLUDES SDL_CHECK_REQUIRED_LINK_OPTIONS) -set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -D_GNU_SOURCE=1") +string(APPEND CMAKE_REQUIRED_FLAGS " -D_GNU_SOURCE=1") list(APPEND CMAKE_REQUIRED_INCLUDES ${SDL_CHECK_REQUIRED_INCLUDES}) list(APPEND CMAKE_REQUIRED_LINK_OPTIONS ${SDL_CHECK_REQUIRED_LINK_OPTIONS}) @@ -153,15 +116,15 @@ endif() # commonly supported in browsers or the Emscripten teams makes a single # binary work everywhere. if (UNIX_OR_MAC_SYS AND NOT EMSCRIPTEN) - set(SDL_PTHREADS_ENABLED_BY_DEFAULT ON) + set(SDL_PTHREADS_DEFAULT ON) else() - set(SDL_PTHREADS_ENABLED_BY_DEFAULT OFF) + set(SDL_PTHREADS_DEFAULT OFF) endif() if(UNIX_SYS OR ANDROID) - set(SDL_CLOCK_GETTIME_ENABLED_BY_DEFAULT ON) + set(SDL_CLOCK_GETTIME_DEFAULT ON) else() - set(SDL_CLOCK_GETTIME_ENABLED_BY_DEFAULT OFF) + set(SDL_CLOCK_GETTIME_DEFAULT OFF) endif() # The hidraw support doesn't catch Xbox, PS4 and Nintendo controllers, @@ -182,31 +145,14 @@ else() set(SDL_HIDAPI_LIBUSB_DEFAULT FALSE) endif() -# Compiler info -if(CMAKE_C_COMPILER_ID MATCHES "Clang|IntelLLVM") - set(USE_CLANG TRUE) - set(SDL_ASSEMBLY_DEFAULT TRUE) - # Visual Studio 2019 v16.2 added support for Clang/LLVM. - # Check if a Visual Studio project is being generated with the Clang toolset. - if(MSVC) - set(MSVC_CLANG TRUE) - endif() -elseif(CMAKE_COMPILER_IS_GNUCC) - set(USE_GCC TRUE) - set(SDL_ASSEMBLY_DEFAULT TRUE) -elseif(MSVC_VERSION GREATER 1400) # VisualStudio 8.0+ - set(SDL_ASSEMBLY_DEFAULT TRUE) -elseif(CMAKE_C_COMPILER_ID MATCHES "^Intel$") - set(SDL_ASSEMBLY_DEFAULT TRUE) - set(USE_INTELCC TRUE) -elseif(CMAKE_C_COMPILER_ID MATCHES "QCC") - set(USE_QCC TRUE) -else() - set(SDL_ASSEMBLY_DEFAULT FALSE) +set(SDL_ASSEMBLY_DEFAULT OFF) +if(USE_CLANG OR USE_GCC OR USE_INTELCC OR MSVC_VERSION GREATER 1400) + set(SDL_ASSEMBLY_DEFAULT ON) endif() +set(SDL_GCC_ATOMICS_DEFAULT OFF) if(USE_GCC OR USE_CLANG OR USE_INTELCC OR USE_QCC) - set(OPT_DEF_GCC_ATOMICS ON) + set(SDL_GCC_ATOMICS_DEFAULT ON) endif() # Default option knobs @@ -217,19 +163,6 @@ if(WINDOWS) set(SDL_SYSTEM_ICONV_DEFAULT OFF) endif() -if(NOT ("$ENV{CFLAGS}" STREQUAL "")) - if(CMAKE_VERSION VERSION_LESS 3.11.0) - message(WARNING "SDL's CMakeLists.txt no longer checks the CFLAGS environment.") - message(WARNING "Please use CMake's CMAKE_C_FLAGS and CMAKE_BUILD_TYPE variables directly.") - message(WARNING "Or upgrade to CMake >= 3.11.0, which respects the CFLAGS environment var.") - endif() -endif() - -# Build in parallel under Visual Studio. Not enabled by default. -if(MSVC AND NOT USE_CLANG) - target_compile_options(sdl-build-options INTERFACE "/MP") -endif() - if(MSVC) option(SDL_FORCE_STATIC_VCRT "Force /MT for static VC runtimes" OFF) if(SDL_FORCE_STATIC_VCRT) @@ -261,108 +194,73 @@ if(MSVC) endif() endif() -# Those are used for pkg-config so sdl3.pc is created correctly. -set(SDL_PC_LIBS "-lSDL3") -set(SDL_PC_CFLAGS ) +set(SDL_SHARED_DEFAULT ON) +set(SDL_STATIC_DEFAULT ON) -# When building shared lib for Windows with MinGW, -# avoid the DLL having a "lib" prefix -if(WINDOWS) - set(CMAKE_SHARED_LIBRARY_PREFIX "") -endif() +set(SDL_SHARED_AVAILABLE ON) -check_linker_flag(C "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/dynapi/SDL_dynapi.sym" HAVE_WL_VERSION_SCRIPT) -if(HAVE_WL_VERSION_SCRIPT) - target_link_libraries(sdl-shared-build-options INTERFACE "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/dynapi/SDL_dynapi.sym") -else() - if((LINUX AND LIBC_IS_GLIBC) OR ANDROID) - message(FATAL_ERROR "Linker does not support '-Wl,--version-script=xxx.sym'. This is required on the current host platform (${SDL_CMAKE_PLATFORM}).") - endif() -endif() - -if(CYGWIN) - # We build SDL on cygwin without the UNIX emulation layer - target_include_directories(sdl-build-options SYSTEM INTERFACE "/usr/include/mingw") - cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mno-cygwin") - check_c_source_compiles("int main(int argc, char **argv) { return 0; }" - HAVE_GCC_NO_CYGWIN) - cmake_pop_check_state() - if(HAVE_GCC_NO_CYGWIN) - target_link_libraries(sdl-shared-build-options INTERFACE "-mno-cygwin") - endif() - list(APPEND SDL_PC_CFLAGS "-I/usr/include/mingw") -endif() - -# General includes -target_compile_definitions(sdl-build-options INTERFACE "USING_GENERATED_CONFIG_H") -target_include_directories(sdl-build-options - INTERFACE - "${SDL3_BINARY_DIR}/include-config-$>" - "${SDL3_BINARY_DIR}/include" - "${SDL3_SOURCE_DIR}/include" -) -# Note: The clang toolset for Visual Studio does not support the '-idirafter' option. -if(USE_GCC OR USE_INTELCC OR (USE_CLANG AND NOT MSVC_CLANG)) - if(CMAKE_VERSION VERSION_LESS 3.12) - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -idirafter \"${SDL3_SOURCE_DIR}/src/video/khronos\"") - else() - target_compile_options(sdl-global-options INTERFACE "SHELL:-idirafter \"${SDL3_SOURCE_DIR}/src/video/khronos\"") - endif() -else() - target_include_directories(sdl-global-options SYSTEM INTERFACE "${SDL3_SOURCE_DIR}/src/video/khronos") -endif() - -set(SDL_SHARED_ENABLED_BY_DEFAULT ON) -set(SDL_STATIC_ENABLED_BY_DEFAULT ON) - -# All these ENABLED_BY_DEFAULT vars will default to ON if not specified, so -# you only need to have a platform override them if they are disabling. +# All these *_DEFAULT vars will default to ON if not specified, +# so you only need to override them if they need to be disabled. if(EMSCRIPTEN) # Set up default values for the currently supported set of subsystems: # Emscripten/Javascript does not have assembly support, a dynamic library # loading architecture, or low-level CPU inspection. - # SDL_THREADS_ENABLED_BY_DEFAULT now defaults to ON, but pthread support might be disabled by default. + # SDL_THREADS_DEFAULT now defaults to ON, but pthread support might be disabled by default. # !!! FIXME: most of these subsystems should default to ON if there are dummy implementations to be used. - set(SDL_ASSEMBLY_DEFAULT FALSE) - set(SDL_SHARED_ENABLED_BY_DEFAULT OFF) - set(SDL_ATOMIC_ENABLED_BY_DEFAULT OFF) - set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF) - set(SDL_CPUINFO_ENABLED_BY_DEFAULT OFF) + set(SDL_ASSEMBLY_DEFAULT OFF) + set(SDL_SHARED_AVAILABLE OFF) + set(SDL_ATOMIC_DEFAULT OFF) + set(SDL_LOADSO_DEFAULT OFF) + set(SDL_CPUINFO_DEFAULT OFF) endif() if(VITA OR PSP OR PS2 OR N3DS OR RISCOS) - set(SDL_SHARED_ENABLED_BY_DEFAULT OFF) - set(SDL_LOADSO_ENABLED_BY_DEFAULT OFF) + set(SDL_SHARED_AVAILABLE OFF) + set(SDL_LOADSO_DEFAULT OFF) endif() -if(SDL_SHARED_ENABLED_BY_DEFAULT AND SDL_STATIC_ENABLED_BY_DEFAULT) +if(SDL_SHARED_DEFAULT AND SDL_STATIC_DEFAULT AND SDL_SHARED_AVAILABLE) if(DEFINED BUILD_SHARED_LIBS) # When defined, use BUILD_SHARED_LIBS as default if(BUILD_SHARED_LIBS) - set(SDL_STATIC_ENABLED_BY_DEFAULT OFF) + set(SDL_STATIC_DEFAULT OFF) else() - set(SDL_SHARED_ENABLED_BY_DEFAULT OFF) + set(SDL_SHARED_DEFAULT OFF) endif() else() # Default to just building the shared library - set(SDL_STATIC_ENABLED_BY_DEFAULT OFF) + set(SDL_STATIC_DEFAULT OFF) endif() endif() -set(LONGESTOPTIONNAME 0) # set_option and friends will change this. - set(SDL_SUBSYSTEMS - Atomic Audio Video Render Events Joystick Haptic Hidapi Power Threads Timers - File Loadso CPUinfo Filesystem Sensor Locale Misc) -foreach(_SUB ${SDL_SUBSYSTEMS}) + Atomic + Audio + Video + Render + Events + Joystick + Haptic + Hidapi + Power + Threads + Timers + File + Loadso + CPUinfo + Filesystem + Sensor + Locale + Misc +) +foreach(_SUB IN LISTS SDL_SUBSYSTEMS) string(TOUPPER ${_SUB} _OPT) - if (NOT DEFINED SDL_${_OPT}_ENABLED_BY_DEFAULT) - set(SDL_${_OPT}_ENABLED_BY_DEFAULT ON) + if(NOT DEFINED SDL_${_OPT}_DEFAULT) + set(SDL_${_OPT}_DEFAULT ON) endif() - option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ${SDL_${_OPT}_ENABLED_BY_DEFAULT}) + option(SDL_${_OPT} "Enable the ${_SUB} subsystem" ${SDL_${_OPT}_DEFAULT}) endforeach() # Allow some projects to be built conditionally. @@ -374,7 +272,6 @@ set_option(SDL_DISABLE_UNINSTALL "Disable uninstallation of SDL3" OFF) cmake_dependent_option(SDL_DISABLE_ANDROID_JAR "Disable creation of SDL3.jar" ${SDL3_SUBPROJECT} "ANDROID" ON) option_string(SDL_ASSERTIONS "Enable internal sanity checks (auto/disabled/release/enabled/paranoid)" "auto") -#set_option(SDL_DEPENDENCY_TRACKING "Use gcc -MMD -MT dependency tracking" ON) set_option(SDL_ASSEMBLY "Enable assembly routines" ${SDL_ASSEMBLY_DEFAULT}) dep_option(SDL_AVX "Use AVX assembly routines" ON "SDL_ASSEMBLY;SDL_CPU_X86 OR SDL_CPU_X64" OFF) dep_option(SDL_AVX2 "Use AVX2 assembly routines" ON "SDL_ASSEMBLY;SDL_CPU_X86 OR SDL_CPU_X64" OFF) @@ -394,7 +291,7 @@ dep_option(SDL_LASX "Use LASX assembly routines" ON "SDL_ASSEMBLY set_option(SDL_LIBC "Use the system C library" ${SDL_LIBC_DEFAULT}) set_option(SDL_SYSTEM_ICONV "Use iconv() from system-installed libraries" ${SDL_SYSTEM_ICONV_DEFAULT}) -set_option(SDL_GCC_ATOMICS "Use gcc builtin atomics" ${OPT_DEF_GCC_ATOMICS}) +set_option(SDL_GCC_ATOMICS "Use gcc builtin atomics" ${SDL_GCC_ATOMICS_DEFAULT}) dep_option(SDL_DBUS "Enable D-Bus support" ON ${UNIX_SYS} OFF) set_option(SDL_DISKAUDIO "Support the disk writer audio driver" ON) set_option(SDL_DUMMYAUDIO "Support the dummy audio driver" ON) @@ -402,7 +299,7 @@ set_option(SDL_DUMMYVIDEO "Use dummy video driver" ON) dep_option(SDL_IBUS "Enable IBus support" ON ${UNIX_SYS} OFF) set_option(SDL_OPENGL "Include OpenGL support" ON) set_option(SDL_OPENGLES "Include OpenGL ES support" ON) -set_option(SDL_PTHREADS "Use POSIX threads for multi-threading" ${SDL_PTHREADS_ENABLED_BY_DEFAULT}) +set_option(SDL_PTHREADS "Use POSIX threads for multi-threading" ${SDL_PTHREADS_DEFAULT}) dep_option(SDL_PTHREADS_SEM "Use pthread semaphores" ON "SDL_PTHREADS" OFF) dep_option(SDL_OSS "Support the OSS audio API" ON "UNIX_SYS OR RISCOS" OFF) set_option(SDL_ALSA "Support the ALSA audio API" ${UNIX_SYS}) @@ -416,7 +313,7 @@ dep_option(SDL_PULSEAUDIO_SHARED "Dynamically load PulseAudio support" ON "SDL set_option(SDL_SNDIO "Support the sndio audio API" ${UNIX_SYS}) dep_option(SDL_SNDIO_SHARED "Dynamically load the sndio audio API" ON "SDL_SNDIO" OFF) set_option(SDL_RPATH "Use an rpath when linking SDL" ${UNIX_SYS}) -set_option(SDL_CLOCK_GETTIME "Use clock_gettime() instead of gettimeofday()" ${SDL_CLOCK_GETTIME_ENABLED_BY_DEFAULT}) +set_option(SDL_CLOCK_GETTIME "Use clock_gettime() instead of gettimeofday()" ${SDL_CLOCK_GETTIME_DEFAULT}) set_option(SDL_X11 "Use X11 video driver" ${UNIX_SYS}) dep_option(SDL_X11_SHARED "Dynamically load X11 support" ON "SDL_X11" OFF) set(SDL_X11_OPTIONS Xcursor Xdbe XInput Xfixes Xrandr Xscrnsaver XShape) @@ -429,15 +326,15 @@ dep_option(SDL_WAYLAND_SHARED "Dynamically load Wayland support" ON "SDL_WA dep_option(SDL_WAYLAND_LIBDECOR "Use client-side window decorations on Wayland" ON "SDL_WAYLAND" OFF) dep_option(SDL_WAYLAND_LIBDECOR_SHARED "Dynamically load libdecor support" ON "SDL_WAYLAND_LIBDECOR;SDL_WAYLAND_SHARED" OFF) dep_option(SDL_WAYLAND_QT_TOUCH "QtWayland server support for Wayland video driver" ON "SDL_WAYLAND" OFF) -set_option(SDL_RPI "Use Raspberry Pi video driver" ${UNIX_SYS}) -set_option(SDL_ROCKCHIP "Use ROCKCHIP Hardware Acceleration video driver" ${UNIX_SYS}) +dep_option(SDL_RPI "Use Raspberry Pi video driver" ON "UNIX_SYS;SDL_CPU_ARM32 OR SDL_CPU_ARM64" OFF) +dep_option(SDL_ROCKCHIP "Use ROCKCHIP Hardware Acceleration video driver" ON "UNIX_SYS;SDL_CPU_ARM32 OR SDL_CPU_ARM64" OFF) set_option(SDL_COCOA "Use Cocoa video driver" ${APPLE}) set_option(SDL_DIRECTX "Use DirectX for Windows audio/video" ${WINDOWS}) set_option(SDL_XINPUT "Use Xinput for Windows" ${WINDOWS}) set_option(SDL_WASAPI "Use the Windows WASAPI audio driver" ${WINDOWS}) set_option(SDL_RENDER_D3D "Enable the Direct3D render driver" ${WINDOWS}) set_option(SDL_RENDER_METAL "Enable the Metal render driver" ${APPLE}) -set_option(SDL_VIVANTE "Use Vivante EGL video driver" ${UNIX_SYS}) +dep_option(SDL_VIVANTE "Use Vivante EGL video driver" ON "${UNIX_SYS};SDL_CPU_ARM32" OFF) dep_option(SDL_VULKAN "Enable Vulkan support" ON "ANDROID OR APPLE OR LINUX OR WINDOWS" OFF) set_option(SDL_METAL "Enable Metal support" ${APPLE}) set_option(SDL_KMSDRM "Use KMS DRM video driver" ${UNIX_SYS}) @@ -451,14 +348,13 @@ dep_option(SDL_HIDAPI_JOYSTICK "Use HIDAPI for low level joystick drivers" O dep_option(SDL_VIRTUAL_JOYSTICK "Enable the virtual-joystick driver" ON SDL_HIDAPI OFF) set_option(SDL_LIBUDEV "Enable libudev support" ON) set_option(SDL_ASAN "Use AddressSanitizer to detect memory errors" OFF) -option_string(SDL_VENDOR_INFO "Vendor name and/or version to add to SDL_REVISION" "") set_option(SDL_CCACHE "Use Ccache to speed up build" OFF) set_option(SDL_CLANG_TIDY "Run clang-tidy static analysis" OFF) -option(SDL_WERROR "Enable -Werror" OFF) +set(SDL_VENDOR_INFO "" CACHE STRING "Vendor name and/or version to add to SDL_REVISION") -option(SDL_SHARED "Build a shared version of the library" ${SDL_SHARED_ENABLED_BY_DEFAULT}) -option(SDL_STATIC "Build a static version of the library" ${SDL_STATIC_ENABLED_BY_DEFAULT}) +cmake_dependent_option(SDL_SHARED "Build a shared version of the library" ${SDL_SHARED_DEFAULT} ${SDL_SHARED_AVAILABLE} OFF) +option(SDL_STATIC "Build a static version of the library" ${SDL_STATIC_DEFAULT}) option(SDL_TEST "Build the SDL3_test library" ON) # Apple Frameworks NEED a (shared) SDL3.framework for `#include ` to work @@ -470,42 +366,122 @@ dep_option(SDL_INSTALL_TESTS "Install test-cases" OFF "NOT SDL_DISABLE_INSTALL dep_option(SDL_TESTS_LINK_SHARED "link tests to shared SDL library" "${SDL_SHARED}" "SDL_SHARED;SDL_STATIC" "${SDL_SHARED}") set(SDL_TESTS_TIMEOUT_MULTIPLIER "1" CACHE STRING "Timeout multiplier to account for really slow machines") +if(VITA) + set_option(VIDEO_VITA_PIB "Build with PSVita piglet gles2 support" OFF) + set_option(VIDEO_VITA_PVR "Build with PSVita PVR gles/gles2 support" OFF) +endif() + set(HAVE_STATIC_PIC "${SDL_STATIC_PIC}") if(NOT (SDL_SHARED OR SDL_STATIC)) message(FATAL_ERROR "SDL_SHARED and SDL_STATIC cannot both be disabled") endif() -if(VITA) - set_option(VIDEO_VITA_PIB "Build with PSVita piglet gles2 support" OFF) - set_option(VIDEO_VITA_PVR "Build with PSVita PVR gles/gles2 support" OFF) +if(SDL_SHARED) + add_library(SDL3-shared SHARED) + add_library(SDL3::SDL3-shared ALIAS SDL3-shared) + SDL_AddCommonCompilerFlags(SDL3-shared) +endif() + +if(SDL_STATIC) + add_library(SDL3-static STATIC) + add_library(SDL3::SDL3-static ALIAS SDL3-static) + SDL_AddCommonCompilerFlags(SDL3-static) +endif() + +if(SDL_TEST) + add_library(SDL3_test STATIC) + add_library(SDL3::SDL3_test ALIAS SDL3_test) + SDL_AddCommonCompilerFlags(SDL3_test) +endif() + +# Make sure SDL3::SDL3 always exists +if(TARGET SDL3::SDL3-shared) + add_library(SDL3::SDL3 ALIAS SDL3-shared) +else() + add_library(SDL3::SDL3 ALIAS SDL3-static) +endif() + +sdl_pc_link_options("-lSDL3") + +# Enable large file support on 32-bit glibc, so that we can access files +# with large inode numbers +check_symbol_exists("__GLIBC__" "stdlib.h" LIBC_IS_GLIBC) +if (LIBC_IS_GLIBC AND CMAKE_SIZEOF_VOID_P EQUAL 4) + # Enable large file support on 32-bit glibc, so that we can access files with large inode numbers + sdl_compile_definitions(PRIVATE "_FILE_OFFSET_BITS=64") + # Enable 64-bit time_t on 32-bit glibc, so that time stamps remain correct beyond January 2038 + sdl_compile_definitions(PRIVATE "_TIME_BITS=64") +endif() + +if(WINDOWS_STORE) + sdl_compile_definitions(PRIVATE "SDL_BUILDING_WINRT=1") + sdl_compile_options(PRIVATE "-ZW") +endif() + +check_linker_flag(C "-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/dynapi/SDL_dynapi.sym" HAVE_WL_VERSION_SCRIPT) +if(HAVE_WL_VERSION_SCRIPT) + sdl_shared_link_options("-Wl,--version-script=${CMAKE_CURRENT_SOURCE_DIR}/src/dynapi/SDL_dynapi.sym") +else() + if((LINUX AND LIBC_IS_GLIBC) OR ANDROID) + message(FATAL_ERROR "Linker does not support '-Wl,--version-script=xxx.sym'. This is required on the current host platform (${SDL_CMAKE_PLATFORM}).") + endif() +endif() + +if(CYGWIN) + # We build SDL on cygwin without the UNIX emulation layer + sdl_include_directories(PUBLIC SYSTEM "/usr/include/mingw") + cmake_push_check_state() + string(APPEND CMAKE_REQUIRED_FLAGS " -mno-cygwin") + check_c_source_compiles("int main(int argc, char **argv) { return 0; }" + HAVE_GCC_NO_CYGWIN) + cmake_pop_check_state() + if(HAVE_GCC_NO_CYGWIN) + sdl_shared_link_options("-mno-cygwin") + endif() +endif() + +# General includes +sdl_compile_definitions(PRIVATE "USING_GENERATED_CONFIG_H") +sdl_include_directories( + PRIVATE + "${SDL3_BINARY_DIR}/include-config-$>" + "${SDL3_BINARY_DIR}/include" + "${SDL3_SOURCE_DIR}/include" +) +# Note: The clang toolset for Visual Studio does not support the '-idirafter' option. +if(USE_GCC OR USE_INTELCC OR (USE_CLANG AND NOT MSVC_CLANG)) + sdl_compile_options(NO_EXPORT PUBLIC "$") +else() + sdl_include_directories(NO_EXPORT SYSTEM PUBLIC "$") endif() # General source files -file(GLOB SOURCE_FILES - ${SDL3_SOURCE_DIR}/src/*.c - ${SDL3_SOURCE_DIR}/src/atomic/*.c - ${SDL3_SOURCE_DIR}/src/audio/*.c - ${SDL3_SOURCE_DIR}/src/core/*.c - ${SDL3_SOURCE_DIR}/src/cpuinfo/*.c - ${SDL3_SOURCE_DIR}/src/dynapi/*.c - ${SDL3_SOURCE_DIR}/src/events/*.c - ${SDL3_SOURCE_DIR}/src/file/*.c - ${SDL3_SOURCE_DIR}/src/joystick/*.c - ${SDL3_SOURCE_DIR}/src/haptic/*.c - ${SDL3_SOURCE_DIR}/src/hidapi/*.c - ${SDL3_SOURCE_DIR}/src/libm/*.c - ${SDL3_SOURCE_DIR}/src/locale/*.c - ${SDL3_SOURCE_DIR}/src/misc/*.c - ${SDL3_SOURCE_DIR}/src/power/*.c - ${SDL3_SOURCE_DIR}/src/render/*.c - ${SDL3_SOURCE_DIR}/src/render/*/*.c - ${SDL3_SOURCE_DIR}/src/sensor/*.c - ${SDL3_SOURCE_DIR}/src/stdlib/*.c - ${SDL3_SOURCE_DIR}/src/thread/*.c - ${SDL3_SOURCE_DIR}/src/timer/*.c - ${SDL3_SOURCE_DIR}/src/video/*.c - ${SDL3_SOURCE_DIR}/src/video/yuv2rgb/*.c) +sdl_glob_sources( + "${SDL3_SOURCE_DIR}/src/*.c" + "${SDL3_SOURCE_DIR}/src/atomic/*.c" + "${SDL3_SOURCE_DIR}/src/audio/*.c" + "${SDL3_SOURCE_DIR}/src/core/*.c" + "${SDL3_SOURCE_DIR}/src/cpuinfo/*.c" + "${SDL3_SOURCE_DIR}/src/dynapi/*.c" + "${SDL3_SOURCE_DIR}/src/events/*.c" + "${SDL3_SOURCE_DIR}/src/file/*.c" + "${SDL3_SOURCE_DIR}/src/joystick/*.c" + "${SDL3_SOURCE_DIR}/src/haptic/*.c" + "${SDL3_SOURCE_DIR}/src/hidapi/*.c" + "${SDL3_SOURCE_DIR}/src/libm/*.c" + "${SDL3_SOURCE_DIR}/src/locale/*.c" + "${SDL3_SOURCE_DIR}/src/misc/*.c" + "${SDL3_SOURCE_DIR}/src/power/*.c" + "${SDL3_SOURCE_DIR}/src/render/*.c" + "${SDL3_SOURCE_DIR}/src/render/*/*.c" + "${SDL3_SOURCE_DIR}/src/sensor/*.c" + "${SDL3_SOURCE_DIR}/src/stdlib/*.c" + "${SDL3_SOURCE_DIR}/src/thread/*.c" + "${SDL3_SOURCE_DIR}/src/timer/*.c" + "${SDL3_SOURCE_DIR}/src/video/*.c" + "${SDL3_SOURCE_DIR}/src/video/yuv2rgb/*.c" +) if(USE_INTELCC) # warning #39: division by zero @@ -535,83 +511,20 @@ elseif(SDL_ASSERTIONS MATCHES "^(enabled|2)$") elseif(SDL_ASSERTIONS MATCHES "^(paranoid|3)$") set(SDL_DEFAULT_ASSERT_LEVEL 3) else() - message_error("unknown assertion level") + message(FATAL_ERROR "unknown assertion level") endif() set(HAVE_ASSERTIONS ${SDL_ASSERTIONS}) if(NOT SDL_BACKGROUNDING_SIGNAL STREQUAL "OFF") - target_compile_definitions(sdl-build-options INTERFACE "SDL_BACKGROUNDING_SIGNAL=${SDL_BACKGROUNDING_SIGNAL}") + sdl_compile_definitions(PRIVATE "SDL_BACKGROUNDING_SIGNAL=${SDL_BACKGROUNDING_SIGNAL}") endif() if(NOT SDL_FOREGROUNDING_SIGNAL STREQUAL "OFF") - target_compile_definitions(sdl-build-options INTERFACE "SDL_FOREGROUNDING_SIGNAL=${SDL_FOREGROUNDING_SIGNAL}") + sdl_compile_definitions(PRIVATE "SDL_FOREGROUNDING_SIGNAL=${SDL_FOREGROUNDING_SIGNAL}") endif() # Compiler option evaluation if(USE_GCC OR USE_CLANG OR USE_INTELCC OR USE_QCC) - # Check for -Wall first, so later things can override pieces of it. - # Note: clang-cl treats -Wall as -Weverything (which is very loud), - # /W3 as -Wall, and /W4 as -Wall -Wextra. So: /W3 is enough. - check_c_compiler_flag(-Wall HAVE_GCC_WALL) - if(MSVC_CLANG) - target_compile_options(sdl-global-options INTERFACE "/W3") - elseif(HAVE_GCC_WALL) - target_compile_options(sdl-global-options INTERFACE "-Wall") - if(HAIKU) - target_compile_options(sdl-global-options INTERFACE "-Wno-multichar") - endif() - endif() - - check_c_compiler_flag(-Wundef HAVE_GCC_WUNDEF) - if(HAVE_GCC_WUNDEF) - target_compile_options(sdl-global-options INTERFACE "-Wundef") - endif() - - check_c_compiler_flag(-fno-strict-aliasing HAVE_GCC_NO_STRICT_ALIASING) - if(HAVE_GCC_NO_STRICT_ALIASING) - target_compile_options(sdl-global-options INTERFACE "-fno-strict-aliasing") - endif() - - check_c_compiler_flag(-Wdocumentation HAVE_GCC_WDOCUMENTATION) - if(HAVE_GCC_WDOCUMENTATION) - if(SDL_WERROR) - check_c_compiler_flag(-Werror=documentation HAVE_GCC_WERROR_DOCUMENTATION) - if(HAVE_GCC_WERROR_DOCUMENTATION) - target_compile_options(sdl-global-options INTERFACE "-Werror=documentation") - endif() - endif() - target_compile_options(sdl-global-options INTERFACE "-Wdocumentation") - endif() - - check_c_compiler_flag(-Wdocumentation-unknown-command HAVE_GCC_WDOCUMENTATION_UNKNOWN_COMMAND) - if(HAVE_GCC_WDOCUMENTATION_UNKNOWN_COMMAND) - if(SDL_WERROR) - check_c_compiler_flag(-Werror=documentation-unknown-command HAVE_GCC_WERROR_DOCUMENTATION_UNKNOWN_COMMAND) - if(HAVE_GCC_WERROR_DOCUMENTATION_UNKNOWN_COMMAND) - target_compile_options(sdl-global-options INTERFACE "-Werror=documentation-unknown-command") - endif() - endif() - target_compile_options(sdl-global-options INTERFACE "-Wdocumentation-unknown-command") - endif() - - check_c_compiler_flag(-fcomment-block-commands=threadsafety HAVE_GCC_COMMENT_BLOCK_COMMANDS) - if(HAVE_GCC_COMMENT_BLOCK_COMMANDS) - target_compile_options(sdl-global-options INTERFACE "-fcomment-block-commands=threadsafety") - else() - check_c_compiler_flag(/clang:-fcomment-block-commands=threadsafety HAVE_CLANG_COMMENT_BLOCK_COMMANDS) - if(HAVE_CLANG_COMMENT_BLOCK_COMMANDS) - target_compile_options(sdl-global-options INTERFACE "/clang:-fcomment-block-commands=threadsafety") - endif() - endif() - - if(DEPENDENCY_TRACKING) - check_c_source_compiles(" - #if !defined(__GNUC__) || __GNUC__ < 3 - #error Dependency tracking requires GCC 3.0 or newer - #endif - int main(int argc, char **argv) { return 0; }" HAVE_DEPENDENCY_TRACKING) - endif() - if(SDL_GCC_ATOMICS) check_c_source_compiles("int main(int argc, char **argv) { int a; @@ -634,7 +547,7 @@ if(USE_GCC OR USE_CLANG OR USE_INTELCC OR USE_QCC) endif() cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -fvisibility=hidden -Werror") + string(APPEND CMAKE_REQUIRED_FLAGS " -fvisibility=hidden -Werror") check_c_source_compiles(" #if !defined(__GNUC__) || __GNUC__ < 4 #error SDL only uses visibility attributes in GCC 4 or newer @@ -646,74 +559,48 @@ if(USE_GCC OR USE_CLANG OR USE_INTELCC OR USE_QCC) int main(void) { return 0; }" HAVE_GCC_FVISIBILITY) cmake_pop_check_state() - check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW) - if(HAVE_GCC_WSHADOW) - target_compile_options(sdl-global-options INTERFACE "-Wshadow") - endif() - - check_c_compiler_flag(-Wunused-local-typedefs HAVE_GCC_WUNUSED_LOCAL_TYPEDEFS) - if(HAVE_GCC_WUNUSED_LOCAL_TYPEDEFS) - target_compile_options(sdl-global-options INTERFACE "-Wno-unused-local-typedefs") + if(APPLE) + # FIXME: don't use deprecated declarations + check_c_compiler_flag(-Wno-error=deprecated-declarations COMPILER_SUPPORTS_WNO_ERROR_DEPRECATED_DECLARATIONS) + if(COMPILER_SUPPORTS_WNO_ERROR_DEPRECATED_DECLARATIONS) + sdl_compile_options(PRIVATE "-Wno-error=deprecated-declarations") + endif() endif() if(APPLE) - cmake_push_check_state() - # FIXME: don't use deprecated declarations - check_c_compiler_flag(-Wno-error=deprecated-declarations HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS) - if(HAVE_WNO_ERROR_DEPRECATED_DECLARATIONS) - target_compile_options(sdl-build-options INTERFACE "-Wno-error=deprecated-declarations") - endif() - cmake_pop_check_state() - - if(CMAKE_VERSION VERSION_LESS "3.6") - target_link_libraries(sdl-shared-build-options INTERFACE "-Wl,-compatibility_version,${SDL_DYLIB_COMPAT_VERSION}") - target_link_libraries(sdl-shared-build-options INTERFACE "-Wl,-current_version,${SDL_DYLIB_CURRENT_VERSION}") + check_linker_flag(C "-Wl,-undefined,error" LINKER_SUPPORTS_WL_UNDEFINED_ERROR) + if(LINKER_SUPPORTS_WL_UNDEFINED_ERROR) + sdl_shared_link_options("-Wl,-undefined,error") endif() elseif(NOT OPENBSD) cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wl,--no-undefined") - check_c_compiler_flag("" HAVE_NO_UNDEFINED) - cmake_pop_check_state() - if(HAVE_NO_UNDEFINED AND NOT (USE_CLANG AND WINDOWS)) - target_link_libraries(sdl-shared-build-options INTERFACE "-Wl,--no-undefined") - endif() - endif() - - if(MINGW) - # See if GCC's -gdwarf-4 is supported - # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101377 for why this is needed on Windows - cmake_push_check_state() - check_c_compiler_flag("-gdwarf-4" HAVE_GDWARF_4) - if(HAVE_GDWARF_4) - target_compile_options(sdl-global-options INTERFACE "-gdwarf-4") - endif() - cmake_pop_check_state() - endif() - - # Force color diagnostics when one of these conditions are met - if(DEFINED ENV{CI} OR DEFINED ENV{USE_CCACHE} OR CMAKE_GENERATOR MATCHES Ninja) - if(EMSCRIPTEN OR (USE_GCC AND NOT CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9)) - target_compile_options(sdl-global-options INTERFACE -fdiagnostics-color=always) - elseif(USE_CLANG AND NOT CMAKE_C_COMPILER_ID MATCHES AppleClang) - target_compile_options(sdl-global-options INTERFACE -fcolor-diagnostics) + check_linker_flag(C "-Wl,--no-undefined" LINKER_SUPPORTS_WL_NO_UNDEFINED) + #FIXME: originally this if had an additional "AND NOT (USE_CLANG AND WINDOWS)" + if(LINKER_SUPPORTS_WL_NO_UNDEFINED) + sdl_shared_link_options("-Wl,--no-undefined") endif() endif() endif() -if(MSVC) - target_compile_definitions(sdl-build-options INTERFACE "_CRT_SECURE_NO_DEPRECATE") - target_compile_definitions(sdl-build-options INTERFACE "_CRT_NONSTDC_NO_DEPRECATE") - target_compile_definitions(sdl-build-options INTERFACE "_CRT_SECURE_NO_WARNINGS") - # CET support was added in VS 16.7 +if(MSVC) + sdl_compile_definitions( + PRIVATE + "_CRT_SECURE_NO_DEPRECATE" + "_CRT_NONSTDC_NO_DEPRECATE" + "_CRT_SECURE_NO_WARNINGS" + ) + + # CET support was added in VS 2019 16.7 if(MSVC_VERSION GREATER 1926 AND CMAKE_GENERATOR_PLATFORM MATCHES "Win32|x64") - target_link_libraries(sdl-shared-build-options INTERFACE "-CETCOMPAT") + # Mark SDL3.dll as compatible with Control-flow Enforcement Technology (CET) + sdl_shared_link_options("-CETCOMPAT") endif() endif() if(CMAKE_C_COMPILER_ID STREQUAL "MSVC") # Due to a limitation of Microsoft's LTO implementation, LTO must be disabled for memcpy and memset. # The same applies to various functions normally belonging in the C library (for x86 architecture). - set_property(SOURCE src/stdlib/SDL_mslibc.c APPEND_STRING PROPERTY COMPILE_FLAGS " /GL-") + set_property(SOURCE "${SDL3_SOURCE_DIR}/src/stdlib/SDL_mslibc.c" APPEND_STRING PROPERTY COMPILE_FLAGS " /GL-") endif() if(SDL_ASSEMBLY) @@ -722,7 +609,7 @@ if(SDL_ASSEMBLY) if(SDL_MMX) cmake_push_check_state() if(USE_GCC OR USE_CLANG OR USE_INTELCC) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mmmx") + string(APPEND CMAKE_REQUIRED_FLAGS " -mmmx") endif() check_c_source_compiles(" #include @@ -743,7 +630,7 @@ if(SDL_ASSEMBLY) if(SDL_SSE) cmake_push_check_state() if(USE_GCC OR USE_CLANG OR USE_INTELCC) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -msse") + string(APPEND CMAKE_REQUIRED_FLAGS " -msse") endif() check_c_source_compiles(" #include @@ -764,7 +651,7 @@ if(SDL_ASSEMBLY) if(SDL_SSE2) cmake_push_check_state() if(USE_GCC OR USE_CLANG OR USE_INTELCC) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -msse2") + string(APPEND CMAKE_REQUIRED_FLAGS " -msse2") endif() check_c_source_compiles(" #include @@ -785,7 +672,7 @@ if(SDL_ASSEMBLY) if(SDL_SSE3) cmake_push_check_state() if(USE_GCC OR USE_CLANG OR USE_INTELCC) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -msse3") + string(APPEND CMAKE_REQUIRED_FLAGS " -msse3") endif() check_c_source_compiles(" #include @@ -806,7 +693,7 @@ if(SDL_ASSEMBLY) if(SDL_SSE4_1) cmake_push_check_state() if(USE_GCC OR USE_CLANG OR USE_INTELCC) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -msse4.1") + string(APPEND CMAKE_REQUIRED_FLAGS " -msse4.1") endif() check_c_source_compiles(" #include @@ -827,7 +714,7 @@ if(SDL_ASSEMBLY) if(SDL_SSE4_2) cmake_push_check_state() if(USE_GCC OR USE_CLANG OR USE_INTELCC) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -msse4.2") + string(APPEND CMAKE_REQUIRED_FLAGS " -msse4.2") endif() check_c_source_compiles(" #include @@ -850,7 +737,7 @@ if(SDL_ASSEMBLY) if(SDL_AVX) cmake_push_check_state() if(USE_GCC OR USE_CLANG OR USE_INTELCC) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mavx") + string(APPEND CMAKE_REQUIRED_FLAGS " -mavx") endif() check_c_source_compiles(" #include @@ -871,7 +758,7 @@ if(SDL_ASSEMBLY) if(SDL_AVX2) cmake_push_check_state() if(USE_GCC OR USE_CLANG OR USE_INTELCC) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mavx2") + string(APPEND CMAKE_REQUIRED_FLAGS " -mavx2") endif() check_c_source_compiles(" #include @@ -892,7 +779,7 @@ if(SDL_ASSEMBLY) if(SDL_AVX512F) cmake_push_check_state() if(USE_GCC OR USE_CLANG OR USE_INTELCC) - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mavx512f") + string(APPEND CMAKE_REQUIRED_FLAGS " -mavx512f") endif() check_c_source_compiles(" #include @@ -917,7 +804,7 @@ if(SDL_ASSEMBLY) if(SDL_ALTIVEC) cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -maltivec") + string(APPEND CMAKE_REQUIRED_FLAGS " -maltivec") check_c_source_compiles(" #include vector unsigned int vzero() { @@ -928,7 +815,7 @@ if(SDL_ASSEMBLY) if(COMPILER_SUPPORTS_ALTIVEC) set(HAVE_ALTIVEC TRUE) set(SDL_ALTIVEC_BLITTERS 1) - target_compile_options(sdl-build-options INTERFACE "-maltivec") + sdl_compile_options(PRIVATE "-maltivec") set_property(SOURCE "${SDL3_SOURCE_DIR}/src/video/SDL_blit_N.c" APPEND PROPERTY COMPILE_DEFINITIONS "SDL_ENABLE_ALTIVEC") set_property(SOURCE "${SDL3_SOURCE_DIR}/src/video/SDL_blit_N.c" PROPERTY SKIP_PRECOMPILE_HEADERS 1) endif() @@ -936,7 +823,7 @@ if(SDL_ASSEMBLY) if(SDL_LSX) cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mlsx") + string(APPEND CMAKE_REQUIRED_FLAGS " -mlsx") check_c_source_compiles(" #ifndef __loongarch_sx #error Assembler CPP flag not enabled @@ -952,7 +839,7 @@ if(SDL_ASSEMBLY) if(SDL_LASX) cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -mlasx") + string(APPEND CMAKE_REQUIRED_FLAGS " -mlasx") check_c_source_compiles(" #ifndef __loongarch_asx #error Assembler CPP flag not enabled @@ -967,7 +854,7 @@ if(SDL_ASSEMBLY) if(SDL_ARMSIMD) cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -x assembler-with-cpp") + string(APPEND CMAKE_REQUIRED_FLAGS " -x assembler-with-cpp") list(APPEND CMAKE_REQUIRED_LINK_OPTIONS -x none) check_c_source_compiles(" .text @@ -989,8 +876,7 @@ if(SDL_ASSEMBLY) set(HAVE_ARMSIMD TRUE) set(SDL_ARM_SIMD_BLITTERS 1) enable_language(ASM) - file(GLOB ARMSIMD_SOURCES ${SDL3_SOURCE_DIR}/src/video/arm/pixman-arm-simd*.S) - list(APPEND SOURCE_FILES ${ARMSIMD_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/arm/pixman-arm-simd*.S") set_property(SOURCE ${ARMSIMD_SOURCES} APPEND PROPERTY COMPILE_OPTIONS -x assembler-with-cpp) set(WARN_ABOUT_ARM_SIMD_ASM_MIT TRUE) endif() @@ -998,7 +884,7 @@ if(SDL_ASSEMBLY) if(SDL_ARMNEON_BLITTERS) cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -x assembler-with-cpp") + string(APPEND CMAKE_REQUIRED_FLAGS " -x assembler-with-cpp") list(APPEND CMAKE_REQUIRED_LINK_OPTIONS -x none) check_c_source_compiles(" .text @@ -1021,8 +907,7 @@ if(SDL_ASSEMBLY) set(HAVE_ARMNEON_BLITTERS TRUE) set(SDL_ARM_NEON_BLITTERS 1) enable_language(ASM) - file(GLOB ARMNEON_SOURCES ${SDL3_SOURCE_DIR}/src/video/arm/pixman-arm-neon*.S) - list(APPEND SOURCE_FILES ${ARMNEON_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/arm/pixman-arm-neon*.S") set_property(SOURCE ${ARMNEON_SOURCES} APPEND PROPERTY COMPILE_OPTIONS -x assembler-with-cpp) set(WARN_ABOUT_ARM_NEON_ASM_MIT TRUE) endif() @@ -1096,107 +981,113 @@ if(NOT HAVE_ARMNEON) set(SDL_DISABLE_NEON 1) endif() -# TODO: Can't deactivate on FreeBSD? w/o LIBC, SDL_stdinc.h can't define -# anything. +# TODO: Can't deactivate on FreeBSD? w/o LIBC, SDL_stdinc.h can't define anything. if(SDL_LIBC) - if(WINDOWS AND NOT MINGW) - set(HAVE_LIBC TRUE) - check_include_file(stdint.h HAVE_STDINT_H) - foreach(_HEADER stdio.h string.h wchar.h ctype.h math.h limits.h) - string(TOUPPER "HAVE_${_HEADER}" _UPPER) - string(REPLACE "." "_" _HAVE_H ${_UPPER}) - set(${_HAVE_H} 1) - endforeach() - set(HAVE_SIGNAL_H 1) - foreach(_FN abs acos acosf asin asinf atan atan2 atan2f atanf atof atoi bsearch calloc ceil ceilf copysign copysignf cos cosf exp expf fabs fabsf floor floorf fmod fmodf free itoa log log10 log10f logf lround lroundf _ltoa malloc memcmp memcpy memmove memset modf modff pow powf qsort realloc round roundf scalbn scalbnf sin sinf sqrt sqrtf sscanf strchr strcmp _stricmp strlen strnlen _strlwr strncmp _strnicmp strrchr _strrev strstr strtod strtol strtoll strtoul _strupr tan tanf trunc truncf _ultoa wcscmp _wcsdup wcsdup _wcsicmp wcslen wcsnlen wcsncmp _wcsnicmp wcsstr wcstol) - string(TOUPPER ${_FN} _UPPER) - set(HAVE_${_UPPER} 1) - endforeach() - set(HAVE_ALLOCA 1) - else() - set(HAVE_LIBC TRUE) - set(headers_to_check - ctype.h - float.h - iconv.h - inttypes.h - limits.h - malloc.h - math.h - memory.h - signal.h - stdarg.h - stddef.h - stdint.h - stdio.h - stdlib.h - string.h - strings.h - sys/types.h - wchar.h - ) - if(NOT EMSCRIPTEN) - list(APPEND headers_to_check libunwind.h) + set(available_headers) + set(HAVE_LIBC TRUE) + set(headers_to_check + alloca.h + ctype.h + float.h + iconv.h + inttypes.h + limits.h + malloc.h + math.h + memory.h + signal.h + stdarg.h + stddef.h + stdint.h + stdio.h + stdlib.h + string.h + strings.h + sys/types.h + wchar.h + ) + foreach(_HEADER IN LISTS headers_to_check) + string(TOUPPER "${_HEADER}" HEADER_IDENTIFIER) + string(REGEX REPLACE "[./]" "_" HEADER_IDENTIFIER "${HEADER_IDENTIFIER}") + set(LIBC_HAS_VAR "LIBC_HAS_${HEADER_IDENTIFIER}") + check_include_file("${_HEADER}" "${LIBC_HAS_VAR}") + set(HAVE_${HEADER_IDENTIFIER} ${${LIBC_HAS_VAR}}) + if(HAVE_${HEADER_IDENTIFIER}) + list(APPEND available_headers "${_HEADER}") endif() - foreach(_HEADER ${headers_to_check}) - string(TOUPPER "${_HEADER}" HEADER_IDENTIFIER) - string(REGEX REPLACE "[./]" "_" HEADER_IDENTIFIER "${HEADER_IDENTIFIER}") - set(LIBC_HAS_VAR "LIBC_HAS_${HEADER_IDENTIFIER}") - check_include_file("${_HEADER}" "${LIBC_HAS_VAR}") - set(HAVE_${HEADER_IDENTIFIER} ${${LIBC_HAS_VAR}}) - endforeach() + endforeach() + + set(symbols_to_check + abs acos acosf alloca asin asinf atan atan2 atan2f atanf atof atoi + bcopy bsearch + calloc ceil ceilf copysign copysignf cos cosf + _Exit exp expf + fabs fabsf floor floorf fmod fmodf fopen64 free fseeko fseeko64 + getenv + _i64toa index itoa + log log10 log10f logf lround lroundf _ltoa + malloc memcmp memcpy memmove memset modf modff + pow powf putenv + qsort + realloc rindex round roundf + scalbn scalbnf setenv sin sinf sqr sqrt sqrtf sscanf strchr + strcmp strlcat strlcpy strlen strncmp strnlen + strrchr strstr strtod strtok_r strtol strtoll strtoul strtoull + tan tanf trunc truncf + unsetenv + vsnprintf vsscanf + wcsnlen wcscmp wcsdup wcslcat wcslcpy wcslen wcsncmp wcsstr wcstol + ) + if(WINDOWS) + list(APPEND symbols_to_check + _stricmp _strlwr _strnicmp _strrev _strupr _ui64toa _uitoa _ultoa _wcsdup _wcsicmp _wcsnicmp + ) + else() + list(APPEND symbols_to_check + strcasecmp strcasestr strncasecmp wcscasecmp wcsncasecmp + ) + endif() + check_library_exists(m pow "" HAVE_LIBM) + cmake_push_check_state() + if(HAVE_LIBM) + sdl_link_dependency(math LIBS m) + list(APPEND CMAKE_REQUIRED_LIBRARIES m) + endif() + foreach(_FN IN LISTS symbols_to_check) + string(TOUPPER ${_FN} _UPPER) + set(LIBC_HAS_VAR "LIBC_HAS_${_UPPER}") + check_symbol_exists("${_FN}" "${available_headers}" ${LIBC_HAS_VAR}) + set(HAVE_${_UPPER} ${${LIBC_HAS_VAR}}) + endforeach() + cmake_pop_check_state() + + if(NOT WINDOWS) check_include_file(linux/input.h HAVE_LINUX_INPUT_H) - set(STDC_HEADER_NAMES "stddef.h;stdarg.h;stdlib.h;string.h;stdio.h;wchar.h;float.h") - # TODO: refine the mprotect check - check_c_source_compiles("#include - #include - int main(void) { return 0; }" HAVE_MPROTECT) - foreach(_FN abs atof atoi bcopy bsearch calloc _Exit fopen64 free fseeko fseeko64 getenv _i64toa index itoa _ltoa malloc memcmp memcpy memmove memset putenv qsort realloc rindex setenv sscanf strcasecmp strcasestr strchr strcmp _stricmp strlcat strlcpy strlen strnlen _strlwr strncasecmp strncmp _strnicmp strrchr _strrev strstr strtod strtok_r strtol strtoll strtoul strtoull _strupr _ui64toa _uitoa _ultoa unsetenv vsnprintf vsscanf wcscasecmp wcscmp _wcsdup wcsdup _wcsicmp wcslcat wcslcpy wcslen wcsnlen wcsncasecmp wcsncmp _wcsnicmp wcsstr wcstol) - string(TOUPPER ${_FN} _UPPER) - set(LIBC_HAS_VAR "LIBC_HAS_${_UPPER}") - check_symbol_exists("${_FN}" "${STDC_HEADER_NAMES}" ${LIBC_HAS_VAR}) - set(HAVE_${_UPPER} ${${LIBC_HAS_VAR}}) - endforeach() - + check_symbol_exists(getpagesize "unistd.h" HAVE_GETPAGESIZE) check_symbol_exists(sigaction "signal.h" HAVE_SIGACTION) check_symbol_exists(setjmp "setjmp.h" HAVE_SETJMP) - check_symbol_exists(nanosleep "time.h" FOUND_NANOSLEEP) - set(HAVE_NANOSLEEP ${FOUND_NANOSLEEP}) + check_symbol_exists(nanosleep "time.h" HAVE_NANOSLEEP) check_symbol_exists(sysconf "unistd.h" HAVE_SYSCONF) check_symbol_exists(sysctlbyname "sys/types.h;sys/sysctl.h" HAVE_SYSCTLBYNAME) check_symbol_exists(getauxval "sys/auxv.h" HAVE_GETAUXVAL) check_symbol_exists(elf_aux_info "sys/auxv.h" HAVE_ELF_AUX_INFO) check_symbol_exists(poll "poll.h" HAVE_POLL) - check_library_exists(m pow "" HAVE_LIBM) - if(HAVE_LIBM) - cmake_push_check_state() - list(APPEND CMAKE_REQUIRED_LIBRARIES m) - endif() - foreach(_FN - atan atan2 atanf atan2f ceil ceilf copysign copysignf cos cosf - exp expf fabs fabsf floor floorf fmod fmodf log logf log10 log10f - lround lroundf modf modff pow powf round roundf scalbn scalbnf - sin sinf sqrt sqrtf tan tanf acos acosf asin asinf trunc truncf) - string(TOUPPER ${_FN} _UPPER) - set(LIBC_HASVAR "LIBC_HAS_${_UPPER}") - check_symbol_exists("${_FN}" "math.h" ${LIBC_HASVAR}) - set(HAVE_${_UPPER} ${${LIBC_HASVAR}}) - endforeach() - if(HAVE_LIBM) - cmake_pop_check_state() - if(NOT VITA) - list(APPEND SDL_EXTRA_LIBS m) - endif() - endif() - if(SDL_SYSTEM_ICONV) check_library_exists(iconv iconv_open "" HAVE_LIBICONV) if(HAVE_LIBICONV) - list(APPEND SDL_EXTRA_LIBS iconv) - set(HAVE_ICONV 1) - set(HAVE_SYSTEM_ICONV TRUE) + find_package(Iconv) + if(Iconv_FOUND AND NOT Iconv_IS_BUILT_IN) + set(HAVE_ICONV 1) + set(HAVE_SYSTEM_ICONV TRUE) + pkg_check_modules(PC_ICONV iconv) + if(PC_ICONV_FOUND) + sdl_link_dependency(iconv LIBS Iconv::Iconv CMAKE_MODULE Iconv PKG_CONFIG_SPECS iconv) + else() + sdl_link_dependency(iconv LIBS Iconv::Iconv CMAKE_MODULE Iconv PKG_CONFIG_LIBS iconv) + endif() + endif() else() check_library_exists(c iconv_open "" HAVE_BUILTIN_ICONV) if(HAVE_BUILTIN_ICONV) @@ -1206,19 +1097,6 @@ if(SDL_LIBC) endif() endif() - if(NOT APPLE) - check_include_file(alloca.h HAVE_ALLOCA_H) - check_symbol_exists(alloca "alloca.h" HAVE_ALLOCA1) - check_symbol_exists(alloca "stdlib.h" HAVE_ALLOCA2) - check_symbol_exists(alloca "malloc.h" HAVE_ALLOCA3) - if(HAVE_ALLOCA1 OR HAVE_ALLOCA2 OR HAVE_ALLOCA3) - set(HAVE_ALLOCA 1) - endif() - else() - set(HAVE_ALLOCA_H 1) - set(HAVE_ALLOCA 1) - endif() - check_struct_has_member("struct sigaction" "sa_sigaction" "signal.h" HAVE_SA_SIGACTION) endif() else() @@ -1236,7 +1114,7 @@ else() endforeach() if(MSVC AND USE_CLANG) - check_c_compiler_flag("/Q_no-use-libirc" HAS_Q_NO_USE_LIBIRC ) + check_c_compiler_flag("/Q_no-use-libirc" HAS_Q_NO_USE_LIBIRC) endif() endif() @@ -1251,7 +1129,7 @@ endforeach() if(SDL_HAPTIC) if(NOT SDL_JOYSTICK) # Haptic requires some private functions from the joystick subsystem. - message_error("SDL_HAPTIC requires SDL_JOYSTICK, which is not enabled") + message(FATAL_ERROR "SDL_HAPTIC requires SDL_JOYSTICK, which is not enabled") endif() endif() @@ -1261,15 +1139,13 @@ if(SDL_AUDIO) # CheckDummyAudio/CheckDiskAudio - valid for all platforms if(SDL_DUMMYAUDIO) set(SDL_AUDIO_DRIVER_DUMMY 1) - file(GLOB DUMMYAUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/dummy/*.c) - list(APPEND SOURCE_FILES ${DUMMYAUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/dummy/*.c") set(HAVE_DUMMYAUDIO TRUE) set(HAVE_SDL_AUDIO TRUE) endif() if(SDL_DISKAUDIO) set(SDL_AUDIO_DRIVER_DISK 1) - file(GLOB DISKAUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/disk/*.c) - list(APPEND SOURCE_FILES ${DISKAUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/disk/*.c") set(HAVE_DISKAUDIO TRUE) set(HAVE_SDL_AUDIO TRUE) endif() @@ -1281,8 +1157,7 @@ if(UNIX OR APPLE) CheckDLOPEN() if(SDL_LOADSO AND HAVE_DLOPEN) set(SDL_LOADSO_DLOPEN 1) - file(GLOB DLOPEN_SOURCES ${SDL3_SOURCE_DIR}/src/loadso/dlopen/*.c) - list(APPEND SOURCE_FILES ${DLOPEN_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/loadso/dlopen/*.c") set(HAVE_SDL_LOADSO TRUE) endif() endif() @@ -1295,16 +1170,14 @@ if(SDL_JOYSTICK) if(SDL_VIRTUAL_JOYSTICK) set(HAVE_VIRTUAL_JOYSTICK TRUE) set(SDL_JOYSTICK_VIRTUAL 1) - file(GLOB JOYSTICK_VIRTUAL_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/virtual/*.c) - list(APPEND SOURCE_FILES ${JOYSTICK_VIRTUAL_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/virtual/*.c") endif() endif() if(SDL_VIDEO) if(SDL_DUMMYVIDEO) set(SDL_VIDEO_DRIVER_DUMMY 1) - file(GLOB VIDEO_DUMMY_SOURCES ${SDL3_SOURCE_DIR}/src/video/dummy/*.c) - list(APPEND SOURCE_FILES ${VIDEO_DUMMY_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/dummy/*.c") set(HAVE_DUMMYVIDEO TRUE) set(HAVE_SDL_VIDEO TRUE) endif() @@ -1314,13 +1187,12 @@ endif() if(ANDROID) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/cmake/android") - file(GLOB ANDROID_CORE_SOURCES ${SDL3_SOURCE_DIR}/src/core/android/*.c) - list(APPEND SOURCE_FILES ${ANDROID_CORE_SOURCES} ${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/core/android/*.c") + sdl_sources("${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c") set_property(SOURCE "${ANDROID_NDK}/sources/android/cpufeatures/cpu-features.c" APPEND_STRING PROPERTY COMPILE_FLAGS " -Wno-declaration-after-statement") if(SDL_MISC) - file(GLOB ANDROID_MISC_SOURCES ${SDL3_SOURCE_DIR}/src/misc/android/*.c) - list(APPEND SOURCE_FILES ${ANDROID_MISC_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/misc/android/*.c") set(HAVE_SDL_MISC TRUE) endif() @@ -1329,7 +1201,7 @@ if(ANDROID) # see: https://issuetracker.google.com/issues/62264618 # Another option would be to set ARM mode to all compiled files cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unused-command-line-argument") + string(APPEND CMAKE_REQUIRED_FLAGS " -Werror=unused-command-line-argument") check_c_compiler_flag(-marm HAVE_ARM_MODE) cmake_pop_check_state() if(HAVE_ARM_MODE) @@ -1339,31 +1211,26 @@ if(ANDROID) if(SDL_AUDIO) set(SDL_AUDIO_DRIVER_ANDROID 1) - file(GLOB ANDROID_AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/android/*.c) - list(APPEND SOURCE_FILES ${ANDROID_AUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/android/*.c") set(SDL_AUDIO_DRIVER_OPENSLES 1) - file(GLOB OPENSLES_AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/openslES/*.c) - list(APPEND SOURCE_FILES ${OPENSLES_AUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/openslES/*.c") - list(APPEND SDL_EXTRA_LIBS ${ANDROID_DL_LIBRARY} OpenSLES) + sdl_link_dependency(opensles LIBS ${ANDROID_DL_LIBRARY} OpenSLES) set(SDL_AUDIO_DRIVER_AAUDIO 1) - file(GLOB AAUDIO_AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/aaudio/*.c) - list(APPEND SOURCE_FILES ${AAUDIO_AUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/aaudio/*.c") set(HAVE_SDL_AUDIO TRUE) endif() if(SDL_FILESYSTEM) set(SDL_FILESYSTEM_ANDROID 1) - file(GLOB ANDROID_FILESYSTEM_SOURCES ${SDL3_SOURCE_DIR}/src/filesystem/android/*.c) - list(APPEND SOURCE_FILES ${ANDROID_FILESYSTEM_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/filesystem/android/*.c") set(HAVE_SDL_FILESYSTEM TRUE) endif() if(SDL_HAPTIC) set(SDL_HAPTIC_ANDROID 1) - file(GLOB ANDROID_HAPTIC_SOURCES ${SDL3_SOURCE_DIR}/src/haptic/android/*.c) - list(APPEND SOURCE_FILES ${ANDROID_HAPTIC_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/haptic/android/*.c") set(HAVE_SDL_HAPTIC TRUE) endif() if(SDL_HIDAPI) @@ -1371,50 +1238,46 @@ if(ANDROID) endif() if(SDL_JOYSTICK) set(SDL_JOYSTICK_ANDROID 1) - file(GLOB ANDROID_JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/android/*.c ${SDL3_SOURCE_DIR}/src/joystick/steam/*.c) - list(APPEND SOURCE_FILES ${ANDROID_JOYSTICK_SOURCES}) + sdl_glob_sources( + "${SDL3_SOURCE_DIR}/src/joystick/android/*.c" + "${SDL3_SOURCE_DIR}/src/joystick/steam/*.c" + ) set(HAVE_SDL_JOYSTICK TRUE) endif() if(SDL_LOADSO) set(SDL_LOADSO_DLOPEN 1) - file(GLOB LOADSO_SOURCES ${SDL3_SOURCE_DIR}/src/loadso/dlopen/*.c) - list(APPEND SOURCE_FILES ${LOADSO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/loadso/dlopen/*.c") set(HAVE_SDL_LOADSO TRUE) endif() if(SDL_POWER) set(SDL_POWER_ANDROID 1) - file(GLOB ANDROID_POWER_SOURCES ${SDL3_SOURCE_DIR}/src/power/android/*.c) - list(APPEND SOURCE_FILES ${ANDROID_POWER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/power/android/*.c") set(HAVE_SDL_POWER TRUE) endif() if(SDL_LOCALE) - file(GLOB ANDROID_LOCALE_SOURCES ${SDL3_SOURCE_DIR}/src/locale/android/*.c) - list(APPEND SOURCE_FILES ${ANDROID_LOCALE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/locale/android/*.c") set(HAVE_SDL_LOCALE TRUE) endif() if(SDL_TIMERS) set(SDL_TIMER_UNIX 1) - file(GLOB TIMER_SOURCES ${SDL3_SOURCE_DIR}/src/timer/unix/*.c) - list(APPEND SOURCE_FILES ${TIMER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/unix/*.c") set(HAVE_SDL_TIMERS TRUE) endif() if(SDL_SENSOR) set(SDL_SENSOR_ANDROID 1) set(HAVE_SDL_SENSORS TRUE) - file(GLOB ANDROID_SENSOR_SOURCES ${SDL3_SOURCE_DIR}/src/sensor/android/*.c) - list(APPEND SOURCE_FILES ${ANDROID_SENSOR_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/sensor/android/*.c") endif() if(SDL_VIDEO) set(SDL_VIDEO_DRIVER_ANDROID 1) - file(GLOB ANDROID_VIDEO_SOURCES ${SDL3_SOURCE_DIR}/src/video/android/*.c) - list(APPEND SOURCE_FILES ${ANDROID_VIDEO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/android/*.c") set(HAVE_SDL_VIDEO TRUE) # Core stuff # find_library(ANDROID_DL_LIBRARY dl) # FIXME failing dlopen https://github.com/android-ndk/ndk/issues/929 - list(APPEND SDL_EXTRA_LIBS dl log android) - target_compile_definitions(sdl-build-options INTERFACE "GL_GLEXT_PROTOTYPES") + sdl_link_dependency(android_video LIBS dl log android) + sdl_compile_definitions(PRIVATE "GL_GLEXT_PROTOTYPES") #enable gles if(SDL_OPENGLES) @@ -1424,11 +1287,11 @@ if(ANDROID) set(SDL_VIDEO_OPENGL_ES2 1) set(SDL_VIDEO_RENDER_OGL_ES2 1) - list(APPEND SDL_EXTRA_LIBS GLESv1_CM GLESv2) + sdl_link_dependency(opengles LIBS GLESv1_CM GLESv2) endif() if(SDL_VULKAN) - CHECK_C_SOURCE_COMPILES(" + check_c_source_compiles(" #if defined(__ARM_ARCH) && __ARM_ARCH < 7 #error Vulkan doesn't work on this configuration #endif @@ -1493,46 +1356,39 @@ if(ANDROID) elseif(EMSCRIPTEN) # Hide noisy warnings that intend to aid mostly during initial stages of porting a new # project. Uncomment at will for verbose cross-compiling -I/../ path info. - target_compile_options(sdl-build-options INTERFACE "-Wno-warn-absolute-paths") + sdl_compile_options(PRIVATE "-Wno-warn-absolute-paths") if(SDL_MISC) - file(GLOB EMSRIPTEN_MISC_SOURCES ${SDL3_SOURCE_DIR}/src/misc/emscripten/*.c) - list(APPEND SOURCE_FILES ${EMSRIPTEN_MISC_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/misc/emscripten/*.c") set(HAVE_SDL_MISC TRUE) endif() if(SDL_AUDIO) set(SDL_AUDIO_DRIVER_EMSCRIPTEN 1) - file(GLOB EM_AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/emscripten/*.c) - list(APPEND SOURCE_FILES ${EM_AUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/emscripten/*.c") set(HAVE_SDL_AUDIO TRUE) endif() if(SDL_FILESYSTEM) set(SDL_FILESYSTEM_EMSCRIPTEN 1) - file(GLOB EM_FILESYSTEM_SOURCES ${SDL3_SOURCE_DIR}/src/filesystem/emscripten/*.c) - list(APPEND SOURCE_FILES ${EM_FILESYSTEM_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/filesystem/emscripten/*.c") set(HAVE_SDL_FILESYSTEM TRUE) endif() if(SDL_JOYSTICK) set(SDL_JOYSTICK_EMSCRIPTEN 1) - file(GLOB EM_JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/emscripten/*.c) - list(APPEND SOURCE_FILES ${EM_JOYSTICK_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/emscripten/*.c") set(HAVE_SDL_JOYSTICK TRUE) endif() if(SDL_POWER) set(SDL_POWER_EMSCRIPTEN 1) - file(GLOB EM_POWER_SOURCES ${SDL3_SOURCE_DIR}/src/power/emscripten/*.c) - list(APPEND SOURCE_FILES ${EM_POWER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/power/emscripten/*.c") set(HAVE_SDL_POWER TRUE) endif() if(SDL_LOCALE) - file(GLOB LOCALE_SOURCES ${SDL3_SOURCE_DIR}/src/locale/emscripten/*.c) - list(APPEND SOURCE_FILES ${LOCALE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/locale/emscripten/*.c") set(HAVE_SDL_LOCALE TRUE) endif() if(SDL_TIMERS) set(SDL_TIMER_UNIX 1) - file(GLOB TIMER_SOURCES ${SDL3_SOURCE_DIR}/src/timer/unix/*.c) - list(APPEND SOURCE_FILES ${TIMER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/unix/*.c") set(HAVE_SDL_TIMERS TRUE) if(SDL_CLOCK_GETTIME) @@ -1541,8 +1397,7 @@ elseif(EMSCRIPTEN) endif() if(SDL_VIDEO) set(SDL_VIDEO_DRIVER_EMSCRIPTEN 1) - file(GLOB EM_VIDEO_SOURCES ${SDL3_SOURCE_DIR}/src/video/emscripten/*.c) - list(APPEND SOURCE_FILES ${EM_VIDEO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/emscripten/*.c") set(HAVE_SDL_VIDEO TRUE) #enable gles @@ -1555,23 +1410,18 @@ elseif(EMSCRIPTEN) endif() CheckPTHREAD() - - if(HAVE_LIBUNWIND_H) - list(APPEND EXTRA_TEST_LIBS unwind) - endif() + CheckLibUnwind() elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) if(SDL_AUDIO) if(NETBSD) set(SDL_AUDIO_DRIVER_NETBSD 1) - file(GLOB NETBSD_AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/netbsd/*.c) - list(APPEND SOURCE_FILES ${NETBSD_AUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/netbsd/*.c") set(HAVE_SDL_AUDIO TRUE) elseif(QNX) set(SDL_AUDIO_DRIVER_QNX 1) - file(GLOB QNX_AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/qnx/*.c) - list(APPEND SOURCE_FILES ${QNX_AUDIO_SOURCES}) - list(APPEND SDL_EXTRA_LIBS asound) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/qnx/*.c") + sdl_link_dependency(asound LIBS asound) set(HAVE_SDL_AUDIO TRUE) endif() CheckOSS() @@ -1588,7 +1438,7 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) # Need to check for ROCKCHIP platform and get rid of "Can't window GBM/EGL surfaces on window creation." CheckROCKCHIP() CheckX11() - # Need to check for EGL first because KMSDRM and Wayland depends on it. + # Need to check for EGL first because KMSDRM and Wayland depend on it. CheckEGL() CheckKMSDRM() CheckGLX() @@ -1596,25 +1446,20 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) CheckOpenGLES() CheckWayland() CheckVivante() - # FIXME: implement CheckVulkan() - if(SDL_VULKAN) - set(SDL_VIDEO_VULKAN 1) - set(HAVE_VULKAN TRUE) - endif() + CheckVulkan() CheckQNXScreen() endif() if(UNIX) - file(GLOB CORE_UNIX_SOURCES ${SDL3_SOURCE_DIR}/src/core/unix/*.c) - list(APPEND SOURCE_FILES ${CORE_UNIX_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/core/unix/*.c") if (HAVE_LINUX_INPUT_H) - check_c_source_compiles(" - #include - #ifndef EVIOCGNAME - #error EVIOCGNAME() ioctl not available - #endif - int main(int argc, char** argv) { return 0; }" HAVE_INPUT_EVENTS) + check_c_source_compiles(" + #include + #ifndef EVIOCGNAME + #error EVIOCGNAME() ioctl not available + #endif + int main(int argc, char** argv) { return 0; }" HAVE_INPUT_EVENTS) endif() if(LINUX) @@ -1657,8 +1502,7 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) if(SDL_HAPTIC AND HAVE_INPUT_EVENTS) set(SDL_HAPTIC_LINUX 1) - file(GLOB HAPTIC_SOURCES ${SDL3_SOURCE_DIR}/src/haptic/linux/*.c) - list(APPEND SOURCE_FILES ${HAPTIC_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/haptic/linux/*.c") set(HAVE_SDL_HAPTIC TRUE) endif() @@ -1688,7 +1532,7 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) pkg_search_module(DBUS dbus-1 dbus) if(DBUS_FOUND) set(HAVE_DBUS_DBUS_H TRUE) - target_include_directories(sdl-build-options SYSTEM INTERFACE ${DBUS_INCLUDE_DIRS}) + sdl_include_directories(PRIVATE SYSTEM ${DBUS_INCLUDE_DIRS}) # Fcitx need only dbus. set(HAVE_FCITX TRUE) set(HAVE_DBUS TRUE) @@ -1700,7 +1544,7 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) find_path(HAVE_SYS_INOTIFY_H NAMES sys/inotify.h) if(IBUS_FOUND AND HAVE_SYS_INOTIFY_H) set(HAVE_IBUS_IBUS_H TRUE) - target_include_directories(sdl-build-options SYSTEM INTERFACE ${IBUS_INCLUDE_DIRS}) + sdl_include_directories(PRIVATE SYSTEM ${IBUS_INCLUDE_DIRS}) set(HAVE_IBUS TRUE) endif() endif() @@ -1710,58 +1554,57 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) endif() if(FREEBSD AND NOT HAVE_INOTIFY) - pkg_search_module(INOTIFY libinotify) - if(INOTIFY_FOUND) + set(LibInotify_PKG_CONFIG_SPEC libinotify) + pkg_check_modules(PC_LIBINOTIFY IMPORTED_TARGET ${LibInotify_PKG_CONFIG_SPEC}) + if(PC_LIBINOTIFY_FOUND) set(HAVE_INOTIFY 1) - target_include_directories(sdl-build-options SYSTEM INTERFACE ${INOTIFY_INCLUDE_DIRS}) - list(APPEND SDL_EXTRA_LIBS ${INOTIFY_LIBRARIES}) + sdl_link_dependency(libinotify LIBS PkgConfig::PC_LIBINOTIFY PKG_CONFIG_PREFIX PC_LIBINOTIFY PKG_CONFIG_SPECS ${LibInotify_PKG_CONFIG_SPEC}) endif() endif() - if(HAVE_LIBUNWIND_H) - # We've already found the header, so link the lib if present. - # NB: This .pc file is not present on FreeBSD where the implicitly - # linked base system libgcc_s includes all libunwind ABI. - pkg_search_module(UNWIND libunwind) - pkg_search_module(UNWIND_GENERIC libunwind-generic) - list(APPEND EXTRA_TEST_LIBS ${UNWIND_LIBRARIES} ${UNWIND_GENERIC_LIBRARIES}) - endif() + CheckLibUnwind() endif() if(HAVE_DBUS_DBUS_H) - list(APPEND SOURCE_FILES "${SDL3_SOURCE_DIR}/src/core/linux/SDL_dbus.c") - list(APPEND SOURCE_FILES "${SDL3_SOURCE_DIR}/src/core/linux/SDL_system_theme.c") + sdl_sources( + "${SDL3_SOURCE_DIR}/src/core/linux/SDL_dbus.c" + "${SDL3_SOURCE_DIR}/src/core/linux/SDL_system_theme.c" + ) endif() if(SDL_USE_IME) - list(APPEND SOURCE_FILES "${SDL3_SOURCE_DIR}/src/core/linux/SDL_ime.c") + sdl_sources("${SDL3_SOURCE_DIR}/src/core/linux/SDL_ime.c") endif() if(HAVE_IBUS_IBUS_H) - list(APPEND SOURCE_FILES "${SDL3_SOURCE_DIR}/src/core/linux/SDL_ibus.c") + sdl_sources("${SDL3_SOURCE_DIR}/src/core/linux/SDL_ibus.c") endif() if(HAVE_FCITX) - list(APPEND SOURCE_FILES "${SDL3_SOURCE_DIR}/src/core/linux/SDL_fcitx.c") + sdl_sources("${SDL3_SOURCE_DIR}/src/core/linux/SDL_fcitx.c") endif() if(HAVE_LIBUDEV_H) - list(APPEND SOURCE_FILES "${SDL3_SOURCE_DIR}/src/core/linux/SDL_udev.c") + sdl_sources("${SDL3_SOURCE_DIR}/src/core/linux/SDL_udev.c") endif() if(HAVE_INPUT_EVENTS) - list(APPEND SOURCE_FILES "${SDL3_SOURCE_DIR}/src/core/linux/SDL_evdev.c") - list(APPEND SOURCE_FILES "${SDL3_SOURCE_DIR}/src/core/linux/SDL_evdev_kbd.c") + sdl_sources( + "${SDL3_SOURCE_DIR}/src/core/linux/SDL_evdev.c" + "${SDL3_SOURCE_DIR}/src/core/linux/SDL_evdev_kbd.c" + ) endif() if(HAVE_INPUT_KBIO) - list(APPEND SOURCE_FILES "${SDL3_SOURCE_DIR}/src/core/freebsd/SDL_evdev_kbd_freebsd.c") + sdl_sources("${SDL3_SOURCE_DIR}/src/core/freebsd/SDL_evdev_kbd_freebsd.c") endif() # Always compiled for Linux, unconditionally: - list(APPEND SOURCE_FILES "${SDL3_SOURCE_DIR}/src/core/linux/SDL_evdev_capabilities.c") - list(APPEND SOURCE_FILES "${SDL3_SOURCE_DIR}/src/core/linux/SDL_threadprio.c") - list(APPEND SOURCE_FILES "${SDL3_SOURCE_DIR}/src/core/linux/SDL_sandbox.c") + sdl_sources( + "${SDL3_SOURCE_DIR}/src/core/linux/SDL_evdev_capabilities.c" + "${SDL3_SOURCE_DIR}/src/core/linux/SDL_threadprio.c" + "${SDL3_SOURCE_DIR}/src/core/linux/SDL_sandbox.c" + ) # src/core/unix/*.c is included in a generic if(UNIX) section, elsewhere. endif() @@ -1776,8 +1619,10 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) endif() if(LINUX AND HAVE_LINUX_INPUT_H AND NOT ANDROID) set(SDL_JOYSTICK_LINUX 1) - file(GLOB JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/linux/*.c ${SDL3_SOURCE_DIR}/src/joystick/steam/*.c) - list(APPEND SOURCE_FILES ${JOYSTICK_SOURCES}) + sdl_glob_sources( + "${SDL3_SOURCE_DIR}/src/joystick/linux/*.c" + "${SDL3_SOURCE_DIR}/src/joystick/steam/*.c" + ) set(HAVE_SDL_JOYSTICK TRUE) endif() endif() @@ -1792,43 +1637,38 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) check_library_exists(rt clock_gettime "" FOUND_CLOCK_GETTIME_LIBRT) if(FOUND_CLOCK_GETTIME_LIBRT) set(HAVE_CLOCK_GETTIME 1) - list(APPEND SDL_EXTRA_LIBS rt) + sdl_link_dependency(clock LIBS rt) endif() endif() endif() if(SDL_MISC) - file(GLOB MISC_SOURCES ${SDL3_SOURCE_DIR}/src/misc/unix/*.c) - list(APPEND SOURCE_FILES ${MISC_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/misc/unix/*.c") set(HAVE_SDL_MISC TRUE) endif() if(SDL_POWER) if(LINUX) set(SDL_POWER_LINUX 1) - file(GLOB POWER_SOURCES ${SDL3_SOURCE_DIR}/src/power/linux/*.c) - list(APPEND SOURCE_FILES ${POWER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/power/linux/*.c") set(HAVE_SDL_POWER TRUE) endif() endif() if(SDL_LOCALE) - file(GLOB LOCALE_SOURCES ${SDL3_SOURCE_DIR}/src/locale/unix/*.c) - list(APPEND SOURCE_FILES ${LOCALE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/locale/unix/*.c") set(HAVE_SDL_LOCALE TRUE) endif() if(SDL_FILESYSTEM) set(SDL_FILESYSTEM_UNIX 1) - file(GLOB FILESYSTEM_SOURCES ${SDL3_SOURCE_DIR}/src/filesystem/unix/*.c) - list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/filesystem/unix/*.c") set(HAVE_SDL_FILESYSTEM TRUE) endif() if(SDL_TIMERS) set(SDL_TIMER_UNIX 1) - file(GLOB TIMER_SOURCES ${SDL3_SOURCE_DIR}/src/timer/unix/*.c) - list(APPEND SOURCE_FILES ${TIMER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/unix/*.c") set(HAVE_SDL_TIMERS TRUE) endif() @@ -1836,7 +1676,7 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) if(SDL_RPATH AND SDL_SHARED) if(BSDI OR FREEBSD OR LINUX OR NETBSD) cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wl,--enable-new-dtags") + string(APPEND CMAKE_REQUIRED_FLAGS " -Wl,--enable-new-dtags") check_c_compiler_flag("" HAVE_ENABLE_NEW_DTAGS) cmake_pop_check_state() if(HAVE_ENABLE_NEW_DTAGS) @@ -1858,35 +1698,33 @@ elseif(UNIX AND NOT APPLE AND NOT RISCOS AND NOT HAIKU) set (USE_POSIX_SPAWN 1) endif() elseif(WINDOWS) - find_program(WINDRES windres) - check_c_source_compiles(" #include int main(int argc, char **argv) { return 0; }" HAVE_WIN32_CC) - file(GLOB CORE_SOURCES ${SDL3_SOURCE_DIR}/src/core/windows/*.c) - list(APPEND SOURCE_FILES ${CORE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/core/windows/*.c") if(WINDOWS_STORE) - file(GLOB WINRT_SOURCE_FILES ${SDL3_SOURCE_DIR}/src/core/winrt/*.c ${SDL3_SOURCE_DIR}/src/core/winrt/*.cpp) - list(APPEND SOURCE_FILES ${WINRT_SOURCE_FILES}) + sdl_glob_sources( + "${SDL3_SOURCE_DIR}/src/core/winrt/*.c" + "${SDL3_SOURCE_DIR}/src/core/winrt/*.cpp" + ) endif() - if(MSVC AND NOT SDL_LIBC) + if(TARGET SDL3-shared AND MSVC AND NOT SDL_LIBC) # Prevent codegen that would use the VC runtime libraries. - set_property(DIRECTORY . APPEND PROPERTY COMPILE_OPTIONS "/GS-;/Gs1048576") + target_compile_options(SDL3-shared PRIVATE "/GS-" "/Gs1048576") if(SDL_CPU_X86) - set_property(DIRECTORY . APPEND PROPERTY COMPILE_OPTIONS "/arch:SSE") + target_compile_options(SDL3-shared PRIVATE "/arch:SSE") endif() endif() if(SDL_MISC) if(WINDOWS_STORE) - file(GLOB MISC_SOURCES ${SDL3_SOURCE_DIR}/src/misc/winrt/*.cpp) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/misc/winrt/*.cpp") else() - file(GLOB MISC_SOURCES ${SDL3_SOURCE_DIR}/src/misc/windows/*.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/misc/windows/*.c") endif() - list(APPEND SOURCE_FILES ${MISC_SOURCES}) set(HAVE_SDL_MISC TRUE) endif() @@ -1898,9 +1736,9 @@ elseif(WINDOWS) endif() if(NOT MINGW AND NOT USE_WINSDK_DIRECTX) if("$ENV{DXSDK_DIR}" STREQUAL "") - message_error("DIRECTX requires the \$DXSDK_DIR environment variable to be set") + message(FATAL_ERROR "DIRECTX requires the \$DXSDK_DIR environment variable to be set") endif() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} /I\"$ENV{DXSDK_DIR}\\Include\"") + string(APPEND CMAKE_REQUIRED_FLAGS " /I\"$ENV{DXSDK_DIR}\\Include\"") endif() check_include_file(d3d9.h HAVE_D3D_H) @@ -1924,9 +1762,13 @@ elseif(WINDOWS) if(HAVE_D3D_H OR HAVE_D3D11_H OR HAVE_D3D12_H OR HAVE_DDRAW_H OR HAVE_DSOUND_H OR HAVE_DINPUT_H) set(HAVE_DIRECTX TRUE) if(NOT MINGW AND NOT USE_WINSDK_DIRECTX) - # TODO: change $ENV{DXSDL_DIR} to get the path from the include checks - target_link_directories(sdl-build-options INTERFACE "$$ENV{DXSDK_DIR}\\lib\\${PROCESSOR_ARCH}") - target_include_directories(sdl-build-options INTERFACE "$ENV{DXSDK_DIR}\\Include") + if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(PROCESSOR_ARCH "x64") + else() + set(PROCESSOR_ARCH "x86") + endif() + sdl_link_directories("$") + sdl_include_directories(PRIVATE SYSTEM "$") endif() endif() endif() @@ -1965,19 +1807,17 @@ elseif(WINDOWS) if(SDL_AUDIO) if(HAVE_DSOUND_H AND NOT WINDOWS_STORE) set(SDL_AUDIO_DRIVER_DSOUND 1) - file(GLOB DSOUND_AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/directsound/*.c) - list(APPEND SOURCE_FILES ${DSOUND_AUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/directsound/*.c") set(HAVE_SDL_AUDIO TRUE) endif() if(SDL_WASAPI AND HAVE_AUDIOCLIENT_H AND HAVE_MMDEVICEAPI_H) set(SDL_AUDIO_DRIVER_WASAPI 1) set(HAVE_WASAPI TRUE) - file(GLOB WASAPI_AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/wasapi/*.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/wasapi/*.c") if(WINDOWS_STORE) - list(APPEND WASAPI_AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/wasapi/SDL_wasapi_winrt.cpp) + sdl_sources("${SDL3_SOURCE_DIR}/src/audio/wasapi/SDL_wasapi_winrt.cpp") endif() - list(APPEND SOURCE_FILES ${WASAPI_AUDIO_SOURCES}) set(HAVE_SDL_AUDIO TRUE) endif() endif() @@ -1985,20 +1825,19 @@ elseif(WINDOWS) if(SDL_VIDEO) # requires SDL_LOADSO on Windows (IME, DX, etc.) if(NOT SDL_LOADSO) - message_error("SDL_VIDEO requires SDL_LOADSO, which is not enabled") + message(FATAL_ERROR "SDL_VIDEO requires SDL_LOADSO, which is not enabled") endif() if(WINDOWS_STORE) set(SDL_VIDEO_DRIVER_WINRT 1) - file(GLOB WIN_VIDEO_SOURCES - ${SDL3_SOURCE_DIR}/src/video/winrt/*.c - ${SDL3_SOURCE_DIR}/src/video/winrt/*.cpp - ${SDL3_SOURCE_DIR}/src/render/direct3d11/*.cpp - ) + sdl_glob_sources( + "${SDL3_SOURCE_DIR}/src/video/winrt/*.c" + "${SDL3_SOURCE_DIR}/src/video/winrt/*.cpp" + "${SDL3_SOURCE_DIR}/src/render/direct3d11/*.cpp" + ) else() set(SDL_VIDEO_DRIVER_WINDOWS 1) - file(GLOB WIN_VIDEO_SOURCES ${SDL3_SOURCE_DIR}/src/video/windows/*.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/windows/*.c") endif() - list(APPEND SOURCE_FILES ${WIN_VIDEO_SOURCES}) if(SDL_RENDER_D3D AND HAVE_D3D_H AND NOT WINDOWS_STORE) set(SDL_VIDEO_RENDER_D3D 1) @@ -2019,87 +1858,84 @@ elseif(WINDOWS) set(SDL_THREAD_GENERIC_COND_SUFFIX 1) set(SDL_THREAD_GENERIC_RWLOCK_SUFFIX 1) set(SDL_THREAD_WINDOWS 1) - list(APPEND SOURCE_FILES - ${SDL3_SOURCE_DIR}/src/thread/generic/SDL_syscond.c - ${SDL3_SOURCE_DIR}/src/thread/generic/SDL_sysrwlock.c - ${SDL3_SOURCE_DIR}/src/thread/windows/SDL_syscond_cv.c - ${SDL3_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c - ${SDL3_SOURCE_DIR}/src/thread/windows/SDL_sysrwlock_srw.c - ${SDL3_SOURCE_DIR}/src/thread/windows/SDL_syssem.c - ${SDL3_SOURCE_DIR}/src/thread/windows/SDL_systhread.c - ${SDL3_SOURCE_DIR}/src/thread/windows/SDL_systls.c) + sdl_sources( + "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_syscond.c" + "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_sysrwlock.c" + "${SDL3_SOURCE_DIR}/src/thread/windows/SDL_syscond_cv.c" + "${SDL3_SOURCE_DIR}/src/thread/windows/SDL_sysmutex.c" + "${SDL3_SOURCE_DIR}/src/thread/windows/SDL_sysrwlock_srw.c" + "${SDL3_SOURCE_DIR}/src/thread/windows/SDL_syssem.c" + "${SDL3_SOURCE_DIR}/src/thread/windows/SDL_systhread.c" + "${SDL3_SOURCE_DIR}/src/thread/windows/SDL_systls.c" + ) set(HAVE_SDL_THREADS TRUE) endif() if(SDL_SENSOR AND HAVE_SENSORSAPI_H AND NOT WINDOWS_STORE) set(SDL_SENSOR_WINDOWS 1) set(HAVE_SDL_SENSORS TRUE) - file(GLOB WINDOWS_SENSOR_SOURCES ${SDL3_SOURCE_DIR}/src/sensor/windows/*.c) - list(APPEND SOURCE_FILES ${WINDOWS_SENSOR_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/sensor/windows/*.c") endif() if(SDL_POWER) if(WINDOWS_STORE) set(SDL_POWER_WINRT 1) - list(APPEND SOURCE_FILES ${SDL3_SOURCE_DIR}/src/power/winrt/SDL_syspower.cpp) + sdl_sources("${SDL3_SOURCE_DIR}/src/power/winrt/SDL_syspower.cpp") else() set(SDL_POWER_WINDOWS 1) - list(APPEND SOURCE_FILES ${SDL3_SOURCE_DIR}/src/power/windows/SDL_syspower.c) + sdl_sources("${SDL3_SOURCE_DIR}/src/power/windows/SDL_syspower.c") set(HAVE_SDL_POWER TRUE) endif() endif() if(SDL_LOCALE) if(WINDOWS_STORE) - file(GLOB LOCALE_SOURCES ${SDL3_SOURCE_DIR}/src/locale/winrt/*.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/locale/winrt/*.c") else() - file(GLOB LOCALE_SOURCES ${SDL3_SOURCE_DIR}/src/locale/windows/*.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/locale/windows/*.c") endif() - list(APPEND SOURCE_FILES ${LOCALE_SOURCES}) set(HAVE_SDL_LOCALE TRUE) endif() if(SDL_FILESYSTEM) set(SDL_FILESYSTEM_WINDOWS 1) if(WINDOWS_STORE) - file(GLOB FILESYSTEM_SOURCES ${SDL3_SOURCE_DIR}/src/filesystem/winrt/*.cpp) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/filesystem/winrt/*.cpp") else() - file(GLOB FILESYSTEM_SOURCES ${SDL3_SOURCE_DIR}/src/filesystem/windows/*.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/filesystem/windows/*.c") endif() - list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES}) set(HAVE_SDL_FILESYSTEM TRUE) endif() # Libraries for Win32 native and MinGW if(NOT WINDOWS_STORE) - list(APPEND SDL_EXTRA_LIBS kernel32 user32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 setupapi shell32) + sdl_link_dependency(base LIBS kernel32 user32 gdi32 winmm imm32 ole32 oleaut32 version uuid advapi32 setupapi shell32) endif() if(WINDOWS_STORE) - list(APPEND SDL_EXTRA_LIBS - -nodefaultlib:vccorlib$<$:d> - -nodefaultlib:msvcrt$<$:d> - vccorlib$<$:d>.lib - msvcrt$<$:d>.lib + sdl_link_dependency(windows + LIBS + vccorlib$<$:d>.lib + msvcrt$<$:d>.lib + LINK_OPTIONS + -nodefaultlib:vccorlib$<$:d> + -nodefaultlib:msvcrt$<$:d> ) endif() if(SDL_TIMERS) set(SDL_TIMER_WINDOWS 1) - file(GLOB TIMER_SOURCES ${SDL3_SOURCE_DIR}/src/timer/windows/*.c) - list(APPEND SOURCE_FILES ${TIMER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/windows/*.c") set(HAVE_SDL_TIMERS TRUE) endif() if(SDL_LOADSO) set(SDL_LOADSO_WINDOWS 1) - file(GLOB LOADSO_SOURCES ${SDL3_SOURCE_DIR}/src/loadso/windows/*.c) - list(APPEND SOURCE_FILES ${LOADSO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/loadso/windows/*.c") set(HAVE_SDL_LOADSO TRUE) endif() - file(GLOB CORE_SOURCES ${SDL3_SOURCE_DIR}/src/core/windows/*.c) - list(APPEND SOURCE_FILES ${CORE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/core/windows/*.c") if(SDL_VIDEO) if(SDL_OPENGL AND NOT WINDOWS_STORE) @@ -2127,15 +1963,14 @@ elseif(WINDOWS) endif() if(SDL_JOYSTICK) - file(GLOB JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/windows/*.c) - list(APPEND SOURCE_FILES ${JOYSTICK_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/windows/*.c") if(NOT WINDOWS_STORE) set(SDL_JOYSTICK_RAWINPUT 1) endif() if(HAVE_DINPUT_H) set(SDL_JOYSTICK_DINPUT 1) - list(APPEND SDL_EXTRA_LIBS dinput8) + sdl_link_dependency(joystick LIBS dinput8) endif() if(HAVE_XINPUT_H) if(NOT WINDOWS_STORE) @@ -2150,7 +1985,7 @@ elseif(WINDOWS) if(SDL_HAPTIC) if((HAVE_DINPUT_H OR HAVE_XINPUT_H) AND NOT WINDOWS_STORE) - file(GLOB HAPTIC_SOURCES ${SDL3_SOURCE_DIR}/src/haptic/windows/*.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/haptic/windows/*.c") if(HAVE_DINPUT_H) set(SDL_HAPTIC_DINPUT 1) endif() @@ -2158,17 +1993,16 @@ elseif(WINDOWS) set(SDL_HAPTIC_XINPUT 1) endif() else() - file(GLOB HAPTIC_SOURCES ${SDL3_SOURCE_DIR}/src/haptic/dummy/*.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/haptic/dummy/*.c") set(SDL_HAPTIC_DUMMY 1) endif() - list(APPEND SOURCE_FILES ${HAPTIC_SOURCES}) set(HAVE_SDL_HAPTIC TRUE) endif() endif() - file(GLOB VERSION_SOURCES ${SDL3_SOURCE_DIR}/src/core/windows/*.rc) + sdl_glob_sources(SHARED "${SDL3_SOURCE_DIR}/src/core/windows/*.rc") if(MINGW OR CYGWIN) - list(APPEND SDL_PC_LIBS "-mwindows") + sdl_pc_link_options("-mwindows") endif() elseif(APPLE) @@ -2187,25 +2021,22 @@ elseif(APPLE) # Requires the darwin file implementation if(SDL_FILE) - file(GLOB EXTRA_SOURCES ${SDL3_SOURCE_DIR}/src/file/cocoa/*.m) - list(APPEND SOURCE_FILES ${EXTRA_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/file/cocoa/*.m") set(HAVE_SDL_FILE TRUE) endif() if(SDL_MISC) if(IOS OR TVOS) - file(GLOB MISC_SOURCES ${SDL3_SOURCE_DIR}/src/misc/ios/*.m) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/misc/ios/*.m") else() - file(GLOB MISC_SOURCES ${SDL3_SOURCE_DIR}/src/misc/macos/*.m) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/misc/macos/*.m") endif() - list(APPEND SOURCE_FILES ${MISC_SOURCES}) set(HAVE_SDL_MISC TRUE) endif() if(SDL_AUDIO) set(SDL_AUDIO_DRIVER_COREAUDIO 1) - file(GLOB AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/coreaudio/*.m) - list(APPEND SOURCE_FILES ${AUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/coreaudio/*.m") set(HAVE_SDL_AUDIO TRUE) set(SDL_FRAMEWORK_COREAUDIO 1) set(SDL_FRAMEWORK_AUDIOTOOLBOX 1) @@ -2217,9 +2048,9 @@ elseif(APPLE) endif() if(SDL_JOYSTICK) - file(GLOB MFI_JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/apple/*.m) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/apple/*.m") if(IOS OR TVOS) - file(GLOB JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/steam/*.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/steam/*.c") set(SDL_JOYSTICK_MFI 1) if(IOS) set(SDL_FRAMEWORK_COREMOTION 1) @@ -2227,7 +2058,7 @@ elseif(APPLE) set(SDL_FRAMEWORK_GAMECONTROLLER 1) set(SDL_FRAMEWORK_COREHAPTICS 1) else() - file(GLOB JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/darwin/*.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/darwin/*.c") set_property(SOURCE ${MFI_JOYSTICK_SOURCES} APPEND_STRING PROPERTY COMPILE_FLAGS " -fobjc-weak") check_objc_source_compiles(" #include @@ -2257,54 +2088,48 @@ elseif(APPLE) set(SDL_FRAMEWORK_IOKIT 1) set(SDL_FRAMEWORK_FF 1) endif() - list(APPEND SOURCE_FILES ${JOYSTICK_SOURCES} ${MFI_JOYSTICK_SOURCES}) set(HAVE_SDL_JOYSTICK TRUE) endif() if(SDL_HAPTIC) if (IOS OR TVOS) - file(GLOB HAPTIC_SOURCES ${SDL3_SOURCE_DIR}/src/haptic/dummy/*.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/haptic/dummy/*.c") set(SDL_HAPTIC_DUMMY 1) else() - file(GLOB HAPTIC_SOURCES ${SDL3_SOURCE_DIR}/src/haptic/darwin/*.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/haptic/darwin/*.c") set(SDL_HAPTIC_IOKIT 1) set(SDL_FRAMEWORK_IOKIT 1) set(SDL_FRAMEWORK_FF 1) endif() - list(APPEND SOURCE_FILES ${HAPTIC_SOURCES}) set(HAVE_SDL_HAPTIC TRUE) endif() if(SDL_POWER) if (IOS OR TVOS) - file(GLOB POWER_SOURCES ${SDL3_SOURCE_DIR}/src/power/uikit/*.m) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/power/uikit/*.m") set(SDL_POWER_UIKIT 1) else() - file(GLOB POWER_SOURCES ${SDL3_SOURCE_DIR}/src/power/macos/*.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/power/macos/*.c") set(SDL_POWER_MACOSX 1) set(SDL_FRAMEWORK_IOKIT 1) endif() - list(APPEND SOURCE_FILES ${POWER_SOURCES}) set(HAVE_SDL_POWER TRUE) endif() if(SDL_LOCALE) - file(GLOB LOCALE_SOURCES ${SDL3_SOURCE_DIR}/src/locale/macos/*.m) - list(APPEND SOURCE_FILES ${LOCALE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/locale/macos/*.m") set(HAVE_SDL_LOCALE TRUE) endif() if(SDL_TIMERS) set(SDL_TIMER_UNIX 1) - file(GLOB TIMER_SOURCES ${SDL3_SOURCE_DIR}/src/timer/unix/*.c) - list(APPEND SOURCE_FILES ${TIMER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/unix/*.c") set(HAVE_SDL_TIMERS TRUE) endif(SDL_TIMERS) if(SDL_FILESYSTEM) set(SDL_FILESYSTEM_COCOA 1) - file(GLOB FILESYSTEM_SOURCES ${SDL3_SOURCE_DIR}/src/filesystem/cocoa/*.m) - list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/filesystem/cocoa/*.m") set(HAVE_SDL_FILESYSTEM TRUE) endif() @@ -2312,8 +2137,7 @@ elseif(APPLE) if(IOS) set(SDL_SENSOR_COREMOTION 1) set(HAVE_SDL_SENSORS TRUE) - file(GLOB SENSOR_SOURCES ${SDL3_SOURCE_DIR}/src/sensor/coremotion/*.m) - list(APPEND SOURCE_FILES ${SENSOR_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/sensor/coremotion/*.m") endif() endif() @@ -2326,8 +2150,7 @@ elseif(APPLE) set(SDL_FRAMEWORK_UIKIT 1) set(SDL_IPHONE_KEYBOARD 1) set(SDL_IPHONE_LAUNCHSCREEN 1) - file(GLOB UIKITVIDEO_SOURCES ${SDL3_SOURCE_DIR}/src/video/uikit/*.m) - list(APPEND SOURCE_FILES ${UIKITVIDEO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/uikit/*.m") set(HAVE_SDL_VIDEO TRUE) else() CheckCOCOA() @@ -2373,8 +2196,7 @@ elseif(APPLE) set(HAVE_METAL TRUE) endif() if(SDL_RENDER_METAL) - file(GLOB RENDER_METAL_SOURCES ${SDL3_SOURCE_DIR}/src/render/metal/*.m) - list(APPEND SOURCE_FILES ${RENDER_METAL_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/render/metal/*.m") set(SDL_VIDEO_RENDER_METAL 1) set(HAVE_RENDER_METAL TRUE) endif() @@ -2384,71 +2206,71 @@ elseif(APPLE) # Actually load the frameworks at the end so we don't duplicate include. if(SDL_FRAMEWORK_COREVIDEO) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,CoreVideo") + sdl_link_dependency(corevideo LINK_OPTIONS "-Wl,-framework,CoreVideo") endif() if(SDL_FRAMEWORK_COCOA) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,Cocoa") + sdl_link_dependency(cocoa LINK_OPTIONS "-Wl,-framework,Cocoa") endif() if(SDL_FRAMEWORK_IOKIT) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,IOKit") + sdl_link_dependency(iokit LINK_OPTIONS "-Wl,-framework,IOKit") endif() if(SDL_FRAMEWORK_FF) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,ForceFeedback") + sdl_link_dependency(ff LINK_OPTIONS "-Wl,-framework,ForceFeedback") endif() if(SDL_FRAMEWORK_CARBON) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,Carbon") + sdl_link_dependency(carbon LINK_OPTIONS "-Wl,-framework,Carbon") endif() if(SDL_FRAMEWORK_COREAUDIO) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,CoreAudio") + sdl_link_dependency(core_audio LINK_OPTIONS "-Wl,-framework,CoreAudio") endif() if(SDL_FRAMEWORK_AUDIOTOOLBOX) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,AudioToolbox") + sdl_link_dependency(audio_toolbox LINK_OPTIONS "-Wl,-framework,AudioToolbox") endif() if(SDL_FRAMEWORK_AVFOUNDATION) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,AVFoundation") + sdl_link_dependency(av_foundation LINK_OPTIONS "-Wl,-framework,AVFoundation") endif() if(SDL_FRAMEWORK_COREBLUETOOTH) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,CoreBluetooth") + sdl_link_dependency(core_bluetooth LINK_OPTIONS "-Wl,-framework,CoreBluetooth") endif() if(SDL_FRAMEWORK_COREGRAPHICS) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,CoreGraphics") + sdl_link_dependency(core_graphics LINK_OPTIONS "-Wl,-framework,CoreGraphics") endif() if(SDL_FRAMEWORK_COREMOTION) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,CoreMotion") + sdl_link_dependency(core_motion LINK_OPTIONS "-Wl,-framework,CoreMotion") endif() if(SDL_FRAMEWORK_FOUNDATION) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,Foundation") + sdl_link_dependency(foundation LINK_OPTIONS "-Wl,-framework,Foundation") endif() if(SDL_FRAMEWORK_GAMECONTROLLER) find_library(GAMECONTROLLER GameController) if(GAMECONTROLLER) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-weak_framework,GameController") + sdl_link_dependency(game_controller LINK_OPTIONS "-Wl,-weak_framework,GameController") endif() endif() if(SDL_FRAMEWORK_METAL) if(IOS OR TVOS) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,Metal") + sdl_link_dependency(metal LINK_OPTIONS "-Wl,-framework,Metal") else() - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-weak_framework,Metal") + sdl_link_dependency(metal LINK_OPTIONS "-Wl,-weak_framework,Metal") endif() endif() if(SDL_FRAMEWORK_OPENGLES) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,OpenGLES") + sdl_link_dependency(opengles LINK_OPTIONS "-Wl,-framework,OpenGLES") endif() if(SDL_FRAMEWORK_QUARTZCORE) if(IOS OR TVOS) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,QuartzCore") + sdl_link_dependency(quartz_core LINK_OPTIONS "-Wl,-framework,QuartzCore") else() - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-weak_framework,QuartzCore") + sdl_link_dependency(metal LINK_OPTIONS "-Wl,-weak_framework,QuartzCore") endif() endif() if(SDL_FRAMEWORK_UIKIT) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-framework,UIKit") + sdl_link_dependency(ui_kit LINK_OPTIONS "-Wl,-framework,UIKit") endif() if(SDL_FRAMEWORK_COREHAPTICS) find_library(COREHAPTICS CoreHaptics) if(COREHAPTICS) - list(APPEND SDL_EXTRA_LDFLAGS "-Wl,-weak_framework,CoreHaptics") + sdl_link_dependency(core_haptics LINK_OPTIONS "-Wl,-framework,CoreHaptics") endif() endif() @@ -2457,28 +2279,24 @@ elseif(APPLE) elseif(HAIKU) if(SDL_AUDIO) set(SDL_AUDIO_DRIVER_HAIKU 1) - file(GLOB HAIKU_AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/haiku/*.cc) - list(APPEND SOURCE_FILES ${HAIKU_AUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/haiku/*.cc") set(HAVE_SDL_AUDIO TRUE) endif() if(SDL_JOYSTICK) set(SDL_JOYSTICK_HAIKU 1) - file(GLOB HAIKU_JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/haiku/*.cc) - list(APPEND SOURCE_FILES ${HAIKU_JOYSTICK_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/haiku/*.cc") set(HAVE_SDL_JOYSTICK TRUE) endif() if(SDL_MISC) - file(GLOB MISC_SOURCES ${SDL3_SOURCE_DIR}/src/misc/haiku/*.cc) - list(APPEND SOURCE_FILES ${MISC_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/misc/haiku/*.cc") set(HAVE_SDL_MISC TRUE) endif() if(SDL_VIDEO) set(SDL_VIDEO_DRIVER_HAIKU 1) - file(GLOB HAIKUVIDEO_SOURCES ${SDL3_SOURCE_DIR}/src/video/haiku/*.cc) - list(APPEND SOURCE_FILES ${HAIKUVIDEO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/haiku/*.cc") set(HAVE_SDL_VIDEO TRUE) if(SDL_OPENGL) @@ -2486,69 +2304,60 @@ elseif(HAIKU) set(SDL_VIDEO_OPENGL 1) set(SDL_VIDEO_OPENGL_HAIKU 1) set(SDL_VIDEO_RENDER_OGL 1) - list(APPEND SDL_EXTRA_LIBS GL) + sdl_link_dependency(opengl LIBS GL) set(HAVE_OPENGL TRUE) endif() endif() if(SDL_FILESYSTEM) set(SDL_FILESYSTEM_HAIKU 1) - file(GLOB FILESYSTEM_SOURCES ${SDL3_SOURCE_DIR}/src/filesystem/haiku/*.cc) - list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/filesystem/haiku/*.cc") set(HAVE_SDL_FILESYSTEM TRUE) endif() if(SDL_TIMERS) set(SDL_TIMER_HAIKU 1) - file(GLOB TIMER_SOURCES ${SDL3_SOURCE_DIR}/src/timer/haiku/*.c) - list(APPEND SOURCE_FILES ${TIMER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/haiku/*.c") set(HAVE_SDL_TIMERS TRUE) endif() if(SDL_POWER) set(SDL_POWER_HAIKU 1) - file(GLOB HAIKU_POWER_SOURCES ${SDL3_SOURCE_DIR}/src/power/haiku/*.c) - list(APPEND SOURCE_FILES ${HAIKU_POWER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/power/haiku/*.c") set(HAVE_SDL_POWER TRUE) endif() if(SDL_LOCALE) - file(GLOB LOCALE_SOURCES ${SDL3_SOURCE_DIR}/src/locale/haiku/*.cc) - list(APPEND SOURCE_FILES ${LOCALE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/locale/haiku/*.cc") set(HAVE_SDL_LOCALE TRUE) endif() - file(GLOB HAIKU_CORE_SOURCES ${SDL3_SOURCE_DIR}/src/core/haiku/*.cc) - list(APPEND SOURCE_FILES ${HAIKU_CORE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/core/haiku/*.cc") CheckPTHREAD() - list(APPEND SDL_EXTRA_LIBS root be media game device textencoding) + sdl_link_dependency(base LIBS root be media game device textencoding) elseif(RISCOS) if(SDL_MISC) - file(GLOB MISC_SOURCES ${SDL3_SOURCE_DIR}/src/misc/riscos/*.c) - list(APPEND SOURCE_FILES ${MISC_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/misc/riscos/*.c") set(HAVE_SDL_MISC TRUE) endif() if(SDL_VIDEO) set(SDL_VIDEO_DRIVER_RISCOS 1) - file(GLOB RISCOSVIDEO_SOURCES ${SDL3_SOURCE_DIR}/src/video/riscos/*.c) - list(APPEND SOURCE_FILES ${RISCOSVIDEO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/riscos/*.c") set(HAVE_SDL_VIDEO TRUE) endif() if(SDL_FILESYSTEM) set(SDL_FILESYSTEM_RISCOS 1) - file(GLOB FILESYSTEM_SOURCES ${SDL3_SOURCE_DIR}/src/filesystem/riscos/*.c) - list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/filesystem/riscos/*.c") set(HAVE_SDL_FILESYSTEM TRUE) endif() if(SDL_TIMERS) set(SDL_TIMER_UNIX 1) - file(GLOB TIMER_SOURCES ${SDL3_SOURCE_DIR}/src/timer/unix/*.c) - list(APPEND SOURCE_FILES ${TIMER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/unix/*.c") set(HAVE_SDL_TIMERS TRUE) if(SDL_CLOCK_GETTIME) @@ -2565,7 +2374,7 @@ elseif(RISCOS) elseif(VITA) # SDL_spinlock.c Needs to be compiled in ARM mode. cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror=unused-command-line-argument") + string(APPEND CMAKE_REQUIRED_FLAGS " -Werror=unused-command-line-argument") check_c_compiler_flag(-marm HAVE_ARM_MODE) cmake_pop_check_state() if(HAVE_ARM_MODE) @@ -2573,67 +2382,59 @@ elseif(VITA) endif() if(SDL_MISC) - file(GLOB MISC_SOURCES ${SDL3_SOURCE_DIR}/src/misc/vita/*.c) - list(APPEND SOURCE_FILES ${MISC_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/misc/vita/*.c") set(HAVE_SDL_MISC TRUE) endif() if(SDL_AUDIO) set(SDL_AUDIO_DRIVER_VITA 1) - file(GLOB VITA_AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/vita/*.c) - list(APPEND SOURCE_FILES ${VITA_AUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/vita/*.c") set(HAVE_SDL_AUDIO TRUE) endif() if(SDL_FILESYSTEM) set(SDL_FILESYSTEM_VITA 1) - file(GLOB VITA_FILESYSTEM_SOURCES ${SDL3_SOURCE_DIR}/src/filesystem/vita/*.c) - list(APPEND SOURCE_FILES ${VITA_FILESYSTEM_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/filesystem/vita/*.c") set(HAVE_SDL_FILESYSTEM TRUE) endif() if(SDL_JOYSTICK) set(SDL_JOYSTICK_VITA 1) - file(GLOB VITA_JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/vita/*.c) - list(APPEND SOURCE_FILES ${VITA_JOYSTICK_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/vita/*.c") set(HAVE_SDL_JOYSTICK TRUE) endif() if(SDL_POWER) set(SDL_POWER_VITA 1) - file(GLOB VITA_POWER_SOURCES ${SDL3_SOURCE_DIR}/src/power/vita/*.c) - list(APPEND SOURCE_FILES ${VITA_POWER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/power/vita/*.c") set(HAVE_SDL_POWER TRUE) endif() if(SDL_THREADS) set(SDL_THREAD_VITA 1) - list(APPEND SOURCE_FILES - ${SDL3_SOURCE_DIR}/src/thread/vita/SDL_sysmutex.c - ${SDL3_SOURCE_DIR}/src/thread/vita/SDL_syssem.c - ${SDL3_SOURCE_DIR}/src/thread/vita/SDL_systhread.c - ${SDL3_SOURCE_DIR}/src/thread/vita/SDL_syscond.c - ${SDL3_SOURCE_DIR}/src/thread/generic/SDL_sysrwlock.c - ${SDL3_SOURCE_DIR}/src/thread/generic/SDL_systls.c) + sdl_sources( + "${SDL3_SOURCE_DIR}/src/thread/vita/SDL_sysmutex.c" + "${SDL3_SOURCE_DIR}/src/thread/vita/SDL_syssem.c" + "${SDL3_SOURCE_DIR}/src/thread/vita/SDL_systhread.c" + "${SDL3_SOURCE_DIR}/src/thread/vita/SDL_syscond.c" + "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_sysrwlock.c" + "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_systls.c" + ) set(HAVE_SDL_THREADS TRUE) endif() if(SDL_LOCALE) - file(GLOB LOCALE_SOURCES ${SDL3_SOURCE_DIR}/src/locale/vita/*.c) - list(APPEND SOURCE_FILES ${LOCALE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/locale/vita/*.c") set(HAVE_SDL_LOCALE TRUE) endif() if(SDL_TIMERS) set(SDL_TIMER_VITA 1) - file(GLOB TIMER_SOURCES ${SDL3_SOURCE_DIR}/src/timer/vita/*.c) - list(APPEND SOURCE_FILES ${TIMER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/vita/*.c") set(HAVE_SDL_TIMERS TRUE) endif() if(SDL_SENSOR) set(SDL_SENSOR_VITA 1) set(HAVE_SDL_SENSORS TRUE) - file(GLOB VITA_SENSOR_SOURCES ${SDL3_SOURCE_DIR}/src/sensor/vita/*.c) - list(APPEND SOURCE_FILES ${VITA_SENSOR_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/sensor/vita/*.c") endif() if(SDL_VIDEO) set(SDL_VIDEO_DRIVER_VITA 1) - file(GLOB VITA_VIDEO_SOURCES ${SDL3_SOURCE_DIR}/src/video/vita/*.c) - list(APPEND SOURCE_FILES ${VITA_VIDEO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/vita/*.c") set(HAVE_SDL_VIDEO TRUE) if(VIDEO_VITA_PIB) @@ -2641,11 +2442,12 @@ elseif(VITA) if(HAVE_PIGS_IN_BLANKET_H) set(SDL_VIDEO_OPENGL_ES2 1) - list(APPEND SDL_EXTRA_LIBS - pib - libScePiglet_stub_weak - taihen_stub_weak - SceShaccCg_stub_weak + sdl_link_dependency(pib + LIBS + pib + libScePiglet_stub_weak + taihen_stub_weak + SceShaccCg_stub_weak ) set(HAVE_VIDEO_VITA_PIB ON) set(SDL_VIDEO_VITA_PIB 1) @@ -2657,17 +2459,18 @@ elseif(VITA) if(VIDEO_VITA_PVR) check_include_file(gpu_es4/psp2_pvr_hint.h HAVE_PVR_H) if(HAVE_PVR_H) - target_compile_definitions(sdl-build-options INTERFACE "__psp2__") + sdl_compile_definitions(PRIVATE "__psp2__") set(SDL_VIDEO_OPENGL_EGL 1) set(HAVE_OPENGLES TRUE) set(SDL_VIDEO_OPENGL_ES 1) set(SDL_VIDEO_OPENGL_ES2 1) set(SDL_VIDEO_RENDER_OGL_ES2 1) - list(APPEND SDL_EXTRA_LIBS - libgpu_es4_ext_stub_weak - libIMGEGL_stub_weak - SceIme_stub + sdl_link_dependency(pvr + LIBS + libgpu_es4_ext_stub_weak + libIMGEGL_stub_weak + SceIme_stub ) set(HAVE_VIDEO_VITA_PVR ON) @@ -2679,7 +2482,7 @@ elseif(VITA) set(HAVE_OPENGL TRUE) set(SDL_VIDEO_OPENGL 1) set(SDL_VIDEO_RENDER_OGL 1) - list(APPEND SDL_EXTRA_LIBS libGL_stub) + sdl_link_dependency(opengl LIBS libGL_stub) set(SDL_VIDEO_VITA_PVR_OGL 1) endif() endif() @@ -2690,81 +2493,76 @@ elseif(VITA) endif() set(SDL_VIDEO_RENDER_VITA_GXM 1) - - list(APPEND SDL_EXTRA_LIBS - SceGxm_stub - SceDisplay_stub - SceCtrl_stub - SceAppMgr_stub - SceAppUtil_stub - SceAudio_stub - SceAudioIn_stub - SceSysmodule_stub - SceDisplay_stub - SceCtrl_stub - SceIofilemgr_stub - SceCommonDialog_stub - SceTouch_stub - SceHid_stub - SceMotion_stub - ScePower_stub - SceProcessmgr_stub - m + sdl_link_dependency(base + LIBS + SceGxm_stub + SceDisplay_stub + SceCtrl_stub + SceAppMgr_stub + SceAppUtil_stub + SceAudio_stub + SceAudioIn_stub + SceSysmodule_stub + SceDisplay_stub + SceCtrl_stub + SceIofilemgr_stub + SceCommonDialog_stub + SceTouch_stub + SceHid_stub + SceMotion_stub + ScePower_stub + SceProcessmgr_stub ) endif() - target_compile_definitions(sdl-build-options INTERFACE "__VITA__") + sdl_compile_definitions(PRIVATE "__VITA__") elseif(PSP) - file(GLOB PSP_CORE_SOURCES ${SDL3_SOURCE_DIR}/src/core/psp/*.c) - list(APPEND SOURCE_FILES ${PSP_CORE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/core/psp/*.c") if(SDL_AUDIO) set(SDL_AUDIO_DRIVER_PSP 1) - file(GLOB PSP_AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/psp/*.c) - list(APPEND SOURCE_FILES ${PSP_AUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/psp/*.c") set(HAVE_SDL_AUDIO TRUE) endif() if(SDL_FILESYSTEM) set(SDL_FILESYSTEM_PSP 1) - file(GLOB PSP_FILESYSTEM_SOURCES ${SDL3_SOURCE_DIR}/src/filesystem/psp/*.c) - list(APPEND SOURCE_FILES ${PSP_FILESYSTEM_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/filesystem/psp/*.c") set(HAVE_SDL_FILESYSTEM TRUE) endif() if(SDL_JOYSTICK) set(SDL_JOYSTICK_PSP 1) - file(GLOB PSP_JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/psp/*.c) - list(APPEND SOURCE_FILES ${PSP_JOYSTICK_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/psp/*.c") set(HAVE_SDL_JOYSTICK TRUE) endif() if(SDL_POWER) set(SDL_POWER_PSP 1) - file(GLOB PSP_POWER_SOURCES ${SDL3_SOURCE_DIR}/src/power/psp/*.c) - list(APPEND SOURCE_FILES ${PSP_POWER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/power/psp/*.c") set(HAVE_SDL_POWER TRUE) endif() if(SDL_THREADS) set(SDL_THREAD_PSP 1) - file(GLOB PSP_THREAD_SOURCES ${SDL3_SOURCE_DIR}/src/thread/generic/SDL_systls.c ${SDL3_SOURCE_DIR}/src/thread/generic/SDL_sysrwlock.c ${SDL3_SOURCE_DIR}/src/thread/psp/*.c) - list(APPEND SOURCE_FILES ${PSP_THREAD_SOURCES}) + sdl_glob_sources( + "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_systls.c" + "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_sysrwlock.c" + "${SDL3_SOURCE_DIR}/src/thread/psp/*.c" + ) set(HAVE_SDL_THREADS TRUE) endif() if(SDL_TIMERS) set(SDL_TIMER_PSP 1) - file(GLOB PSP_TIMER_SOURCES ${SDL3_SOURCE_DIR}/src/timer/psp/*.c) - list(APPEND SOURCE_FILES ${PSP_TIMER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/psp/*.c") set(HAVE_SDL_TIMERS TRUE) endif() if(SDL_VIDEO) set(SDL_VIDEO_DRIVER_PSP 1) set(SDL_VIDEO_RENDER_PSP 1) - file(GLOB PSP_VIDEO_SOURCES ${SDL3_SOURCE_DIR}/src/video/psp/*.c) - list(APPEND SOURCE_FILES ${PSP_VIDEO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/psp/*.c") set(SDL_VIDEO_OPENGL 1) set(HAVE_SDL_VIDEO TRUE) endif() - - list(APPEND SDL_EXTRA_LIBS + sdl_link_dependency(base + LIBS GL pspvram pspaudio @@ -2778,139 +2576,127 @@ elseif(PSP) ) elseif(PS2) - target_compile_definitions(sdl-build-options INTERFACE "PS2" "__PS2__") - target_include_directories(sdl-build-options INTERFACE "$ENV{PS2SDK}/ports/include" "$ENV{PS2DEV}/gsKit/include") + sdl_compile_definitions(PRIVATE "PS2" "__PS2__") + sdl_include_directories(PRIVATE SYSTEM "$ENV{PS2SDK}/ports/include" "$ENV{PS2DEV}/gsKit/include") - file(GLOB PS2_CORE_SOURCES ${SDL3_SOURCE_DIR}/src/core/ps2/*.c) - set(SOURCE_FILES ${SOURCE_FILES} ${PS2_CORE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/core/ps2/*.c") if(SDL_AUDIO) set(SDL_AUDIO_DRIVER_PS2 1) - file(GLOB PS2_AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/ps2/*.c) - set(SOURCE_FILES ${SOURCE_FILES} ${PS2_AUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/ps2/*.c") set(HAVE_SDL_AUDIO TRUE) endif() if(SDL_FILESYSTEM) set(SDL_FILESYSTEM_PS2 1) - file(GLOB PS2_FILESYSTEM_SOURCES ${SDL3_SOURCE_DIR}/src/filesystem/ps2/*.c) - list(APPEND SOURCE_FILES ${PS2_FILESYSTEM_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/filesystem/ps2/*.c") set(HAVE_SDL_FILESYSTEM TRUE) endif() if(SDL_JOYSTICK) set(SDL_JOYSTICK_PS2 1) - file(GLOB PS2_JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/ps2/*.c) - list(APPEND SOURCE_FILES ${PS2_JOYSTICK_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/ps2/*.c") set(HAVE_SDL_JOYSTICK TRUE) endif() if(SDL_THREADS) set(SDL_THREAD_PS2 1) - file(GLOB PS2_THREAD_SOURCES ${SDL3_SOURCE_DIR}/src/thread/generic/SDL_syscond.c ${SDL3_SOURCE_DIR}/src/thread/generic/SDL_sysmutex.c ${SDL3_SOURCE_DIR}/src/thread/generic/SDL_sysrwlock.c ${SDL3_SOURCE_DIR}/src/thread/generic/SDL_systls.c ${SDL3_SOURCE_DIR}/src/thread/ps2/*.c) - list(APPEND SOURCE_FILES ${PS2_THREAD_SOURCES}) + sdl_glob_sources( + "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_syscond.c" + "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_sysmutex.c" + "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_sysrwlock.c" + "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_systls.c" + "${SDL3_SOURCE_DIR}/src/thread/ps2/*.c" + ) set(HAVE_SDL_THREADS TRUE) endif() if(SDL_TIMERS) set(SDL_TIMER_PS2 1) - file(GLOB PS2_TIMER_SOURCES ${SDL3_SOURCE_DIR}/src/timer/ps2/*.c) - list(APPEND SOURCE_FILES ${PS2_TIMER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/ps2/*.c") set(HAVE_SDL_TIMERS TRUE) endif() if(SDL_VIDEO) set(SDL_VIDEO_DRIVER_PS2 1) set(SDL_VIDEO_RENDER_PS2 1) - file(GLOB PS2_VIDEO_SOURCES ${SDL3_SOURCE_DIR}/src/video/ps2/*.c ${SDL3_SOURCE_DIR}/src/render/ps2/*.c) - list(APPEND SOURCE_FILES ${PS2_VIDEO_SOURCES}) + sdl_glob_sources( + "${SDL3_SOURCE_DIR}/src/video/ps2/*.c" + "${SDL3_SOURCE_DIR}/src/render/ps2/*.c" + ) set(SDL_VIDEO_OPENGL 0) set(HAVE_SDL_VIDEO TRUE) endif() - list(APPEND SDL_EXTRA_LIBS - patches - gskit - dmakit - ps2_drivers + sdl_link_dependency(base + LIBS + patches + gskit + dmakit + ps2_drivers ) - elseif(N3DS) - file(GLOB N3DS_CORE_SOURCES ${SDL3_SOURCE_DIR}/src/core/n3ds/*.c) - list(APPEND SOURCE_FILES ${N3DS_CORE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/core/n3ds/*.c") if(SDL_AUDIO) set(SDL_AUDIO_DRIVER_N3DS 1) - file(GLOB N3DS_AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/n3ds/*.c) - list(APPEND SOURCE_FILES ${N3DS_AUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/n3ds/*.c") set(HAVE_SDL_AUDIO TRUE) endif() if(SDL_FILESYSTEM) set(SDL_FILESYSTEM_N3DS 1) - file(GLOB N3DS_FILESYSTEM_SOURCES ${SDL3_SOURCE_DIR}/src/filesystem/n3ds/*.c) - list(APPEND SOURCE_FILES ${N3DS_FILESYSTEM_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/filesystem/n3ds/*.c") set(HAVE_SDL_FILESYSTEM TRUE) endif() if(SDL_JOYSTICK) set(SDL_JOYSTICK_N3DS 1) - file(GLOB N3DS_JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/n3ds/*.c) - list(APPEND SOURCE_FILES ${N3DS_JOYSTICK_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/n3ds/*.c") set(HAVE_SDL_JOYSTICK TRUE) endif() if(SDL_POWER) set(SDL_POWER_N3DS 1) - file(GLOB N3DS_POWER_SOURCES ${SDL3_SOURCE_DIR}/src/power/n3ds/*.c) - list(APPEND SOURCE_FILES ${N3DS_POWER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/power/n3ds/*.c") set(HAVE_SDL_POWER TRUE) endif() if(SDL_THREADS) set(SDL_THREAD_N3DS 1) - file(GLOB N3DS_THREAD_SOURCES ${SDL3_SOURCE_DIR}/src/thread/n3ds/*.c) - list(APPEND SOURCE_FILES ${N3DS_THREAD_SOURCES} ${SDL3_SOURCE_DIR}/src/thread/generic/SDL_systls.c ${SDL3_SOURCE_DIR}/src/thread/generic/SDL_sysrwlock.c) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/thread/n3ds/*.c") + sdl_sources( + "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_systls.c" + "${SDL3_SOURCE_DIR}/src/thread/generic/SDL_sysrwlock.c" + ) set(HAVE_SDL_THREADS TRUE) endif() if(SDL_TIMERS) set(SDL_TIMER_N3DS 1) - file(GLOB N3DS_TIMER_SOURCES ${SDL3_SOURCE_DIR}/src/timer/n3ds/*.c) - list(APPEND SOURCE_FILES ${N3DS_TIMER_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/n3ds/*.c") set(HAVE_SDL_TIMERS TRUE) endif() if(SDL_SENSOR) set(SDL_SENSOR_N3DS 1) - file(GLOB N3DS_SENSOR_SOURCES ${SDL3_SOURCE_DIR}/src/sensor/n3ds/*.c) - list(APPEND SOURCE_FILES ${N3DS_SENSOR_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/sensor/n3ds/*.c") set(HAVE_SDL_SENSORS TRUE) endif() if(SDL_VIDEO) set(SDL_VIDEO_DRIVER_N3DS 1) - file(GLOB N3DS_VIDEO_SOURCES ${SDL3_SOURCE_DIR}/src/video/n3ds/*.c) - list(APPEND SOURCE_FILES ${N3DS_VIDEO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/n3ds/*.c") set(HAVE_SDL_VIDEO TRUE) endif() if(SDL_LOCALE) - file(GLOB N3DS_LOCALE_SOURCES ${SDL3_SOURCE_DIR}/src/locale/n3ds/*.c) - list(APPEND SOURCE_FILES ${N3DS_LOCALE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/locale/n3ds/*.c") set(HAVE_SDL_LOCALE TRUE) endif() # Requires the n3ds file implementation if(SDL_FILE) - file(GLOB N3DS_FILE_SOURCES ${SDL3_SOURCE_DIR}/src/file/n3ds/*.c) - list(APPEND SOURCE_FILES ${N3DS_FILE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/file/n3ds/*.c") set(HAVE_SDL_FILE TRUE) else() - message_error("SDL_FILE must be enabled to build on N3DS") + message(FATAL_ERROR "SDL_FILE must be enabled to build on N3DS") endif() - - foreach(lib ${CMAKE_C_STANDARD_LIBRARIES}) - if(lib MATCHES "^-l") - string(SUBSTRING "${lib}" 2 -1 lib) - endif() - list(APPEND SDL_EXTRA_LIBS ${lib}) - endforeach() endif() if(HAVE_VULKAN AND NOT SDL_LOADSO) @@ -2924,8 +2710,7 @@ endif() if(SDL_VIDEO) if(SDL_OFFSCREEN AND SDL_VIDEO_OPENGL_EGL) set(SDL_VIDEO_DRIVER_OFFSCREEN 1) - file(GLOB VIDEO_OFFSCREEN_SOURCES ${SDL3_SOURCE_DIR}/src/video/offscreen/*.c) - list(APPEND SOURCE_FILES ${VIDEO_OFFSCREEN_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/offscreen/*.c") set(HAVE_OFFSCREEN TRUE) set(HAVE_SDL_VIDEO TRUE) endif() @@ -2941,108 +2726,68 @@ endif() # src/X/*.c does not get included. if(NOT HAVE_SDL_AUDIO) set(SDL_AUDIO_DRIVER_DUMMY 1) - file(GLOB AUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/dummy/*.c) - list(APPEND SOURCE_FILES ${AUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/dummy/*.c") endif() if(NOT HAVE_SDL_VIDEO) set(SDL_VIDEO_DRIVER_DUMMY 1) - file(GLOB VIDEO_SOURCES ${SDL3_SOURCE_DIR}/src/video/dummy/*.c) - list(APPEND SOURCE_FILES ${VIDEO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/dummy/*.c") endif() if(NOT HAVE_SDL_JOYSTICK) set(SDL_JOYSTICK_DUMMY 1) - file(GLOB JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/dummy/*.c) - list(APPEND SOURCE_FILES ${JOYSTICK_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/dummy/*.c") endif() if(NOT HAVE_SDL_HAPTIC) set(SDL_HAPTIC_DUMMY 1) - file(GLOB HAPTIC_SOURCES ${SDL3_SOURCE_DIR}/src/haptic/dummy/*.c) - list(APPEND SOURCE_FILES ${HAPTIC_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/haptic/dummy/*.c") endif() if(NOT HAVE_SDL_SENSORS) set(SDL_SENSOR_DUMMY 1) - file(GLOB SENSORS_SOURCES ${SDL3_SOURCE_DIR}/src/sensor/dummy/*.c) - list(APPEND SOURCE_FILES ${SENSORS_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/sensor/dummy/*.c") endif() if(NOT HAVE_SDL_LOADSO) set(SDL_LOADSO_DUMMY 1) - file(GLOB LOADSO_SOURCES ${SDL3_SOURCE_DIR}/src/loadso/dummy/*.c) - list(APPEND SOURCE_FILES ${LOADSO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/loadso/dummy/*.c") endif() if(NOT HAVE_SDL_FILESYSTEM) set(SDL_FILESYSTEM_DUMMY 1) - file(GLOB FILESYSTEM_SOURCES ${SDL3_SOURCE_DIR}/src/filesystem/dummy/*.c) - list(APPEND SOURCE_FILES ${FILESYSTEM_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/filesystem/dummy/*.c") endif() if(NOT HAVE_SDL_LOCALE) set(SDL_LOCALE_DUMMY 1) - file(GLOB LOCALE_SOURCES ${SDL3_SOURCE_DIR}/src/locale/dummy/*.c) - list(APPEND SOURCE_FILES ${LOCALE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/locale/dummy/*.c") endif() if(NOT HAVE_SDL_MISC) set(SDL_MISC_DUMMY 1) - file(GLOB MISC_SOURCES ${SDL3_SOURCE_DIR}/src/misc/dummy/*.c) - list(APPEND SOURCE_FILES ${MISC_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/misc/dummy/*.c") endif() # We always need to have threads and timers around if(NOT HAVE_SDL_THREADS) # The emscripten platform has been carefully vetted to work without threads - if (EMSCRIPTEN) + if(EMSCRIPTEN) set(SDL_THREADS_DISABLED 1) - file(GLOB THREADS_SOURCES ${SDL3_SOURCE_DIR}/src/thread/generic/*.c) - list(APPEND SOURCE_FILES ${THREADS_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/thread/generic/*.c") else() - message_error("Threads are needed by many SDL subsystems and may not be disabled") + message(FATAL_ERROR "Threads are needed by many SDL subsystems and may not be disabled") endif() endif() if(NOT HAVE_SDL_TIMERS) set(SDL_TIMER_DUMMY 1) - file(GLOB TIMER_SOURCES ${SDL3_SOURCE_DIR}/src/timer/dummy/*.c) - list(APPEND SOURCE_FILES ${TIMER_SOURCES}) -endif() - -if(SDL_WERROR) - if(MSVC) - check_c_compiler_flag(/WX HAVE_WX) - if(HAVE_WX) - target_compile_options(sdl-global-options INTERFACE "/WX") - endif() - elseif(USE_GCC OR USE_CLANG OR USE_INTELCC OR USE_QNX) - check_c_compiler_flag(-Werror HAVE_WERROR) - if(HAVE_WERROR) - target_compile_options(sdl-global-options INTERFACE "-Werror") - endif() - endif() + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/timer/dummy/*.c") endif() # config variables may contain generator expression, so we need to generate SDL_build_config.h in 2 steps: # 1. replace all `#cmakedefine`'s and `@abc@` configure_file("${SDL3_SOURCE_DIR}/include/build_config/SDL_build_config.h.cmake" "${SDL3_BINARY_DIR}/SDL_build_config.h.intermediate") -# 2. Create the "include-config-${CMAKE_BUILD_TYPE}" folder (fails on older CMake versions when it does not exist) -string(TOLOWER "${CMAKE_BUILD_TYPE}" lower_build_type) -execute_process(COMMAND "${CMAKE_COMMAND}" -E make_directory "${CMAKE_CURRENT_BINARY_DIR}/include-config-${lower_build_type}/build_config") -# 3. generate SDL_build_config.h in an build_type-dependent folder (which should be first in the include search path) +# 2. generate SDL_build_config.h in an build_type-dependent folder (which should be first in the include search path) file(GENERATE - OUTPUT "${SDL3_BINARY_DIR}/include-config-$>/build_config/SDL_build_config.h" - INPUT "${SDL3_BINARY_DIR}/SDL_build_config.h.intermediate") + OUTPUT "${SDL3_BINARY_DIR}/include-config-$>/build_config/SDL_build_config.h" + INPUT "${SDL3_BINARY_DIR}/SDL_build_config.h.intermediate" +) -# Prepare the flags and remove duplicates -if(SDL_EXTRA_LDFLAGS) - list(REMOVE_DUPLICATES SDL_EXTRA_LDFLAGS) -endif() -if(SDL_EXTRA_LIBS) - list(REMOVE_DUPLICATES SDL_EXTRA_LIBS) -endif() -if(EXTRA_CFLAGS) - list(REMOVE_DUPLICATES EXTRA_CFLAGS) -endif() -listtostr(EXTRA_CFLAGS _EXTRA_CFLAGS) -set(EXTRA_CFLAGS ${_EXTRA_CFLAGS}) - -file(GLOB SDL3_INCLUDE_FILES ${SDL3_SOURCE_DIR}/include/SDL3/*.h) -file(GLOB SDL3_TEST_INCLUDE_FILES ${SDL3_SOURCE_DIR}/include/SDL3/SDL_test*.h) +file(GLOB SDL3_INCLUDE_FILES "${SDL3_SOURCE_DIR}/include/SDL3/*.h") +file(GLOB SDL3_TEST_INCLUDE_FILES "${SDL3_SOURCE_DIR}/include/SDL3/SDL_test*.h") foreach(_hdr IN LISTS SDL3_INCLUDE_FILES) if(_hdr MATCHES ".*SDL_revision\\.h" OR _hdr MATCHES ".*SDL_test.*\\.h") list(REMOVE_ITEM SDL3_INCLUDE_FILES "${_hdr}") @@ -3070,7 +2815,7 @@ list(APPEND SDL3_INCLUDE_FILES "${SDL3_BINARY_DIR}/include/SDL3/SDL_revision.h") if(SDL_FRAMEWORK) # With Apple frameworks, headers in the PUBLIC_HEADER property also need to be added as sources list(APPEND SDL3_INCLUDE_FILES ${SDL3_TEST_INCLUDE_FILES}) - list(APPEND SOURCE_FILES ${SDL3_INCLUDE_FILES}) + sdl_sources(${SDL3_INCLUDE_FILES}) endif() if((CMAKE_STATIC_LIBRARY_PREFIX STREQUAL "" AND CMAKE_STATIC_LIBRARY_SUFFIX STREQUAL ".lib") OR SDL_FRAMEWORK) @@ -3082,47 +2827,47 @@ else() endif() macro(check_add_debug_flag FLAG SUFFIX) - check_c_compiler_flag(${FLAG} HAS_C_FLAG_${SUFFIX}) - if (HAS_C_FLAG_${SUFFIX}) - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}") - endif() + check_c_compiler_flag(${FLAG} HAS_C_FLAG_${SUFFIX}) + if(HAS_C_FLAG_${SUFFIX}) + string(APPEND CMAKE_C_FLAGS_DEBUG " ${FLAG}") + endif() - check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX}) - if (HAS_CXX_${SUFFIX}) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}") - endif() + check_cxx_compiler_flag(${FLAG} HAS_CXX_${SUFFIX}) + if(HAS_CXX_${SUFFIX}) + string(APPEND CMAKE_CXX_FLAGS_DEBUG " ${FLAG}") + endif() endmacro() macro(asan_check_add_debug_flag ASAN_FLAG) - check_add_debug_flag("-fsanitize=${ASAN_FLAG}" "${ASAN_FLAG}") - if(HAS_C_${ASAN_FLAG} OR HAS_CXX_${ASAN_FLAG}) - set(HAVE_ASAN ON) - endif() + check_add_debug_flag("-fsanitize=${ASAN_FLAG}" "${ASAN_FLAG}") + if(HAS_C_${ASAN_FLAG} OR HAS_CXX_${ASAN_FLAG}) + set(HAVE_ASAN ON) + endif() endmacro() macro(asan_check_add_debug_flag2 ASAN_FLAG) - # for some sanitize flags we have to manipulate the CMAKE_REQUIRED_LIBRARIES: - # http://cmake.3232098.n2.nabble.com/CHECK-CXX-COMPILER-FLAG-doesn-t-give-correct-result-for-fsanitize-address-tp7600216p7600217.html + # for some sanitize flags we have to manipulate the CMAKE_REQUIRED_LIBRARIES: + # http://cmake.3232098.n2.nabble.com/CHECK-CXX-COMPILER-FLAG-doesn-t-give-correct-result-for-fsanitize-address-tp7600216p7600217.html - set(FLAG "-fsanitize=${ASAN_FLAG}") + set(FLAG "-fsanitize=${ASAN_FLAG}") - cmake_push_check_state() - list(APPEND CMAKE_REQUIRED_LIBRARIES ${FLAG} asan) - check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG}) - check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG}) - cmake_pop_check_state() + cmake_push_check_state() + list(APPEND CMAKE_REQUIRED_LIBRARIES ${FLAG} asan) + check_c_compiler_flag (${FLAG} HAS_C_FLAG_${ASAN_FLAG}) + check_cxx_compiler_flag (${FLAG} HAS_CXX_FLAG_${ASAN_FLAG}) + cmake_pop_check_state() - if (HAS_C_FLAG_${ASAN_FLAG}) - set(CMAKE_C_FLAGS_DEBUG "${CMAKE_C_FLAGS_DEBUG} ${FLAG}") - endif() + if (HAS_C_FLAG_${ASAN_FLAG}) + string(APPEND CMAKE_C_FLAGS_DEBUG " ${FLAG}") + endif() - if (HAS_CXX_${ASAN_FLAG}) - set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${FLAG}") - endif() + if (HAS_CXX_${ASAN_FLAG}) + string(APPEND CMAKE_CXX_FLAGS_DEBUG " ${FLAG}") + endif() - if(HAS_C_${ASAN_FLAG} OR HAS_CXX_${ASAN_FLAG}) - set(HAVE_ASAN ON) - endif() + if(HAS_C_${ASAN_FLAG} OR HAS_CXX_${ASAN_FLAG}) + set(HAVE_ASAN ON) + endif() endmacro() # enable AddressSanitizer if supported @@ -3141,12 +2886,12 @@ if(SDL_ASAN) asan_check_add_debug_flag("leak") # The object size sanitizer has no effect on unoptimized builds on Clang, # but causes warnings. - if((NOT USE_CLANG) OR ("${CMAKE_BUILD_TYPE}" STREQUAL "")) + if(NOT USE_CLANG OR CMAKE_BUILD_TYPE STREQUAL "") asan_check_add_debug_flag("object-size") endif() endif() -if(SDL_CCACHE AND NOT CMAKE_VERSION VERSION_LESS 3.4) +if(SDL_CCACHE) find_program(CCACHE_BINARY ccache) if(CCACHE_BINARY) set(CMAKE_C_COMPILER_LAUNCHER ${CCACHE_BINARY}) @@ -3174,7 +2919,8 @@ if(SDL_CLANG_TIDY) set(CMAKE_C_CLANG_TIDY ${CLANG_TIDY_COMMAND}) set(CMAKE_CXX_CLANG_TIDY ${CLANG_TIDY_COMMAND}) set(CMAKE_OBJC_CLANG_TIDY ${CLANG_TIDY_COMMAND}) - set_source_files_properties(${SOURCE_FILES} PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE) + get_property(shared_sources TARGET SDL3-collector PROPERTY INTERFACE_SOURCES) + set_source_files_properties(${shared_sources} PROPERTIES SKIP_PRECOMPILE_HEADERS TRUE) file(GLOB STDLIB_SOURCES "${SDL3_SOURCE_DIR}/src/stdlib/*.c") set_property(SOURCE ${STDLIB_SOURCES} APPEND PROPERTY COMPILE_DEFINITIONS "SDL_DISABLE_ANALYZE_MACROS") else() @@ -3186,115 +2932,27 @@ if(SDL_TESTS) set(HAVE_TESTS ON) endif() -get_property(INFO_CFLAGS TARGET sdl-build-options PROPERTY INTERFACE_COMPILE_OPTIONS) -list(REMOVE_DUPLICATES INFO_CFLAGS) -listtostr(INFO_CFLAGS INFO_CFLAGS) - -get_property(INFO_INCDIRS TARGET sdl-build-options PROPERTY INTERFACE_INCLUDE_DIRECTORIES) -list(REMOVE_DUPLICATES INFO_INCDIRS) -listtostr(INFO_INCDIRS INFO_INCDIRS "-I") - -get_property(INFO_DEFS TARGET sdl-build-options PROPERTY INTERFACE_COMPILE_DEFINITIONS) -list(REMOVE_DUPLICATES INFO_DEFS) -listtostr(INFO_DEFS INFO_DEFS "-D") - -get_property(INFO_CHECKS TARGET sdl-global-options PROPERTY INTERFACE_COMPILE_OPTIONS) -list(REMOVE_DUPLICATES INFO_CHECKS) -listtostr(INFO_CHECKS INFO_CHECKS) - -listtostr(SDL_EXTRA_LDFLAGS INFO_EXTRA_LDFLAGS) - -get_property(INFO_SHARED_LDFLAGS TARGET sdl-shared-build-options PROPERTY INTERFACE_LINK_LIBRARIES) -list(REMOVE_DUPLICATES INFO_SHARED_LDFLAGS) -listtostr(INFO_SHARED_LDFLAGS INFO_SHARED_LDFLAGS) - -listtostr(SDL_EXTRA_LIBS INFO_EXTRA_LIBS) -listtostr(SDL_CMAKE_DEPENDS INFO_CMAKE_DEPENDS) - -##### Info output ##### -message(STATUS "") -message(STATUS "SDL3 was configured with the following options:") -message(STATUS "") -message(STATUS "Platform: ${CMAKE_SYSTEM}") -message(STATUS "64-bit: ${ARCH_64}") -message(STATUS "Compiler: ${CMAKE_C_COMPILER}") -message(STATUS "Revision: ${SDL_REVISION}") -message(STATUS "") -message(STATUS "Subsystems:") - -find_stringlength_longest_item(SDL_SUBSYSTEMS maxLength) -foreach(_SUB IN LISTS SDL_SUBSYSTEMS) - string(LENGTH ${_SUB} _SUBLEN) - math(EXPR _PADLEN "(${maxLength} + 1) - ${_SUBLEN}") - string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING) - string(TOUPPER ${_SUB} _OPT) - message_bool_option(${_SUB} SDL_${_OPT} ${_PADDING}) -endforeach() -message(STATUS "") -message(STATUS "Options:") -list(SORT ALLOPTIONS) -message_dictlist(ALLOPTIONS) -message(STATUS "") -message(STATUS " CMAKE_C_FLAGS: ${CMAKE_C_FLAGS}") -if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug") - message(STATUS " CMAKE_C_FLAGS_DEBUG: ${CMAKE_C_FLAGS_DEBUG}") - message(STATUS " CMAKE_CXX_FLAGS_DEBUG: ${CMAKE_CXX_FLAGS_DEBUG}") - message(STATUS "") -endif() -message(STATUS " EXTRA DEFS: ${INFO_DEFS}") -message(STATUS " EXTRA CFLAGS: ${INFO_CFLAGS} ${INFO_CHECKS}") -message(STATUS " EXTRA INCDIRS: ${INFO_INCDIRS}") -message(STATUS " EXTRA LDFLAGS: ${INFO_SHARED_LDFLAGS} ${INFO_EXTRA_LDFLAGS}") -message(STATUS " EXTRA LIBS: ${INFO_EXTRA_LIBS} ${INFO_CMAKE_DEPENDS}") -message(STATUS "") -message(STATUS " Build Shared Library: ${SDL_SHARED}") -message(STATUS " Build Static Library: ${SDL_STATIC}") -if(SDL_STATIC) - message(STATUS " Build Static Library with Position Independent Code: ${SDL_STATIC_PIC}") -endif() -if(APPLE) - message(STATUS " Build libraries as Apple Framework: ${SDL_FRAMEWORK}") -endif() -message(STATUS "") -if(UNIX) - message(STATUS "If something was not detected, although the libraries") - message(STATUS "were installed, then make sure you have set the") - message(STATUS "CFLAGS and LDFLAGS environment variables correctly.") - message(STATUS "") -endif() - -if(WARN_ABOUT_ARM_SIMD_ASM_MIT) - message(STATUS "SDL is being built with ARM SIMD optimizations, which") - message(STATUS "uses code licensed under the MIT license. If this is a") - message(STATUS "problem, please disable that code by rerunning CMake with:") - message(STATUS "") - message(STATUS " -DSDL_ARMSIMD=OFF") - message(STATUS "") -endif() - -if(WARN_ABOUT_ARM_NEON_ASM_MIT) - message(STATUS "SDL is being built with ARM NEON optimizations, which") - message(STATUS "uses code licensed under the MIT license. If this is a") - message(STATUS "problem, please disable that code by rerunning CMake with:") - message(STATUS "") - message(STATUS " -DSDL_ARMNEON=OFF") - message(STATUS "") +if(CMAKE_SIZEOF_VOID_P EQUAL 8) + set(ARCH_64 TRUE) +else() + set(ARCH_64 FALSE) endif() if(ANDROID) - target_include_directories(sdl-build-options SYSTEM INTERFACE "${ANDROID_NDK}/sources/android/cpufeatures") + sdl_include_directories(PRIVATE SYSTEM "${ANDROID_NDK}/sources/android/cpufeatures") endif() if(APPLE) - target_compile_options(sdl-build-options INTERFACE "-fobjc-arc") + sdl_compile_options(PRIVATE "-fobjc-arc") endif() if(PS2) - target_compile_options(sdl-build-options INTERFACE "-Wno-error=declaration-after-statement") + sdl_compile_options(PRIVATE "-Wno-error=declaration-after-statement") endif() if(APPLE) - foreach(SOURCE_FILE ${SOURCE_FILES}) + get_property(sources TARGET SDL3-collector PROPERTY INTERFACE_SOURCES) + foreach(SOURCE_FILE IN LISTS sources) get_filename_component(FILE_EXTENSION ${SOURCE_FILE} EXT) if(FILE_EXTENSION STREQUAL ".m") set_property(SOURCE ${SOURCE_FILE} APPEND_STRING PROPERTY COMPILE_FLAGS " -x objective-c") @@ -3313,7 +2971,7 @@ set(SDL_FRAMEWORK_RESOURCES LICENSE.txt ) if(SDL_FRAMEWORK) - list(APPEND SOURCE_FILES ${SDL_FRAMEWORK_RESOURCES}) + sdl_sources(${SDL_FRAMEWORK_RESOURCES}) endif() add_library(SDL3_Headers INTERFACE) @@ -3346,14 +3004,13 @@ else() endif() if(SDL_SHARED) - add_library(SDL3-shared SHARED ${SOURCE_FILES} ${VERSION_SOURCES}) - add_library(SDL3::SDL3-shared ALIAS SDL3-shared) set_target_properties(SDL3-shared PROPERTIES OUTPUT_NAME "SDL3" POSITION_INDEPENDENT_CODE TRUE LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/dynapi/SDL_dynapi.sym" INTERFACE_LINK_DEPENDS "$" WINDOWS_EXPORT_ALL_SYMBOLS FALSE + DEFINE_SYMBOL "DLL_EXPORT" ) if(HAVE_GCC_FVISIBILITY) set_target_properties(SDL3-shared PROPERTIES @@ -3384,46 +3041,39 @@ if(SDL_SHARED) RESOURCE "${SDL_FRAMEWORK_RESOURCES}" ) endif() - if(NOT CMAKE_VERSION VERSION_LESS "3.6") - set_target_properties(SDL3-shared PROPERTIES - SOVERSION "${SDL_DYLIB_COMPAT_VERSION}" # SOVERSION corresponds to compatibility version - VERSION "${SDL_DYLIB_CURRENT_VERSION}" # VERSION corresponds to the current version - ) - endif() + set_target_properties(SDL3-shared PROPERTIES + SOVERSION "${SDL_DYLIB_COMPAT_VERSION}" # SOVERSION corresponds to compatibility version + VERSION "${SDL_DYLIB_CURRENT_VERSION}" # VERSION corresponds to the current version + ) elseif(UNIX AND NOT ANDROID) set_target_properties(SDL3-shared PROPERTIES VERSION "${SDL_SO_VERSION}" - SOVERSION "${SDL_SO_VERSION_MAJOR}") + SOVERSION "${SDL_SO_VERSION_MAJOR}" + ) else() if(WINDOWS OR CYGWIN) set_target_properties(SDL3-shared PROPERTIES - DEFINE_SYMBOL DLL_EXPORT) + PREFIX "" + ) endif() endif() # Note: The clang toolset for Visual Studio does not support /NODEFAULTLIB. if(MSVC AND NOT SDL_LIBC AND NOT MSVC_CLANG AND NOT SDL_CPU_ARM32) # Don't try to link with the default set of libraries. if(NOT WINDOWS_STORE) - set_property(TARGET SDL3-shared APPEND_STRING PROPERTY LINK_FLAGS "/NODEFAULTLIB") + # FIXME: is this needed? "-nodefaultlib:MSVCRT" ia already added when SDL_LIBC is false + target_link_options(SDL3-shared PRIVATE "/NODEFAULTLIB") endif() - set_property(TARGET SDL3-shared APPEND_STRING PROPERTY STATIC_LIBRARY_FLAGS " /NODEFAULTLIB") endif() - # FIXME: if CMAKE_VERSION >= 3.13, use target_link_options for SDL_EXTRA_LDFLAGS - target_link_libraries(SDL3-shared PRIVATE ${SDL_EXTRA_LIBS} ${SDL_EXTRA_LDFLAGS} ${SDL_CMAKE_DEPENDS}) + target_link_libraries(SDL3-shared PRIVATE ${SDL_CMAKE_DEPENDS}) target_include_directories(SDL3-shared PRIVATE "$>>" "$" ) target_link_libraries(SDL3-shared PUBLIC $) - # This picks up all the compiler options and such we've accumulated up to here. - target_link_libraries(SDL3-shared PRIVATE $<${build_local_interface}:sdl-build-options>) - target_link_libraries(SDL3-shared PRIVATE $<${build_local_interface}:sdl-shared-build-options>) - target_link_libraries(SDL3-shared PRIVATE $<${build_local_interface}:sdl-global-options>) if(MINGW OR CYGWIN) - if(NOT CMAKE_VERSION VERSION_LESS "3.13") - target_link_options(SDL3-shared PRIVATE -static-libgcc) - endif() + target_link_options(SDL3-shared PRIVATE -static-libgcc) endif() # Use `Compatible Interface Properties` to: # - allow consumers to enforce a shared/static library @@ -3438,8 +3088,6 @@ if(SDL_SHARED) endif() if(SDL_STATIC) - add_library(SDL3-static STATIC ${SOURCE_FILES}) - add_library(SDL3::SDL3-static ALIAS SDL3-static) set_target_properties(SDL3-static PROPERTIES OUTPUT_NAME "${sdl_static_libname}" POSITION_INDEPENDENT_CODE "${SDL_STATIC_PIC}" @@ -3457,16 +3105,13 @@ if(SDL_STATIC) endif() endif() target_compile_definitions(SDL3-static PRIVATE SDL_STATIC_LIB) - target_link_libraries(SDL3-static PRIVATE ${SDL_EXTRA_LIBS} ${SDL_EXTRA_LDFLAGS} ${SDL_CMAKE_DEPENDS}) + target_link_libraries(SDL3-static PRIVATE ${SDL_CMAKE_DEPENDS}) target_include_directories(SDL3-static PRIVATE "$>>" "$" ) target_link_libraries(SDL3-static PUBLIC $) - # This picks up all the compiler options and such we've accumulated up to here. - target_link_libraries(SDL3-static PRIVATE $<${build_local_interface}:sdl-build-options>) - target_link_libraries(SDL3-static PRIVATE $<${build_local_interface}:sdl-global-options>) # Use `Compatible Interface Properties` to: # - allow consumers to enforce a shared/static library # - block linking to SDL libraries of different major version @@ -3479,19 +3124,18 @@ if(SDL_STATIC) endif() endif() -target_compile_definitions(sdl-build-options INTERFACE - "SDL_BUILD_MAJOR_VERSION=${PROJECT_VERSION_MAJOR}" - "SDL_BUILD_MINOR_VERSION=${PROJECT_VERSION_MINOR}" - "SDL_BUILD_MICRO_VERSION=${PROJECT_VERSION_PATCH}" +sdl_compile_definitions( + PRIVATE + "SDL_BUILD_MAJOR_VERSION=${PROJECT_VERSION_MAJOR}" + "SDL_BUILD_MINOR_VERSION=${PROJECT_VERSION_MINOR}" + "SDL_BUILD_MICRO_VERSION=${PROJECT_VERSION_PATCH}" ) ##### Tests ##### if(SDL_TEST) - file(GLOB TEST_SOURCES ${SDL3_SOURCE_DIR}/src/test/*.c) - add_library(SDL3_test STATIC ${TEST_SOURCES}) - add_library(SDL3::SDL3_test ALIAS SDL3_test) - target_link_libraries(SDL3_test PRIVATE $<${build_local_interface}:sdl-global-options>) + file(GLOB TEST_SOURCES "${SDL3_SOURCE_DIR}/src/test/*.c") + target_sources(SDL3_test PRIVATE ${TEST_SOURCES}) if(APPLE) set_target_properties(SDL3_test PROPERTIES FRAMEWORK "${SDL_FRAMEWORK}" @@ -3504,11 +3148,8 @@ if(SDL_TEST) ) endif() endif() - target_include_directories(SDL3_test - PRIVATE - "$>>" - ) target_link_libraries(SDL3_test PUBLIC $) + # FIXME: get rid of EXTRA_TEST_LIBS variable target_link_libraries(SDL3_test PRIVATE ${EXTRA_TEST_LIBS}) set_property(TARGET SDL3_test APPEND PROPERTY COMPATIBLE_INTERFACE_STRING "SDL_VERSION") set_property(TARGET SDL3_test PROPERTY INTERFACE_SDL_VERSION "SDL${SDL3_VERSION_MAJOR}") @@ -3572,27 +3213,30 @@ else() set(SDL_SDLtest_INSTALL_RESOURCEDIR ".") set(SDL_SDLtest_INSTALL_CMAKEDIR "${SDL_SDL_INSTALL_CMAKEDIR}") set(SDL_SDLtest_INSTALL_CMAKEFILENAME "SDL3testTargets.cmake") - endif() - -if(CMAKE_VERSION VERSION_LESS "3.26") - file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/SDL3sharedTargets.cmake" [[message(FATAL_ERROR "find_package(SDL3) using the SDL3 build directory not supported for CMake versions older then 3.26.")]]) -else() - export(TARGETS SDL3_Headers NAMESPACE "SDL3::" FILE "SDL3headersTargets.cmake") - - if(SDL_SHARED) - export(TARGETS SDL3-shared NAMESPACE "SDL3::" FILE "SDL3sharedTargets.cmake") - endif() - - if(SDL_STATIC) - export(TARGETS SDL3-static NAMESPACE "SDL3::" FILE "SDL3staticTargets.cmake") - endif() - - if(SDL_TEST) - export(TARGETS SDL3_test NAMESPACE "SDL3::" FILE "SDL3testTargets.cmake") - endif() endif() -configure_file("cmake/sdlfind.cmake" "sdlfind.cmake" COPYONLY) +export(TARGETS SDL3_Headers NAMESPACE "SDL3::" FILE "SDL3headersTargets.cmake") + +if(SDL_SHARED) + export(TARGETS SDL3-shared NAMESPACE "SDL3::" FILE "SDL3sharedTargets.cmake") +endif() + +if(SDL_STATIC) + export(TARGETS SDL3-static NAMESPACE "SDL3::" FILE "SDL3staticTargets.cmake") +endif() + +if(SDL_TEST) + export(TARGETS SDL3_test NAMESPACE "SDL3::" FILE "SDL3testTargets.cmake") +endif() + +sdl_cmake_config_find_pkg_config_commands(SDL_FIND_PKG_CONFIG_COMMANDS + COLLECTOR SDL3-collector + CONFIG_COMPONENT_FOUND_NAME SDL3_SDL3-static_FOUND +) +sdl_cmake_config_find_pkg_config_commands(SDL_TEST_FIND_PKG_CONFIG_COMMANDS + COLLECTOR SDL3_test-collector + CONFIG_COMPONENT_FOUND_NAME SDL3_SDL3_test_FOUND +) include(CMakePackageConfigHelpers) configure_package_config_file(cmake/SDL3Config.cmake.in SDL3Config.cmake @@ -3603,43 +3247,15 @@ write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/SDL3ConfigVersion. COMPATIBILITY AnyNewerVersion ) +sdl_cmake_config_required_modules(sdl_cmake_modules) +if(sdl_cmake_modules) + execute_process(COMMAND ${CMAKE_COMMAND} -E copy_if_different ${sdl_cmake_modules} "${SDL3_BINARY_DIR}") +endif() + if(NOT SDL_DISABLE_INSTALL) ##### sdl3.pc ##### - - # Clean up variables for sdl3.pc - if(SDL_SHARED) - set(PKGCONFIG_LIBS_PRIV "\nLibs.private:") - else() - set(PKGCONFIG_LIBS_PRIV "") - endif() - - # Clean up the different lists - listtostr(SDL_EXTRA_LIBS EXTRA_LIBS_L "-l") - set(SDL_PC_STATIC_LIBS ${SDL_EXTRA_LDFLAGS} ${EXTRA_LIBS_L}) - list(REMOVE_DUPLICATES SDL_PC_STATIC_LIBS) - listtostr(SDL_PC_STATIC_LIBS SDL_PC_STATIC_LIBS) - listtostr(SDL_PC_LIBS SDL_PC_LIBS) - listtostr(SDL_PC_CFLAGS SDL_PC_CFLAGS) - listtostr(SDL_PC_PRIVATE_REQUIRES SDL_PC_PRIVATE_REQUIRES) - string(REGEX REPLACE "-lSDL3( |$)" "-l${sdl_static_libname} " SDL_PC_STATIC_LIBS "${SDL_PC_STATIC_LIBS}") - if(NOT SDL_SHARED) - string(REGEX REPLACE "-lSDL3( |$)" "-l${sdl_static_libname} " SDL_PC_LIBS "${SDL_PC_LIBS}") - endif() - - if(SDL_STATIC AND SDL_SHARED AND NOT sdl_static_libname STREQUAL "SDL3") - message(STATUS "\"pkg-config --static --libs sdl3\" will return invalid information") - endif() - - file(RELATIVE_PATH SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG "${CMAKE_INSTALL_PREFIX}/${SDL_PKGCONFIG_INSTALLDIR}" "${CMAKE_INSTALL_PREFIX}") - string(REGEX REPLACE "[/]+$" "" SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG "${SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG}") - set(SDL_PKGCONFIG_PREFIX "\${pcfiledir}/${SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG}") - - # message(STATUS "SDL_PC_CFLAGS: ${SDL_PC_CFLAGS}") - # message(STATUS "SDL_PC_LIBS: ${SDL_PC_LIBS}") - # message(STATUS "SDL_PC_STATIC_LIBS: ${SDL_PC_STATIC_LIBS}") - - configure_file(cmake/sdl3.pc.in sdl3.pc @ONLY) + configure_sdl3_pc() if(NOT SDL_FRAMEWORK) install(FILES ${SDL3_BINARY_DIR}/sdl3.pc DESTINATION "${SDL_PKGCONFIG_INSTALLDIR}") endif() @@ -3710,7 +3326,7 @@ if(NOT SDL_DISABLE_INSTALL) install(FILES ${CMAKE_CURRENT_BINARY_DIR}/SDL3Config.cmake ${CMAKE_CURRENT_BINARY_DIR}/SDL3ConfigVersion.cmake - ${SDL3_SOURCE_DIR}/cmake/sdlfind.cmake + ${sdl_cmake_modules} DESTINATION "${SDL_SDL_INSTALL_REAL_CMAKEDIR}" ) @@ -3788,11 +3404,7 @@ if(SDL_TESTS) endif() ##### Fix Objective C builds ##### -set(CMAKE_OBJC_FLAGS "${CMAKE_OBJC_FLAGS} ${CMAKE_C_FLAGS}") +string(APPEND CMAKE_OBJC_FLAGS " ${CMAKE_C_FLAGS}") -# Make sure SDL3::SDL3 always exists -if(TARGET SDL3::SDL3-shared) - add_library(SDL3::SDL3 ALIAS SDL3-shared) -else() - add_library(SDL3::SDL3 ALIAS SDL3-static) -endif() +SDL_PrintSummary() +debug_show_sdl_deps() diff --git a/cmake/FindRPi_BcmHost.cmake b/cmake/FindRPi_BcmHost.cmake new file mode 100644 index 000000000..fe0b06611 --- /dev/null +++ b/cmake/FindRPi_BcmHost.cmake @@ -0,0 +1,75 @@ +include(FeatureSummary) +set_package_properties(RPi_BcmHost PROPERTIES + URL "https://github.com/raspberrypi/firmware" + DESCRIPTION "Broadcom VideoCore host API library" +) + +set(RPi_BcmHost_PKG_CONFIG_SPEC bcm_host) + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_RPi_BcmHost QUIET ${RPi_BcmHost_PKG_CONFIG_SPEC}) + +find_library(RPi_BcmHost_bcm_host_LIBRARY + NAMES bcm_host + HINTS + ${PC_RPi_BcmHost_LIBRARY_DIRS} + /opt/vc/lib +) + +find_path(RPi_BcmHost_bcm_host_h_PATH + NAMES bcm_host.h + HINTS + ${PC_RPi_BcmHost_INCLUDE_DIRS} + /opt/vc/include +) + +if(PC_RPi_BcmHost_FOUND) + include("${CMAKE_CURRENT_LIST_DIR}/PkgConfigHelper.cmake") + get_flags_from_pkg_config("${RPi_BcmHost_bcm_host_LIBRARY}" "PC_RPi_BcmHost" "_RPi_BcmHost") +else() + set(_RPi_BcmHost_include_dirs + /opt/vc/include + /opt/vc/include/interface/vcos/pthreads + /opt/vc/include/interface/vmcs_host/linux + ) + set(_RPi_BcmHost_compile_options + -DUSE_VCHIQ_ARM + ) + set(_RPi_BcmHost_link_libraries + -lvcos -lvchiq_arm + ) + set(_RPi_BcmHost_link_options + -pthread + ) + set(_RPi_BcmHost_link_directories + /opt/vc/lib + ) +endif() + +set(RPi_BcmHost_INCLUDE_DIRS "${_RPi_BcmHost_include_dirs}" CACHE STRING "Extra include dirs of bcm_host") + +set(RPi_BcmHost_COMPILE_OPTIONS "${_RPi_BcmHost_compile_options}" CACHE STRING "Extra compile options of bcm_host") + +set(RPi_BcmHost_LINK_LIBRARIES "${_RPi_BcmHost_link_libraries}" CACHE STRING "Extra link libraries of bcm_host") + +set(RPi_BcmHost_LINK_OPTIONS "${_RPi_BcmHost_link_options}" CACHE STRING "Extra link flags of bcm_host") + +set(RPi_BcmHost_LINK_DIRECTORIES "${_RPi_BcmHost_link_directories}" CACHE PATH "Extra link directories of bcm_host") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(RPi_BcmHost + REQUIRED_VARS RPi_BcmHost_bcm_host_LIBRARY RPi_BcmHost_bcm_host_h_PATH +) + +if(RPi_BcmHost_FOUND) + if(NOT TARGET RPi_BcmHost::RPi_BcmHost) + add_library(RPi_BcmHost::RPi_BcmHost INTERFACE IMPORTED) + set_target_properties(RPi_BcmHost::RPi_BcmHost PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${RPi_BcmHost_INCLUDE_DIRS}" + INTERFACE_COMPILE_OPTIONS "${RPi_BcmHost_COMPILE_OPTIONS}" + INTERFACE_LINK_LIBRARIES "${RPi_BcmHost_LINK_LIBRARIES}" + INTERFACE_LINK_OPTIONS "${RPi_BcmHost_LINK_OPTIONS}" + INTERFACE_LINK_DIRECTORIES "${RPi_BcmHost_LINK_DIRECTORIES}" + ) + endif() +endif() diff --git a/cmake/FindRPi_BrcmEGL.cmake b/cmake/FindRPi_BrcmEGL.cmake new file mode 100644 index 000000000..be4a44782 --- /dev/null +++ b/cmake/FindRPi_BrcmEGL.cmake @@ -0,0 +1,59 @@ +include(FeatureSummary) +set_package_properties(RPi_BrcmEGL PROPERTIES + URL "https://github.com/raspberrypi/firmware" + DESCRIPTION "Fake brcmEGL package for RPi" +) + +set(RPi_BrcmEGL_PKG_CONFIG_SPEC brcmegl) + +find_package(PkgConfig QUIET) +pkg_check_modules(PC_RPi_BrcmEGL QUIET ${RPi_BrcmEGL_PKG_CONFIG_SPEC}) + +find_package(RPi_BcmHost) + +find_library(RPi_BrcmEGL_brcmEGL_LIBRARY + NAMES brcmEGL + HINTS + ${PC_RPi_BrcmEGL_LIBRARY_DIRS} + /opt/vc/lib +) + +find_path(RPi_BrcmEGL_EGL_eglplatform_h_PATH + NAMES EGL/eglplatform.h + HINTS + ${PC_RPi_BrcmEGL_INCLUDE_DIRS} + /opt/vc/include +) + +if(PC_RPi_BrcmEGL_FOUND) + include("${CMAKE_CURRENT_LIST_DIR}/PkgConfigHelper.cmake") + get_flags_from_pkg_config("${RPi_BrcmEGL_brcmEGL_LIBRARY}" "PC_RPi_BrcmEGL" "_RPi_BrcmEGL") +endif() + +set(RPi_BrcmEGL_INCLUDE_DIRS "${_RPi_BrcmEGL_include_dirs}" CACHE STRING "Extra include dirs of brcmEGL") + +set(RPi_BrcmEGL_COMPILE_OPTIONS "${_RPi_BrcmEGL_compile_options}" CACHE STRING "Extra compile options of brcmEGL") + +set(RPi_BrcmEGL_LINK_LIBRARIES "${_RPi_BrcmEGL_link_libraries}" CACHE STRING "Extra link libraries of brcmEGL") + +set(RPi_BrcmEGL_LINK_OPTIONS "${_RPi_BrcmEGL_link_options}" CACHE STRING "Extra link flags of brcmEGL") + +set(RPi_BrcmEGL_LINK_DIRECTORIES "${_RPi_BrcmEGL_link_directories}" CACHE PATH "Extra link directories of brcmEGL") + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(RPi_BrcmEGL + REQUIRED_VARS RPi_BrcmEGL_brcmEGL_LIBRARY RPi_BrcmEGL_EGL_eglext_brcm_h_PATH RPi_BcmHost_FOUND +) + +if(RPi_BrcmEGL_FOUND) + if(NOT TARGET RPi_BcmHost::RPi_BcmHost) + add_library(RPi_BcmHost::RPi_BcmHost INTERFACE IMPORTED) + set_target_properties(RPi_BcmHost::RPi_BcmHost PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${RPi_BrcmEGL_INCLUDE_DIRS}" + INTERFACE_COMPILE_OPTIONS "${RPi_BrcmEGL_COMPILE_OPTIONS}" + INTERFACE_LINK_LIBRARIES "${RPi_BrcmEGL_LINK_LIBRARIES};RPi_BcmHost::RPi_BcmHost" + INTERFACE_LINK_OPTIONS "${RPi_BrcmEGL_LINK_OPTIONS}" + INTERFACE_LINK_DIRECTORIES "${RPi_BrcmEGL_LINK_DIRECTORIES}" + ) + endif() +endif() diff --git a/cmake/PkgConfigHelper.cmake b/cmake/PkgConfigHelper.cmake new file mode 100644 index 000000000..c25fbd518 --- /dev/null +++ b/cmake/PkgConfigHelper.cmake @@ -0,0 +1,39 @@ +# Helper for Find modules + +function(get_flags_from_pkg_config _library _pc_prefix _out_prefix) + if("${_library}" MATCHES "${CMAKE_STATIC_LIBRARY_SUFFIX}$") + set(_include_dirs ${_pc_prefix}_STATIC_INCLUDE_DIRS) + set(_cflags ${_pc_prefix}_STATIC_CFLAGS_OTHER) + set(_link_libraries ${_pc_prefix}_STATIC_LIBRARIES) + set(_link_options ${_pc_prefix}_STATIC_LDFLAGS_OTHER) + set(_library_dirs ${_pc_prefix}_STATIC_LIBRARY_DIRS) + else() + set(_include_dirs ${_pc_prefix}_INCLUDE_DIRS) + set(_cflags ${_pc_prefix}_CFLAGS_OTHER) + set(_link_libraries ${_pc_prefix}_LIBRARIES) + set(_link_options ${_pc_prefix}_LDFLAGS_OTHER) + set(_library_dirs ${_pc_prefix}_LIBRARY_DIRS) + endif() + + # The *_LIBRARIES lists always start with the library itself + list(POP_FRONT "${_link_libraries}") + + # Work around CMake's flag deduplication when pc files use `-framework A` instead of `-Wl,-framework,A` + string(REPLACE "-framework;" "-Wl,-framework," "_filtered_link_options" "${${_link_options}}") + + set(${_out_prefix}_include_dirs + "${${_include_dirs}}" + PARENT_SCOPE) + set(${_out_prefix}_compile_options + "${${_cflags}}" + PARENT_SCOPE) + set(${_out_prefix}_link_libraries + "${${_link_libraries}}" + PARENT_SCOPE) + set(${_out_prefix}_link_options + "${_filtered_link_options}" + PARENT_SCOPE) + set(${_out_prefix}_link_directories + "${${_library_dirs}}" + PARENT_SCOPE) +endfunction() diff --git a/cmake/SDL3Config.cmake.in b/cmake/SDL3Config.cmake.in index 18bce2706..d8b029d4f 100644 --- a/cmake/SDL3Config.cmake.in +++ b/cmake/SDL3Config.cmake.in @@ -23,19 +23,28 @@ if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3sharedTargets.cmake") set(SDL3_SDL3-shared_FOUND TRUE) endif() +macro(find_sdl3_static_dependencies) +@SDL_FIND_PKG_CONFIG_COMMANDS@ +endmacro() + # Find SDL3::SDL3-static if(_sdl3_framework) + set(SDL3_SDL3-static_FOUND TRUE) + find_sdl3_static_dependencies() find_package(SDL3-static CONFIG) - if(SDL3-static_FOUND) + if(SDL3_SDL3-static_FOUND AND SDL3-static_FOUND) set(SDL3_SDL3-static_FOUND TRUE) endif() else() if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3staticTargets.cmake") - if(ANDROID OR HAIKU) - enable_language(CXX) - endif() - include("${CMAKE_CURRENT_LIST_DIR}/SDL3staticTargets.cmake") set(SDL3_SDL3-static_FOUND TRUE) + find_sdl3_static_dependencies() + if(SDL3_SDL3-static_FOUND) + if(ANDROID OR HAIKU) + enable_language(CXX) + endif() + include("${CMAKE_CURRENT_LIST_DIR}/SDL3staticTargets.cmake") + endif() endif() endif() @@ -52,21 +61,14 @@ if(_sdl3_framework) endif() else() if(EXISTS "${CMAKE_CURRENT_LIST_DIR}/SDL3testTargets.cmake") - include("${CMAKE_CURRENT_LIST_DIR}/SDL3testTargets.cmake") set(SDL3_SDL3_test_FOUND TRUE) +@SDL_TEST_FIND_PKG_CONFIG_COMMANDS@ + if(SDL3_SDL3_test_FOUND) + include("${CMAKE_CURRENT_LIST_DIR}/SDL3testTargets.cmake") + endif() endif() endif() -include("${CMAKE_CURRENT_LIST_DIR}/sdlfind.cmake") - -set(SDL_ALSA @SDL_ALSA@) -set(SDL_ALSA_SHARED @SDL_ALSA_SHARED@) -if(SDL_ALSA AND NOT SDL_ALSA_SHARED AND TARGET SDL3::SDL3-static) - sdlFindALSA() -endif() -unset(SDL_ALSA) -unset(SDL_ALSA_SHARED) - check_required_components(SDL3) function(_sdl_create_target_alias_compat NEW_TARGET TARGET) diff --git a/cmake/macros.cmake b/cmake/macros.cmake index 65b6cc9c8..32fc9f1a1 100644 --- a/cmake/macros.cmake +++ b/cmake/macros.cmake @@ -1,9 +1,5 @@ macro(add_to_alloptions _NEWNAME) list(APPEND ALLOPTIONS ${_NEWNAME}) - string(LENGTH ${_NEWNAME} _SLEN) - if(${LONGESTOPTIONNAME} LESS ${_SLEN}) - set(LONGESTOPTIONNAME ${_SLEN}) - endif() endmacro() macro(set_option _NAME _DESC) @@ -27,15 +23,6 @@ macro(option_string _NAME _DESC _VALUE) set(HAVE_${_NAME} ${_VALUE}) ENDMACRO() -# Message Output -macro(message_warn _TEXT) - message(WARNING "${_TEXT}") -endmacro() - -macro(message_error _TEXT) - message(FATAL_ERROR "*** ERROR: ${_TEXT}") -endmacro() - macro(message_bool_option _NAME _VALUE) set(_PAD "\t") if(${ARGC} EQUAL 3) @@ -68,27 +55,6 @@ macro(message_tested_option _NAME) message(STATUS " ${_NAME}${_PAD}(Wanted: ${_REQVALUE}): ${HAVE_${_STRIPPEDNAME}}") endmacro() -function(listtostr LIST OUTPUT) - if(${ARGC} EQUAL 3) - # prefix for each element - set(LPREFIX ${ARGV2}) - else() - set(LPREFIX "") - endif() - # Do not use string(REPLACE ";" " ") here to avoid messing up list entries - set(res) - foreach(ITEM ${${LIST}}) - if(ITEM MATCHES "^SHELL:") - string(SUBSTRING "${ITEM}" 6 -1 ITEM) - endif() - if(ITEM) - set(res "${res} ${LPREFIX}${ITEM}") - endif() - endforeach() - string(STRIP "${res}" res) - set(${OUTPUT} "${res}" PARENT_SCOPE) -endfunction() - function(find_stringlength_longest_item inList outLength) set(maxLength 0) foreach(item IN LISTS ${inList}) @@ -111,22 +77,9 @@ function(message_dictlist inList) endforeach() endfunction() -if(CMAKE_VERSION VERSION_LESS 3.16.0 OR SDL3_SUBPROJECT) - # - CMake versions <3.16 do not support the OBJC language - # - When SDL is built as a subproject and when the main project does not enable OBJC, - # CMake fails due to missing internal CMake variables (CMAKE_OBJC_COMPILE_OBJECT) - # (reproduced with CMake 3.24.2) - macro(CHECK_OBJC_SOURCE_COMPILES SOURCE VAR) - set(PREV_REQUIRED_DEFS "${CMAKE_REQUIRED_DEFINITIONS}") - set(CMAKE_REQUIRED_DEFINITIONS "-x objective-c ${PREV_REQUIRED_DEFS}") - CHECK_C_SOURCE_COMPILES("${SOURCE}" ${VAR}) - set(CMAKE_REQUIRED_DEFINITIONS "${PREV_REQUIRED_DEFS}") - endmacro() -else() +if(APPLE) include(CheckOBJCSourceCompiles) - if (APPLE) - enable_language(OBJC) - endif() + enable_language(OBJC) endif() if(CMAKE_VERSION VERSION_LESS 3.18) @@ -156,8 +109,63 @@ if(APPLE) endif() endif() -if(CMAKE_VERSION VERSION_LESS 3.13.0) - macro(target_link_directories _TARGET _SCOPE) - link_directories(${ARGN}) - endmacro() -endif() +function(SDL_PrintSummary) + ##### Info output ##### + message(STATUS "") + message(STATUS "SDL3 was configured with the following options:") + message(STATUS "") + message(STATUS "Platform: ${CMAKE_SYSTEM}") + message(STATUS "64-bit: ${ARCH_64}") + message(STATUS "Compiler: ${CMAKE_C_COMPILER}") + message(STATUS "Revision: ${SDL_REVISION}") + message(STATUS "Vendor: ${SDL_VENDOR_INFO}") + message(STATUS "") + message(STATUS "Subsystems:") + + find_stringlength_longest_item(SDL_SUBSYSTEMS maxLength) + foreach(_SUB IN LISTS SDL_SUBSYSTEMS) + string(LENGTH ${_SUB} _SUBLEN) + math(EXPR _PADLEN "(${maxLength} + 1) - ${_SUBLEN}") + string(RANDOM LENGTH ${_PADLEN} ALPHABET " " _PADDING) + string(TOUPPER ${_SUB} _OPT) + message_bool_option(${_SUB} SDL_${_OPT} ${_PADDING}) + endforeach() + message(STATUS "") + message(STATUS "Options:") + list(SORT ALLOPTIONS) + message_dictlist(ALLOPTIONS) + message(STATUS "") + message(STATUS " Build Shared Library: ${SDL_SHARED}") + message(STATUS " Build Static Library: ${SDL_STATIC}") + if(SDL_STATIC) + message(STATUS " Build Static Library with Position Independent Code: ${SDL_STATIC_PIC}") + endif() + if(APPLE) + message(STATUS " Build libraries as Apple Framework: ${SDL_FRAMEWORK}") + endif() + message(STATUS "") + if(UNIX) + message(STATUS "If something was not detected, although the libraries") + message(STATUS "were installed, then make sure you have set the") + message(STATUS "CMAKE_C_FLAGS and CMAKE_PREFIX_PATH CMake variables correctly.") + message(STATUS "") + endif() + + if(WARN_ABOUT_ARM_SIMD_ASM_MIT) + message(STATUS "SDL is being built with ARM SIMD optimizations, which") + message(STATUS "uses code licensed under the MIT license. If this is a") + message(STATUS "problem, please disable that code by rerunning CMake with:") + message(STATUS "") + message(STATUS " -DSDL_ARMSIMD=OFF") + message(STATUS "") + endif() + + if(WARN_ABOUT_ARM_NEON_ASM_MIT) + message(STATUS "SDL is being built with ARM NEON optimizations, which") + message(STATUS "uses code licensed under the MIT license. If this is a") + message(STATUS "problem, please disable that code by rerunning CMake with:") + message(STATUS "") + message(STATUS " -DSDL_ARMNEON=OFF") + message(STATUS "") + endif() +endfunction() diff --git a/cmake/sdl3.pc.in b/cmake/sdl3.pc.in index d6ab62ede..5069c90d6 100644 --- a/cmake/sdl3.pc.in +++ b/cmake/sdl3.pc.in @@ -1,5 +1,3 @@ -# sdl pkg-config source file - prefix=@SDL_PKGCONFIG_PREFIX@ exec_prefix=${prefix} libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ @@ -7,8 +5,9 @@ includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ Name: sdl3 Description: Simple DirectMedia Layer is a cross-platform multimedia library designed to provide low level access to audio, keyboard, mouse, joystick, 3D hardware via OpenGL, and 2D video framebuffer. +URL: https://www.libsdl.org/ Version: @PROJECT_VERSION@ Requires.private: @SDL_PC_PRIVATE_REQUIRES@ Conflicts: -Libs: -L${libdir} @SDL_RLD_FLAGS@ @SDL_PC_LIBS@ @PKGCONFIG_LIBS_PRIV@ @SDL_PC_STATIC_LIBS@ +Libs: -L${libdir} @SDL_RLD_FLAGS@ @SDL_PC_LIBS@ @SDL_PC_SECTION_LIBS_PRIVATE@ @SDL_PC_STATIC_LIBS@ Cflags: -I${includedir} -I${includedir}/SDL3 @SDL_PC_CFLAGS@ diff --git a/cmake/sdlchecks.cmake b/cmake/sdlchecks.cmake index 13a777921..20bb1d8f4 100644 --- a/cmake/sdlchecks.cmake +++ b/cmake/sdlchecks.cmake @@ -1,11 +1,12 @@ macro(FindLibraryAndSONAME _LIB) - cmake_parse_arguments(FLAS "" "" "LIBDIRS" ${ARGN}) + cmake_parse_arguments(_FLAS "" "" "LIBDIRS" ${ARGN}) string(TOUPPER ${_LIB} _UPPERLNAME) string(REGEX REPLACE "\\-" "_" _LNAME "${_UPPERLNAME}") - find_library(${_LNAME}_LIB ${_LIB} PATHS ${FLAS_LIBDIRS}) + find_library(${_LNAME}_LIB ${_LIB} PATHS ${_FLAS_LIBDIRS}) + # FIXME: fail FindLibraryAndSONAME when library is not shared. if(${_LNAME}_LIB MATCHES ".*\\${CMAKE_SHARED_LIBRARY_SUFFIX}.*" AND NOT ${_LNAME}_LIB MATCHES ".*\\${CMAKE_STATIC_LIBRARY_SUFFIX}.*") set(${_LNAME}_SHARED TRUE) else() @@ -16,6 +17,7 @@ macro(FindLibraryAndSONAME _LIB) # reduce the library name for shared linking get_filename_component(_LIB_REALPATH ${${_LNAME}_LIB} REALPATH) # resolves symlinks + get_filename_component(_LIB_LIBDIR ${_LIB_REALPATH} DIRECTORY) get_filename_component(_LIB_JUSTNAME ${_LIB_REALPATH} NAME) if(APPLE) @@ -24,20 +26,20 @@ macro(FindLibraryAndSONAME _LIB) string(REGEX REPLACE "(\\.[0-9]*)\\.[0-9\\.]*$" "\\1" _LIB_REGEXD "${_LIB_JUSTNAME}") endif() - get_filename_component(${_LNAME}_LIBDIR ${${_LNAME}_LIB} DIRECTORY) - - SET(_DEBUG_FindSONAME FALSE) - if(_DEBUG_FindSONAME) - message_warn("DYNLIB OUTPUTVAR: ${_LIB} ... ${_LNAME}_LIB") - message_warn("DYNLIB ORIGINAL LIB: ${_LIB} ... ${${_LNAME}_LIB}") - message_warn("DYNLIB REALPATH LIB: ${_LIB} ... ${_LIB_REALPATH}") - message_warn("DYNLIB JUSTNAME LIB: ${_LIB} ... ${_LIB_JUSTNAME}") - message_warn("DYNLIB REGEX'd LIB: ${_LIB} ... ${_LIB_REGEXD}") + if(NOT EXISTS "${_LIB_LIBDIR}/${_LIB_REGEXD}") + set(_LIB_REGEXD "${_LIB_JUSTNAME}") endif() + set(${_LNAME}_LIBDIR "${_LIB_LIBDIR}") message(STATUS "dynamic lib${_LIB} -> ${_LIB_REGEXD}") set(${_LNAME}_LIB_SONAME ${_LIB_REGEXD}) endif() + + message(DEBUG "DYNLIB OUTPUTVAR: ${_LIB} ... ${_LNAME}_LIB") + message(DEBUG "DYNLIB ORIGINAL LIB: ${_LIB} ... ${${_LNAME}_LIB}") + message(DEBUG "DYNLIB REALPATH LIB: ${_LIB} ... ${_LIB_REALPATH}") + message(DEBUG "DYNLIB JUSTNAME LIB: ${_LIB} ... ${_LIB_JUSTNAME}") + message(DEBUG "DYNLIB SONAME LIB: ${_LIB} ... ${_LIB_REGEXD}") endmacro() macro(CheckDLOPEN) @@ -48,7 +50,7 @@ macro(CheckDLOPEN) check_symbol_exists(dlopen "dlfcn.h" HAVE_DLOPEN_IN_LIBDL) cmake_pop_check_state() if(HAVE_DLOPEN_IN_LIBDL) - list(APPEND SDL_EXTRA_LIBS dl) + sdl_link_dependency(dl LIBS dl) endif() endif() if(HAVE_DLOPEN_IN_LIBC OR HAVE_DLOPEN_IN_LIBDL) @@ -73,11 +75,10 @@ macro(CheckOSS) if(HAVE_OSS_SYS_SOUNDCARD_H) set(HAVE_OSS TRUE) - file(GLOB OSS_SOURCES ${SDL3_SOURCE_DIR}/src/audio/dsp/*.c) + sdl_glob_sources(${SDL3_SOURCE_DIR}/src/audio/dsp/*.c) set(SDL_AUDIO_DRIVER_OSS 1) - list(APPEND SOURCE_FILES ${OSS_SOURCES}) if(NETBSD) - list(APPEND SDL_EXTRA_LIBS ossaudio) + sdl_link_dependency(oss LIBS ossaudio) endif() set(HAVE_SDL_AUDIO TRUE) endif() @@ -91,10 +92,10 @@ endmacro() # - HAVE_SDL_LOADSO opt macro(CheckALSA) if(SDL_ALSA) - sdlFindALSA() + set(ALSA_PKG_CONFIG_SPEC "alsa") + find_package(ALSA MODULE) if(ALSA_FOUND) - file(GLOB ALSA_SOURCES "${SDL3_SOURCE_DIR}/src/audio/alsa/*.c") - list(APPEND SOURCE_FILES ${ALSA_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/alsa/*.c") set(SDL_AUDIO_DRIVER_ALSA 1) set(HAVE_ALSA TRUE) set(HAVE_ALSA_SHARED FALSE) @@ -102,7 +103,7 @@ macro(CheckALSA) if(HAVE_SDL_LOADSO) FindLibraryAndSONAME("asound") if(ASOUND_LIB AND ASOUND_SHARED) - target_include_directories(sdl-build-options INTERFACE $) + sdl_link_dependency(alsa INCLUDES $) set(SDL_AUDIO_DRIVER_ALSA_DYNAMIC "\"${ASOUND_LIB_SONAME}\"") set(HAVE_ALSA_SHARED TRUE) else() @@ -113,8 +114,9 @@ macro(CheckALSA) endif() endif() if(NOT HAVE_ALSA_SHARED) - list(APPEND SDL_CMAKE_DEPENDS ALSA::ALSA) + #FIXME: remove this line and property generate sdl3.pc list(APPEND SDL_PC_PRIVATE_REQUIRES alsa) + sdl_link_dependency(alsa LIBS ALSA::ALSA CMAKE_MODULE ALSA PKG_CONFIG_SPECS "${ALSA_PKG_CONFIG_SPEC}") endif() set(HAVE_SDL_AUDIO TRUE) endif() @@ -130,26 +132,26 @@ endmacro() # - SDL_PIPEWIRE_SHARED opt # - HAVE_SDL_LOADSO opt macro(CheckPipewire) - if(SDL_PIPEWIRE) - pkg_check_modules(PKG_PIPEWIRE libpipewire-0.3>=0.3.20) - if(PKG_PIPEWIRE_FOUND) - set(HAVE_PIPEWIRE TRUE) - file(GLOB PIPEWIRE_SOURCES ${SDL3_SOURCE_DIR}/src/audio/pipewire/*.c) - list(APPEND SOURCE_FILES ${PIPEWIRE_SOURCES}) - set(SDL_AUDIO_DRIVER_PIPEWIRE 1) - target_include_directories(sdl-build-options SYSTEM INTERFACE ${PKG_PIPEWIRE_INCLUDE_DIRS}) - if(SDL_PIPEWIRE_SHARED AND NOT HAVE_SDL_LOADSO) - message_warn("You must have SDL_LoadObject() support for dynamic Pipewire loading") - endif() - FindLibraryAndSONAME("pipewire-0.3" LIBDIRS ${PKG_PIPEWIRE_LIBRARY_DIRS}) - if(SDL_PIPEWIRE_SHARED AND PIPEWIRE_0.3_LIB AND HAVE_SDL_LOADSO) - set(SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC "\"${PIPEWIRE_0.3_LIB_SONAME}\"") - set(HAVE_PIPEWIRE_SHARED TRUE) - else() - list(APPEND SDL_EXTRA_LDFLAGS ${PKG_PIPEWIRE_LDFLAGS}) - endif() - set(HAVE_SDL_AUDIO TRUE) - endif() + if(SDL_PIPEWIRE) + set(PipeWire_PKG_CONFIG_SPEC libpipewire-0.3>=0.3.20) + pkg_check_modules(PC_PIPEWIRE IMPORTED_TARGET ${PipeWire_PKG_CONFIG_SPEC}) + if(PC_PIPEWIRE_FOUND) + set(HAVE_PIPEWIRE TRUE) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/pipewire/*.c") + set(SDL_AUDIO_DRIVER_PIPEWIRE 1) + if(SDL_PIPEWIRE_SHARED AND NOT HAVE_SDL_LOADSO) + message(WARNING "You must have SDL_LoadObject() support for dynamic PipeWire loading") + endif() + FindLibraryAndSONAME("pipewire-0.3" LIBDIRS ${PC_PIPEWIRE_LIBRARY_DIRS}) + if(SDL_PIPEWIRE_SHARED AND PIPEWIRE_0.3_LIB AND HAVE_SDL_LOADSO) + set(SDL_AUDIO_DRIVER_PIPEWIRE_DYNAMIC "\"${PIPEWIRE_0.3_LIB_SONAME}\"") + set(HAVE_PIPEWIRE_SHARED TRUE) + sdl_link_dependency(pipewire INCLUDES $) + else() + sdl_link_dependency(pipewire LIBS PkgConfig::PC_PIPEWIRE PKG_CONFIG_PREFIX PC_PIPEWIRE PKG_CONFIG_SPECS ${PipeWire_PKG_CONFIG_SPEC}) + endif() + set(HAVE_SDL_AUDIO TRUE) + endif() endif() endmacro() @@ -160,22 +162,22 @@ endmacro() # - HAVE_SDL_LOADSO opt macro(CheckPulseAudio) if(SDL_PULSEAUDIO) - pkg_check_modules(PKG_PULSEAUDIO libpulse>=5.0) - if(PKG_PULSEAUDIO_FOUND) + set(PulseAudio_PKG_CONFIG_SPEC "libpulse>=5.0") + pkg_check_modules(PC_PULSEAUDIO IMPORTED_TARGET ${PulseAudio_PKG_CONFIG_SPEC}) + if(PC_PULSEAUDIO_FOUND) set(HAVE_PULSEAUDIO TRUE) - file(GLOB PULSEAUDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/pulseaudio/*.c) - list(APPEND SOURCE_FILES ${PULSEAUDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/pulseaudio/*.c") set(SDL_AUDIO_DRIVER_PULSEAUDIO 1) - target_include_directories(sdl-build-options SYSTEM INTERFACE ${PKG_PULSEAUDIO_INCLUDE_DIRS}) if(SDL_PULSEAUDIO_SHARED AND NOT HAVE_SDL_LOADSO) - message_warn("You must have SDL_LoadObject() support for dynamic PulseAudio loading") + message(WARNING "You must have SDL_LoadObject() support for dynamic PulseAudio loading") endif() - FindLibraryAndSONAME("pulse" LIBDIRS ${PKG_PULSEAUDIO_LIBRARY_DIRS}) + FindLibraryAndSONAME("pulse" LIBDIRS ${PC_PULSEAUDIO_LIBRARY_DIRS}) if(SDL_PULSEAUDIO_SHARED AND PULSE_LIB AND HAVE_SDL_LOADSO) set(SDL_AUDIO_DRIVER_PULSEAUDIO_DYNAMIC "\"${PULSE_LIB_SONAME}\"") set(HAVE_PULSEAUDIO_SHARED TRUE) + sdl_link_dependency(pulseaudio INCLUDES $) else() - list(APPEND SDL_EXTRA_LDFLAGS ${PKG_PULSEAUDIO_LDFLAGS}) + sdl_link_dependency(pulseaudio LIBS PkgConfig::PC_PULSEAUDIO PKG_CONFIG_PREFIX PC_PULSEAUDIO PKG_CONFIG_SPECS "${PulseAudio_PKG_CONFIG_SPEC}") endif() set(HAVE_SDL_AUDIO TRUE) endif() @@ -189,22 +191,22 @@ endmacro() # - HAVE_SDL_LOADSO opt macro(CheckJACK) if(SDL_JACK) - pkg_check_modules(PKG_JACK jack) - if(PKG_JACK_FOUND) + set(Jack_PKG_CONFIG_SPEC jack) + pkg_check_modules(PC_JACK IMPORTED_TARGET ${Jack_PKG_CONFIG_SPEC}) + if(PC_JACK_FOUND) set(HAVE_JACK TRUE) - file(GLOB JACK_SOURCES ${SDL3_SOURCE_DIR}/src/audio/jack/*.c) - list(APPEND SOURCE_FILES ${JACK_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/jack/*.c") set(SDL_AUDIO_DRIVER_JACK 1) - target_include_directories(sdl-build-options SYSTEM INTERFACE ${PKG_JACK_INCLUDE_DIRS}) if(SDL_JACK_SHARED AND NOT HAVE_SDL_LOADSO) - message_warn("You must have SDL_LoadObject() support for dynamic JACK audio loading") + message(WARNING "You must have SDL_LoadObject() support for dynamic JACK audio loading") endif() - FindLibraryAndSONAME("jack" LIBDIRS ${PKG_JACK_LIBRARY_DIRS}) + FindLibraryAndSONAME("jack" LIBDIRS ${PC_JACK_LIBRARY_DIRS}) if(SDL_JACK_SHARED AND JACK_LIB AND HAVE_SDL_LOADSO) set(SDL_AUDIO_DRIVER_JACK_DYNAMIC "\"${JACK_LIB_SONAME}\"") set(HAVE_JACK_SHARED TRUE) + sdl_link_dependency(jack INCLUDES $) else() - list(APPEND SDL_EXTRA_LDFLAGS ${PKG_JACK_LDFLAGS}) + sdl_link_dependency(jack LIBS PkgConfig::PC_JACK PKG_CONFIG_PREFIX PC_JACK PKG_CONFIG_SPECS ${Jack_PKG_CONFIG_SPEC}) endif() set(HAVE_SDL_AUDIO TRUE) endif() @@ -218,22 +220,22 @@ endmacro() # - HAVE_SDL_LOADSO opt macro(CheckSNDIO) if(SDL_SNDIO) - pkg_check_modules(PKG_SNDIO sndio) - if(PKG_SNDIO_FOUND) + set(SndIO_PKG_CONFIG_SPEC sndio) + pkg_check_modules(PC_SNDIO IMPORTED_TARGET ${SndIO_PKG_CONFIG_SPEC}) + if(PC_SNDIO_FOUND) set(HAVE_SNDIO TRUE) - file(GLOB SNDIO_SOURCES ${SDL3_SOURCE_DIR}/src/audio/sndio/*.c) - list(APPEND SOURCE_FILES ${SNDIO_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/audio/sndio/*.c") set(SDL_AUDIO_DRIVER_SNDIO 1) - target_include_directories(sdl-build-options INTERFACE ${PKG_SNDIO_INCLUDE_DIRS}) if(SDL_SNDIO_SHARED AND NOT HAVE_SDL_LOADSO) - message_warn("You must have SDL_LoadObject() support for dynamic sndio loading") + message(WARNING "You must have SDL_LoadObject() support for dynamic sndio loading") endif() - FindLibraryAndSONAME("sndio" LIBDIRS ${PKG_SNDIO_LIBRARY_DIRS}) + FindLibraryAndSONAME("sndio" LIBDIRS ${PC_SNDIO_LIBRARY_DIRS}) if(SDL_SNDIO_SHARED AND SNDIO_LIB AND HAVE_SDL_LOADSO) set(SDL_AUDIO_DRIVER_SNDIO_DYNAMIC "\"${SNDIO_LIB_SONAME}\"") set(HAVE_SNDIO_SHARED TRUE) + sdl_include_directories(PRIVATE SYSTEM $) else() - list(APPEND SDL_EXTRA_LIBS ${PKG_SNDIO_LDFLAGS}) + sdl_link_dependency(sndio LIBS PkgConfig::PC_SNDIO PKG_CONFIG_PREFIX PC_SNDIO PKG_CONFIG_SPECS ${SndIO_PKG_CONFIG_SPEC}) endif() set(HAVE_SDL_AUDIO TRUE) endif() @@ -248,14 +250,26 @@ endmacro() macro(CheckX11) cmake_push_check_state() if(SDL_X11) + set(X11_PKG_CONFIG_SPEC x11) + set(Xext_PKG_CONFIG_SPEC xext) + set(Xcursor_PKG_CONFIG_SPEC xcursor) + set(Xi_PKG_CONFIG_SPEC xi) + set(Xfixes_PKG_CONFIG_SPEC xfixes) + set(Xrandr_PKG_CONFIG_SPEC xrandr) + set(Xrender_PKG_CONFIG_SPEC xrender) + set(Xss_PKG_CONFIG_SPEC xscrnsaver) + + find_package(X11) + foreach(_LIB X11 Xext Xcursor Xi Xfixes Xrandr Xrender Xss) - FindLibraryAndSONAME("${_LIB}") + get_filename_component(_libdir "${X11_${_LIB}_LIB}" DIRECTORY) + FindLibraryAndSONAME("${_LIB}" LIBDIRS ${_libdir}) endforeach() - set(X11_dirs) - find_path(X_INCLUDEDIR + find_path(X11_INCLUDEDIR NAMES X11/Xlib.h PATHS + ${X11_INCLUDE_DIR} /usr/pkg/xorg/include /usr/X11R6/include /usr/X11R7/include @@ -267,31 +281,30 @@ macro(CheckX11) /opt/X11/include ) - if(X_INCLUDEDIR) - target_include_directories(sdl-build-options INTERFACE "${X_INCLUDEDIR}") - list(APPEND CMAKE_REQUIRED_INCLUDES ${X_INCLUDEDIR}) + if(X11_INCLUDEDIR) + sdl_include_directories(PRIVATE SYSTEM "${X11_INCLUDEDIR}") + list(APPEND CMAKE_REQUIRED_INCLUDES ${X11_INCLUDEDIR}) endif() - find_file(HAVE_XCURSOR_H NAMES "X11/Xcursor/Xcursor.h" HINTS "${X_INCLUDEDIR}") - find_file(HAVE_XINPUT2_H NAMES "X11/extensions/XInput2.h" HINTS "${X_INCLUDEDIR}") - find_file(HAVE_XRANDR_H NAMES "X11/extensions/Xrandr.h" HINTS "${X_INCLUDEDIR}") - find_file(HAVE_XFIXES_H_ NAMES "X11/extensions/Xfixes.h" HINTS "${X_INCLUDEDIR}") - find_file(HAVE_XRENDER_H NAMES "X11/extensions/Xrender.h" HINTS "${X_INCLUDEDIR}") - find_file(HAVE_XSS_H NAMES "X11/extensions/scrnsaver.h" HINTS "${X_INCLUDEDIR}") - find_file(HAVE_XSHAPE_H NAMES "X11/extensions/shape.h" HINTS "${X_INCLUDEDIR}") - find_file(HAVE_XDBE_H NAMES "X11/extensions/Xdbe.h" HINTS "${X_INCLUDEDIR}") - find_file(HAVE_XEXT_H NAMES "X11/extensions/Xext.h" HINTS "${X_INCLUDEDIR}") + find_file(HAVE_XCURSOR_H NAMES "X11/Xcursor/Xcursor.h" HINTS "${X11_INCLUDEDIR}") + find_file(HAVE_XINPUT2_H NAMES "X11/extensions/XInput2.h" HINTS "${X11_INCLUDEDIR}") + find_file(HAVE_XRANDR_H NAMES "X11/extensions/Xrandr.h" HINTS "${X11_INCLUDEDIR}") + find_file(HAVE_XFIXES_H_ NAMES "X11/extensions/Xfixes.h" HINTS "${X11_INCLUDEDIR}") + find_file(HAVE_XRENDER_H NAMES "X11/extensions/Xrender.h" HINTS "${X11_INCLUDEDIR}") + find_file(HAVE_XSS_H NAMES "X11/extensions/scrnsaver.h" HINTS "${X11_INCLUDEDIR}") + find_file(HAVE_XSHAPE_H NAMES "X11/extensions/shape.h" HINTS "${X11_INCLUDEDIR}") + find_file(HAVE_XDBE_H NAMES "X11/extensions/Xdbe.h" HINTS "${X11_INCLUDEDIR}") + find_file(HAVE_XEXT_H NAMES "X11/extensions/Xext.h" HINTS "${X11_INCLUDEDIR}") if(X11_LIB) if(NOT HAVE_XEXT_H) - message_error("Missing Xext.h, maybe you need to install the libxext-dev package?") + message(FATAL_ERROR "Missing Xext.h, maybe you need to install the libxext-dev package?") endif() set(HAVE_X11 TRUE) set(HAVE_SDL_VIDEO TRUE) - file(GLOB X11_SOURCES ${SDL3_SOURCE_DIR}/src/video/x11/*.c) - list(APPEND SOURCE_FILES ${X11_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/x11/*.c") set(SDL_VIDEO_DRIVER_X11 1) # !!! FIXME: why is this disabled for Apple? @@ -303,16 +316,16 @@ macro(CheckX11) if(NOT HAVE_SHMAT_IN_LIBC) check_library_exists(ipc shmat "" HAVE_SHMAT_IN_LIBIPC) if(HAVE_SHMAT_IN_LIBIPC) - list(APPEND SDL_EXTRA_LIBS ipc) + sdl_link_dependency(x11_ipc LIBS ipc) endif() if(NOT HAVE_SHMAT_IN_LIBIPC) - target_compile_definitions(sdl-build-options INTERFACE "NO_SHARED_MEMORY") + sdl_compile_definitions(PRIVATE "NO_SHARED_MEMORY") endif() endif() if(SDL_X11_SHARED) if(NOT HAVE_SDL_LOADSO) - message_warn("You must have SDL_LoadObject() support for dynamic X11 loading") + message(WARNING "You must have SDL_LoadObject() support for dynamic X11 loading") set(HAVE_X11_SHARED FALSE) else() set(HAVE_X11_SHARED TRUE) @@ -321,21 +334,19 @@ macro(CheckX11) if(HAVE_X11_SHARED) set(SDL_VIDEO_DRIVER_X11_DYNAMIC "\"${X11_LIB_SONAME}\"") else() - list(APPEND SDL_EXTRA_LDFLAGS "-L${X11_LIBDIR}") - list(APPEND SDL_EXTRA_LIBS X11) + sdl_link_dependency(x11 LIBS X11::X11 CMAKE_MODULE X11 PKG_CONFIG_SPECS ${X11_PKG_CONFIG_SPEC}) endif() endif() if(XEXT_LIB) if(HAVE_X11_SHARED) set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XEXT "\"${XEXT_LIB_SONAME}\"") else() - list(APPEND SDL_EXTRA_LDFLAGS "-L${XEXT_LIBDIR}") - list(APPEND SDL_EXTRA_LIBS Xext) + sdl_link_dependency(xext LIBS X11::Xext CMAKE_MODULE X11 PKG_CONFIG_SPECS ${Xext_PKG_CONFIG_SPEC}) endif() endif() else() - list(APPEND SDL_EXTRA_LDFLAGS "-L${X11_LIBDIR}" "-L${XEXT_LIBDIR}") - list(APPEND SDL_EXTRA_LIBS X11 Xext) + sdl_link_dependency(x11 LIBS X11::X11 CMAKE_MODULE X11 PKG_CONFIG_SPECS ${X11_PKG_CONFIG_SPEC}) + sdl_link_dependency(xext LIBS X11::Xext CMAKE_MODULE X11 PKG_CONFIG_SPECS ${Xext_PKG_CONFIG_SPEC}) endif() list(APPEND CMAKE_REQUIRED_LIBRARIES ${X11_LIB}) @@ -361,8 +372,7 @@ macro(CheckX11) if(HAVE_X11_SHARED) set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XCURSOR "\"${XCURSOR_LIB_SONAME}\"") else() - list(APPEND SDL_EXTRA_LDFLAGS "-L${XCURSOR_LIBDIR}") - list(APPEND SDL_EXTRA_LIBS Xcursor) + sdl_link_dependency(xcursor LIBS X11::Xcursor CMAKE_MODULE X11 PKG_CONFIG_SPECS ${Xcursor_PKG_CONFIG_SPEC}) endif() set(SDL_VIDEO_DRIVER_X11_XCURSOR 1) endif() @@ -377,8 +387,7 @@ macro(CheckX11) if(HAVE_X11_SHARED) set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XINPUT2 "\"${XI_LIB_SONAME}\"") else() - list(APPEND SDL_EXTRA_LDFLAGS "-L${XI_LIBDIR}") - list(APPEND SDL_EXTRA_LIBS Xi) + sdl_link_dependency(xi LIBS X11::Xi CMAKE_MODULE X11 PKG_CONFIG_SPECS ${Xi_PKG_CONFIG_SPEC}) endif() set(SDL_VIDEO_DRIVER_X11_XINPUT2 1) @@ -412,8 +421,7 @@ macro(CheckX11) if(HAVE_X11_SHARED) set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XFIXES "\"${XFIXES_LIB_SONAME}\"") else() - list(APPEND SDL_EXTRA_LDFLAGS "-L${XFIXES_LIBDIR}") - list(APPEND SDL_EXTRA_LIBS Xfixes) + sdl_link_dependency(xfixes LIBS X11::Xfixes CMAKE_MODULE X11 PKG_CONFIG_SPECS ${Xfixes_PKG_CONFIG_SPEC}) endif() set(SDL_VIDEO_DRIVER_X11_XFIXES 1) set(HAVE_X11_XFIXES TRUE) @@ -423,8 +431,7 @@ macro(CheckX11) if(HAVE_X11_SHARED) set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XRANDR "\"${XRANDR_LIB_SONAME}\"") else() - list(APPEND SDL_EXTRA_LDFLAGS "-L${XRANDR_LIBDIR}") - list(APPEND SDL_EXTRA_LIBS Xrandr) + sdl_link_dependency(xrandr LIBS X11::Xrandr CMAKE_MODULE X11 PKG_CONFIG_SPECS ${Xrandr_PKG_CONFIG_SPEC}) endif() set(SDL_VIDEO_DRIVER_X11_XRANDR 1) set(HAVE_X11_XRANDR TRUE) @@ -434,8 +441,7 @@ macro(CheckX11) if(HAVE_X11_SHARED) set(SDL_VIDEO_DRIVER_X11_DYNAMIC_XSS "\"${XSS_LIB_SONAME}\"") else() - list(APPEND SDL_EXTRA_LDFLAGS "-L${XSS_LIBDIR}") - list(APPEND SDL_EXTRA_LIBS Xss) + sdl_link_dependency(xss LIBS X11::Xss CMAKE_MODULE X11 PKG_CONFIG_SPECS ${Xss_PKG_CONFIG_SPEC}) endif() set(SDL_VIDEO_DRIVER_X11_XSCRNSAVER 1) set(HAVE_X11_XSCRNSAVER TRUE) @@ -449,7 +455,7 @@ macro(CheckX11) endif() if(NOT HAVE_X11) # Prevent Mesa from including X11 headers - target_compile_definitions(sdl-build-options INTERFACE "MESA_EGL_NO_X11_HEADERS" "EGL_NO_X11") + sdl_compile_definitions(PRIVATE "MESA_EGL_NO_X11_HEADERS" "EGL_NO_X11") endif() cmake_pop_check_state() endmacro() @@ -472,8 +478,7 @@ macro(WaylandProtocolGen _SCANNER _CODE_MODE _XML _PROTL) ARGS "${_CODE_MODE}" "${_XML}" "${_WAYLAND_PROT_C_CODE}" ) - list(APPEND SDL_GENERATED_HEADERS "${_WAYLAND_PROT_H_CODE}") - list(APPEND SOURCE_FILES "${_WAYLAND_PROT_C_CODE}") + sdl_sources("${_WAYLAND_PROT_C_CODE}") endmacro() # Requires: @@ -484,97 +489,95 @@ endmacro() # - HAVE_SDL_LOADSO opt macro(CheckWayland) if(SDL_WAYLAND) - set(WAYLAND_FOUND FALSE) - pkg_check_modules(PKG_WAYLAND "wayland-client>=1.18" wayland-egl wayland-cursor egl "xkbcommon>=0.5.0") + set(WAYLAND_PKG_CONFIG_SPEC "wayland-client>=1.18" wayland-egl wayland-cursor egl "xkbcommon>=0.5.0") + pkg_check_modules(PC_WAYLAND IMPORTED_TARGET ${WAYLAND_PKG_CONFIG_SPEC}) + find_program(WAYLAND_SCANNER NAMES wayland-scanner) - if(PKG_WAYLAND_FOUND) - set(WAYLAND_FOUND TRUE) - find_program(WAYLAND_SCANNER NAMES wayland-scanner REQUIRED) + set(WAYLAND_FOUND FALSE) + if(PC_WAYLAND_FOUND AND WAYLAND_SCANNER) execute_process( COMMAND ${WAYLAND_SCANNER} --version RESULT_VARIABLE WAYLAND_SCANNER_VERSION_RC - ERROR_VARIABLE WAYLAND_SCANNER_VERSION + ERROR_VARIABLE WAYLAND_SCANNER_VERSION_STDERR ERROR_STRIP_TRAILING_WHITESPACE ) if(NOT WAYLAND_SCANNER_VERSION_RC EQUAL 0) - message(FATAL "Failed to get wayland-scanner version") - set(WAYLAND_FOUND FALSE) - endif() - string(REPLACE "wayland-scanner " "" WAYLAND_SCANNER_VERSION ${WAYLAND_SCANNER_VERSION}) - - string(COMPARE LESS ${WAYLAND_SCANNER_VERSION} "1.15.0" WAYLAND_SCANNER_PRE_1_15) - if(WAYLAND_SCANNER_PRE_1_15) - set(WAYLAND_SCANNER_CODE_MODE "code") + message(WARNING "Failed to get wayland-scanner version") else() - set(WAYLAND_SCANNER_CODE_MODE "private-code") + if(WAYLAND_SCANNER_VERSION_STDERR MATCHES [[([0-9.]+)$]]) + set(WAYLAND_FOUND TRUE) + set(WAYLAND_SCANNER_VERSION ${CMAKE_MATCH_1}) + if(WAYLAND_SCANNER_VERSION VERSION_LESS "1.15.0") + set(WAYLAND_SCANNER_CODE_MODE "code") + else() + set(WAYLAND_SCANNER_CODE_MODE "private-code") + endif() + endif() endif() endif() if(WAYLAND_FOUND) - target_link_directories(sdl-build-options INTERFACE ${PKG_WAYLAND_LIBRARY_DIRS}) - target_include_directories(sdl-build-options INTERFACE ${PKG_WAYLAND_INCLUDE_DIRS}) - set(HAVE_WAYLAND TRUE) set(HAVE_SDL_VIDEO TRUE) - file(GLOB WAYLAND_SOURCES ${SDL3_SOURCE_DIR}/src/video/wayland/*.c) - list(APPEND SOURCE_FILES ${WAYLAND_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/wayland/*.c") # We have to generate some protocol interface code for some unstable Wayland features. - file(MAKE_DIRECTORY "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols") - # Prepend to include path to make sure it they override installed protocol headers - target_include_directories(sdl-build-options SYSTEM BEFORE INTERFACE "${CMAKE_CURRENT_BINARY_DIR}/wayland-generated-protocols") + file(MAKE_DIRECTORY "${SDL3_BINARY_DIR}/wayland-generated-protocols") + # Prepend to include path to make sure they override installed protocol headers + sdl_include_directories(PRIVATE SYSTEM BEFORE "${SDL3_BINARY_DIR}/wayland-generated-protocols") file(GLOB WAYLAND_PROTOCOLS_XML RELATIVE "${SDL3_SOURCE_DIR}/wayland-protocols/" "${SDL3_SOURCE_DIR}/wayland-protocols/*.xml") - foreach(_XML ${WAYLAND_PROTOCOLS_XML}) + foreach(_XML IN LISTS WAYLAND_PROTOCOLS_XML) string(REGEX REPLACE "\\.xml$" "" _PROTL "${_XML}") WaylandProtocolGen("${WAYLAND_SCANNER}" "${WAYLAND_SCANNER_CODE_MODE}" "${SDL3_SOURCE_DIR}/wayland-protocols/${_XML}" "${_PROTL}") endforeach() if(SDL_WAYLAND_QT_TOUCH) - set(HAVE_WAYLAND_QT_TOUCH TRUE) - set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1) + set(HAVE_WAYLAND_QT_TOUCH TRUE) + set(SDL_VIDEO_DRIVER_WAYLAND_QT_TOUCH 1) endif() if(SDL_WAYLAND_SHARED AND NOT HAVE_SDL_LOADSO) - message_warn("You must have SDL_LoadObject() support for dynamic Wayland loading") + message(WARNING "You must have SDL_LoadObject() support for dynamic Wayland loading") endif() - FindLibraryAndSONAME(wayland-client LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS}) - FindLibraryAndSONAME(wayland-egl LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS}) - FindLibraryAndSONAME(wayland-cursor LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS}) - FindLibraryAndSONAME(xkbcommon LIBDIRS ${PKG_WAYLAND_LIBRARY_DIRS}) + FindLibraryAndSONAME(wayland-client LIBDIRS ${PC_WAYLAND_LIBRARY_DIRS}) + FindLibraryAndSONAME(wayland-egl LIBDIRS ${PC_WAYLAND_LIBRARY_DIRS}) + FindLibraryAndSONAME(wayland-cursor LIBDIRS ${PC_WAYLAND_LIBRARY_DIRS}) + FindLibraryAndSONAME(xkbcommon LIBDIRS ${PC_WAYLAND_LIBRARY_DIRS}) if(SDL_WAYLAND_SHARED AND WAYLAND_CLIENT_LIB AND WAYLAND_EGL_LIB AND WAYLAND_CURSOR_LIB AND XKBCOMMON_LIB AND HAVE_SDL_LOADSO) set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC "\"${WAYLAND_CLIENT_LIB_SONAME}\"") set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_EGL "\"${WAYLAND_EGL_LIB_SONAME}\"") set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_CURSOR "\"${WAYLAND_CURSOR_LIB_SONAME}\"") set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_XKBCOMMON "\"${XKBCOMMON_LIB_SONAME}\"") set(HAVE_WAYLAND_SHARED TRUE) + sdl_link_dependency(wayland INCLUDES $) else() - list(APPEND SDL_EXTRA_LIBS ${PKG_WAYLAND_LIBRARIES}) + sdl_link_dependency(wayland LIBS PkgConfig::PC_WAYLAND PKG_CONFIG_PREFIX PC_WAYLAND PKG_CONFIG_SPECS ${WAYLAND_PKG_CONFIG_SPEC}) endif() if(SDL_WAYLAND_LIBDECOR) - pkg_check_modules(PKG_LIBDECOR libdecor-0) - if(PKG_LIBDECOR_FOUND) - set(HAVE_WAYLAND_LIBDECOR TRUE) - set(HAVE_LIBDECOR_H 1) - target_link_directories(sdl-build-options INTERFACE "${PKG_LIBDECOR_LIBRARY_DIRS}") - target_include_directories(sdl-build-options SYSTEM INTERFACE "${PKG_LIBDECOR_INCLUDE_DIRS}") - if(SDL_WAYLAND_LIBDECOR_SHARED AND NOT HAVE_SDL_LOADSO) - message_warn("You must have SDL_LoadObject() support for dynamic libdecor loading") + set(LibDecor_PKG_CONFIG_SPEC libdecor-0) + pkg_check_modules(PC_LIBDECOR IMPORTED_TARGET ${LibDecor_PKG_CONFIG_SPEC}) + if(PC_LIBDECOR_FOUND) + # Version 0.1.2 or higher is needed for suspended window state and statically linked min/max getters. + if(PC_LIBDECOR_VERSION VERSION_GREATER_EQUAL "0.1.2") + set(SDL_HAVE_LIBDECOR_VER_0_1_2 1) + set(LibDecor_PKG_CONFIG_SPEC "libdecor-0>=0.1.2") + endif() + set(HAVE_WAYLAND_LIBDECOR TRUE) + set(HAVE_LIBDECOR_H 1) + if(SDL_WAYLAND_LIBDECOR_SHARED AND NOT HAVE_SDL_LOADSO) + message(WARNING "You must have SDL_LoadObject() support for dynamic libdecor loading") + endif() + FindLibraryAndSONAME(decor-0 LIBDIRS ${PC_LIBDECOR_LIBRARY_DIRS}) + if(SDL_WAYLAND_LIBDECOR_SHARED AND DECOR_0_LIB AND HAVE_SDL_LOADSO) + set(HAVE_WAYLAND_LIBDECOR_SHARED TRUE) + set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR "\"${DECOR_0_LIB_SONAME}\"") + sdl_link_dependency(libdecor INCLUDES $) + else() + sdl_link_dependency(libdecor LIBS PkgConfig::PC_LIBDECOR PKG_CONFIG_PREFIX PC_LIBDECOR PKG_CONFIG_SPECS ${LibDecor_PKG_CONFIG_SPEC}) endif() - FindLibraryAndSONAME(decor-0 LIBDIRS ${PKG_LIBDECOR_LIBRARY_DIRS}) - if(SDL_WAYLAND_LIBDECOR_SHARED AND DECOR_0_LIB AND HAVE_SDL_LOADSO) - set(HAVE_WAYLAND_LIBDECOR_SHARED TRUE) - set(SDL_VIDEO_DRIVER_WAYLAND_DYNAMIC_LIBDECOR "\"${DECOR_0_LIB_SONAME}\"") - else() - list(APPEND SDL_EXTRA_LIBS ${PKG_LIBDECOR_LIBRARIES}) - endif() - - # Version 0.1.2 or higher is needed for suspended window state and statically linked min/max getters. - if (PKG_LIBDECOR_VERSION VERSION_GREATER_EQUAL "0.1.2") - set(SDL_HAVE_LIBDECOR_VER_0_1_2 1) - endif () endif() endif() @@ -592,8 +595,7 @@ macro(CheckCOCOA) set(HAVE_COCOA TRUE) endif() if(HAVE_COCOA) - file(GLOB COCOA_SOURCES ${SDL3_SOURCE_DIR}/src/video/cocoa/*.m) - list(APPEND SOURCE_FILES ${COCOA_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/cocoa/*.m") set(SDL_VIDEO_DRIVER_COCOA 1) set(HAVE_SDL_VIDEO TRUE) endif() @@ -616,18 +618,18 @@ macro(CheckVivante) set(HAVE_VIVANTE TRUE) set(HAVE_SDL_VIDEO TRUE) - file(GLOB VIVANTE_SOURCES ${SDL3_SOURCE_DIR}/src/video/vivante/*.c) - list(APPEND SOURCE_FILES ${VIVANTE_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/vivante/*.c") set(SDL_VIDEO_DRIVER_VIVANTE 1) + # FIXME: Use Find module if(HAVE_VIVANTE_VDK) set(SDL_VIDEO_DRIVER_VIVANTE_VDK 1) find_library(VIVANTE_LIBRARY REQUIRED NAMES VIVANTE vivante drm_vivante) find_library(VIVANTE_VDK_LIBRARY VDK REQUIRED) - list(APPEND SDL_EXTRA_LIBS ${VIVANTE_LIBRARY} ${VIVANTE_VDK_LIBRARY}) + sdl_link_dependency(vivante LIBS ${VIVANTE_LIBRARY} ${VIVANTE_VDK_LIBRARY}) else() - target_compile_definitions(sdl-build-options INTERFACE "LINUX;EGL_API_FB") - list(APPEND SDL_PC_CFLAGS -DLINUX -DEGL_API_FB) - list(APPEND SDL_EXTRA_LIBS EGL) + # these defines are needed when including the system EGL headers, which SDL does + sdl_compile_definitions(PUBLIC "LINUX" "EGL_API_FB") + sdl_link_dependency(vivante LIBS EGL) endif(HAVE_VIVANTE_VDK) endif() endif() @@ -649,9 +651,10 @@ endmacro() # Requires: # - PkgCheckModules macro(CheckEGL) - if (SDL_OPENGL OR SDL_OPENGLES) - pkg_check_modules(EGL egl) - set(CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS} ${EGL_CFLAGS}") + if(SDL_OPENGL OR SDL_OPENGLES) + cmake_push_check_state() + find_package(OpenGL MODULE) + list(APPEND CMAKE_REQUIRED_INCLUDES ${OPENGL_EGL_INCLUDE_DIRS}) check_c_source_compiles(" #define EGL_API_FB #define MESA_EGL_NO_X11_HEADERS @@ -659,8 +662,10 @@ macro(CheckEGL) #include #include int main (int argc, char** argv) { return 0; }" HAVE_OPENGL_EGL) + cmake_pop_check_state() if(HAVE_OPENGL_EGL) set(SDL_VIDEO_OPENGL_EGL 1) + sdl_link_dependency(egl INCLUDES ${OPENGL_EGL_INCLUDE_DIRS}) endif() endif() endmacro() @@ -689,21 +694,28 @@ macro(CheckOpenGLES) #include int main (int argc, char** argv) { return 0; }" HAVE_OPENGLES_V1) if(HAVE_OPENGLES_V1) - set(HAVE_OPENGLES TRUE) - set(SDL_VIDEO_OPENGL_ES 1) + set(HAVE_OPENGLES TRUE) + set(SDL_VIDEO_OPENGL_ES 1) endif() check_c_source_compiles(" - #include - #include - int main (int argc, char** argv) { return 0; }" HAVE_OPENGLES_V2) + #include + #include + int main (int argc, char** argv) { return 0; }" HAVE_OPENGLES_V2) if(HAVE_OPENGLES_V2) - set(HAVE_OPENGLES TRUE) - set(SDL_VIDEO_OPENGL_ES2 1) - set(SDL_VIDEO_RENDER_OGL_ES2 1) + set(HAVE_OPENGLES TRUE) + set(SDL_VIDEO_OPENGL_ES2 1) + set(SDL_VIDEO_RENDER_OGL_ES2 1) endif() endif() endmacro() +macro(CheckVulkan) + if(SDL_VULKAN) + set(SDL_VIDEO_VULKAN 1) + set(HAVE_VULKAN TRUE) + endif() +endmacro() + # Requires: # - EGL macro(CheckQNXScreen) @@ -713,9 +725,8 @@ macro(CheckQNXScreen) int main (int argc, char** argv) { return 0; }" HAVE_QNX_SCREEN) if(HAVE_QNX_SCREEN) set(SDL_VIDEO_DRIVER_QNX 1) - file(GLOB QNX_VIDEO_SOURCES ${SDL3_SOURCE_DIR}/src/video/qnx/*.c) - list(APPEND SOURCE_FILES ${QNX_VIDEO_SOURCES}) - list(APPEND SDL_EXTRA_LIBS screen EGL) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/qnx/*.c") + sdl_link_dependency(qnxscreen LIBS screen EGL) endif() endif() endmacro() @@ -779,20 +790,19 @@ macro(CheckPTHREAD) endif() # Run some tests - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}") + string(APPEND CMAKE_REQUIRED_FLAGS " ${PTHREAD_CFLAGS} ${PTHREAD_LDFLAGS}") check_c_source_compiles(" - #include - int main(int argc, char** argv) { - pthread_attr_t type; - pthread_attr_init(&type); - return 0; - }" HAVE_PTHREADS) + #include + int main(int argc, char** argv) { + pthread_attr_t type; + pthread_attr_init(&type); + return 0; + }" HAVE_PTHREADS) if(HAVE_PTHREADS) set(SDL_THREAD_PTHREAD 1) separate_arguments(PTHREAD_CFLAGS) - target_compile_options(sdl-build-options INTERFACE ${PTHREAD_CFLAGS}) - list(APPEND SDL_EXTRA_LDFLAGS ${PTHREAD_LDFLAGS}) - list(APPEND SDL_PC_CFLAGS ${PTHREAD_CFLAGS}) + sdl_compile_options(PRIVATE ${PTHREAD_CFLAGS}) + sdl_link_dependency(pthread LINK_OPTIONS ${PTHREAD_LDFLAGS}) check_c_source_compiles(" #include @@ -850,19 +860,17 @@ macro(CheckPTHREAD) endif() endif() - set(SOURCE_FILES ${SOURCE_FILES} - ${SDL3_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c - ${SDL3_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c # Can be faked, if necessary - ${SDL3_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c # Can be faked, if necessary - ${SDL3_SOURCE_DIR}/src/thread/pthread/SDL_sysrwlock.c # Can be faked, if necessary - ${SDL3_SOURCE_DIR}/src/thread/pthread/SDL_systls.c - ) + sdl_sources( + "${SDL3_SOURCE_DIR}/src/thread/pthread/SDL_systhread.c" + "${SDL3_SOURCE_DIR}/src/thread/pthread/SDL_sysmutex.c" # Can be faked, if necessary + "${SDL3_SOURCE_DIR}/src/thread/pthread/SDL_syscond.c" # Can be faked, if necessary + "${SDL3_SOURCE_DIR}/src/thread/pthread/SDL_sysrwlock.c" # Can be faked, if necessary + "${SDL3_SOURCE_DIR}/src/thread/pthread/SDL_systls.c" + ) if(HAVE_PTHREADS_SEM) - set(SOURCE_FILES ${SOURCE_FILES} - ${SDL3_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c) + sdl_sources("${SDL3_SOURCE_DIR}/src/thread/pthread/SDL_syssem.c") else() - set(SOURCE_FILES ${SOURCE_FILES} - ${SDL3_SOURCE_DIR}/src/thread/generic/SDL_syssem.c) + sdl_sources("${SDL3_SOURCE_DIR}/src/thread/generic/SDL_syssem.c") endif() set(HAVE_SDL_THREADS TRUE) endif() @@ -887,7 +895,7 @@ macro(CheckUSBHID) check_include_file(libusbhid.h HAVE_LIBUSBHID_H) if(HAVE_LIBUSBHID_H) - set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSBHID_H") + string(APPEND USB_CFLAGS " -DHAVE_LIBUSBHID_H") endif() set(USB_LIBS ${USB_LIBS} usbhid) else() @@ -897,7 +905,7 @@ macro(CheckUSBHID) endif() check_include_file(libusb.h HAVE_LIBUSB_H) if(HAVE_LIBUSB_H) - set(USB_CFLAGS "${USB_CFLAGS} -DHAVE_LIBUSB_H") + string(APPEND USB_CFLAGS " -DHAVE_LIBUSB_H") endif() check_library_exists(usb hid_init "" LIBUSB) if(LIBUSB) @@ -905,7 +913,7 @@ macro(CheckUSBHID) endif() endif() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${USB_CFLAGS}") + string(APPEND CMAKE_REQUIRED_FLAGS " ${USB_CFLAGS}") list(APPEND CMAKE_REQUIRED_LIBRARIES ${USB_LIBS}) check_c_source_compiles(" #include @@ -958,7 +966,7 @@ macro(CheckUSBHID) return 0; }" HAVE_USBHID_UCR_DATA) if(HAVE_USBHID_UCR_DATA) - set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_UCR_DATA") + string(APPEND USB_CFLAGS " -DUSBHID_UCR_DATA") endif() check_c_source_compiles(" @@ -986,7 +994,7 @@ macro(CheckUSBHID) return 0; }" HAVE_USBHID_NEW) if(HAVE_USBHID_NEW) - set(USB_CFLAGS "${USB_CFLAGS} -DUSBHID_NEW") + string(APPEND USB_CFLAGS " -DUSBHID_NEW") endif() check_c_source_compiles(" @@ -999,13 +1007,12 @@ macro(CheckUSBHID) set(SDL_HAVE_MACHINE_JOYSTICK_H 1) endif() set(SDL_JOYSTICK_USBHID 1) - file(GLOB BSD_JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/bsd/*.c) - list(APPEND SOURCE_FILES ${BSD_JOYSTICK_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/bsd/*.c") separate_arguments(USB_CFLAGS) - target_compile_options(sdl-build-options INTERFACE ${USB_CFLAGS}) - list(APPEND SDL_EXTRA_LIBS ${USB_LIBS}) + sdl_compile_options(PRIVATE ${USB_CFLAGS}) + #FIXME: properly add usb libs with pkg-config or whatever + sdl_link_dependency(usbhid LIBS ${USB_LIBS}) set(HAVE_SDL_JOYSTICK TRUE) - endif() cmake_pop_check_state() endmacro() @@ -1016,20 +1023,25 @@ macro(CheckHIDAPI) if(SDL_HIDAPI) if(SDL_HIDAPI_LIBUSB) set(HAVE_LIBUSB FALSE) - pkg_check_modules(PKG_LIBUSB libusb-1.0) - if(PKG_LIBUSB_FOUND) - check_include_file(libusb.h HAVE_LIBUSB_H ${PKG_LIBUSB_CFLAGS}) + + set(LibUSB_PKG_CONFIG_SPEC libusb-1.0) + pkg_check_modules(PC_LIBUSB IMPORTED_TARGET ${LibUSB_PKG_CONFIG_SPEC}) + if(PC_LIBUSB_FOUND) + cmake_push_check_state() + list(APPEND CMAKE_REQUIRED_INCLUDES ${LibUSB_INCLUDE_DIRS}) + check_include_file(libusb.h HAVE_LIBUSB_H) + cmake_pop_check_state() if(HAVE_LIBUSB_H) set(HAVE_LIBUSB TRUE) - target_include_directories(sdl-build-options SYSTEM INTERFACE ${PKG_LIBUSB_INCLUDE_DIRS}) if(HIDAPI_ONLY_LIBUSB) - list(APPEND SDL_EXTRA_LIBS ${PKG_LIBUSB_LIBRARIES}) + sdl_link_dependency(hidapi LIBS PkgConfig::PC_LIBUSB PKG_CONFIG_PREFIX PC_LIBUSB PKG_CONFIG_SPECS ${LibUSB_PKG_CONFIG_SPEC}) else() - # libusb is loaded dynamically, so don't add it to SDL_EXTRA_LIBS - FindLibraryAndSONAME("usb-1.0" LIBDIRS ${PKG_LIBUSB_LIBRARY_DIRS}) + # libusb is loaded dynamically, so don't add link to it + FindLibraryAndSONAME("usb-1.0" LIBDIRS ${PC_LIBUSB_LIBRARY_DIRS}) if(USB_1.0_LIB) set(SDL_LIBUSB_DYNAMIC "\"${USB_1.0_LIB_SONAME}\"") endif() + sdl_link_dependency(hidapi INCLUDES $) endif() endif() endif() @@ -1041,10 +1053,10 @@ macro(CheckHIDAPI) if(HAVE_HIDAPI) if(ANDROID) - list(APPEND SOURCE_FILES ${SDL3_SOURCE_DIR}/src/hidapi/android/hid.cpp) + sdl_sources("${SDL3_SOURCE_DIR}/src/hidapi/android/hid.cpp") endif() if(IOS OR TVOS) - list(APPEND SOURCE_FILES ${SDL3_SOURCE_DIR}/src/hidapi/ios/hid.m) + sdl_sources("${SDL3_SOURCE_DIR}/src/hidapi/ios/hid.m") set(SDL_FRAMEWORK_COREBLUETOOTH 1) endif() set(HAVE_SDL_HIDAPI TRUE) @@ -1053,8 +1065,7 @@ macro(CheckHIDAPI) set(SDL_JOYSTICK_HIDAPI 1) set(HAVE_SDL_JOYSTICK TRUE) set(HAVE_HIDAPI_JOYSTICK TRUE) - file(GLOB HIDAPI_JOYSTICK_SOURCES ${SDL3_SOURCE_DIR}/src/joystick/hidapi/*.c) - list(APPEND SOURCE_FILES ${HIDAPI_JOYSTICK_SOURCES}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/joystick/hidapi/*.c") endif() else() set(SDL_HIDAPI_DISABLED 1) @@ -1068,38 +1079,18 @@ endmacro() # - n/a macro(CheckRPI) if(SDL_RPI) - pkg_check_modules(VIDEO_RPI bcm_host brcmegl) - if (NOT VIDEO_RPI_FOUND) - set(VIDEO_RPI_INCLUDE_DIRS "/opt/vc/include" "/opt/vc/include/interface/vcos/pthreads" "/opt/vc/include/interface/vmcs_host/linux/" ) - set(VIDEO_RPI_LIBRARY_DIRS "/opt/vc/lib" ) - set(VIDEO_RPI_LIBRARIES bcm_host ) - set(VIDEO_RPI_LDFLAGS "-Wl,-rpath,/opt/vc/lib") - endif() - listtostr(VIDEO_RPI_INCLUDE_DIRS VIDEO_RPI_INCLUDE_FLAGS "-I") - separate_arguments(VIDEO_RPI_INCLUDE_FLAGS) - listtostr(VIDEO_RPI_LIBRARY_DIRS VIDEO_RPI_LIBRARY_FLAGS "-L") - separate_arguments(VIDEO_RPI_LIBRARY_FLAGS) - - cmake_push_check_state() - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} ${VIDEO_RPI_INCLUDE_FLAGS} ${VIDEO_RPI_LIBRARY_FLAGS}") - list(APPEND CMAKE_REQUIRED_LIBRARIES ${VIDEO_RPI_LIBRARIES}) - check_c_source_compiles(" - #include - #include - int main(int argc, char **argv) { - EGL_DISPMANX_WINDOW_T window; - bcm_host_init(); - }" HAVE_RPI) - cmake_pop_check_state() - - if(SDL_VIDEO AND HAVE_RPI) - set(HAVE_SDL_VIDEO TRUE) - set(SDL_VIDEO_DRIVER_RPI 1) - file(GLOB VIDEO_RPI_SOURCES ${SDL3_SOURCE_DIR}/src/video/raspberry/*.c) - list(APPEND SOURCE_FILES ${VIDEO_RPI_SOURCES}) - list(APPEND SDL_EXTRA_LIBS ${VIDEO_RPI_LIBRARIES}) - target_compile_options(sdl-build-options INTERFACE ${VIDEO_RPI_INCLUDE_FLAGS}) - list(APPEND SDL_EXTRA_LDFLAGS ${VIDEO_RPI_LIBRARY_FLAGS} ${VIDEO_RPI_LDFLAGS}) + # presence of bcm_host means raspberry pi + find_package(RPi_BcmHost) + if(RPi_BcmHost_FOUND) + set(HAVE_RPI TRUE) + sdl_link_dependency(rpi LIBS RPi_BcmHost::RPi_BcmHost CMAKE_MODULE RPi_BcmHost PKG_CONFIG_SPECS ${RPi_BcmHost_PKG_CONFIG_SPEC}) + find_package(RPi_BrcmEGL) + if(SDL_VIDEO AND RPi_BrcmEGL_FOUND) + set(HAVE_SDL_VIDEO TRUE) + set(SDL_VIDEO_DRIVER_RPI 1) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/raspberry/*.c") + sdl_link_dependency(rpi-video LIBS RPi_BrcmEGL::RPi_BrcmEGL CMAKE_MODULE RPi_BrcmEGL PKG_CONFIG_SPECS ${RPi_BrcmEGL_PKG_CONFIG_SPEC}) + endif() endif() endif() endmacro() @@ -1108,8 +1099,9 @@ endmacro() # - n/a macro(CheckROCKCHIP) if(SDL_ROCKCHIP) - pkg_check_modules(VIDEO_ROCKCHIP mali) - if (VIDEO_ROCKCHIP_FOUND) + set(MALI_PKG_CONFIG_SPEC mali) + pkg_check_modules(PC_MALI QUIET ${MALI_PKG_CONFIG_SPEC}) + if(PC_MALI_FOUND) set(HAVE_ROCKCHIP TRUE) endif() if(SDL_VIDEO AND HAVE_ROCKCHIP) @@ -1127,31 +1119,36 @@ endmacro() # - HAVE_SDL_LOADSO opt macro(CheckKMSDRM) if(SDL_KMSDRM) - pkg_check_modules(PKG_KMSDRM libdrm gbm egl) - if(PKG_KMSDRM_FOUND AND HAVE_OPENGL_EGL) - target_link_directories(sdl-build-options INTERFACE ${PKG_KMSDRM_LIBRARY_DIRS}) - target_include_directories(sdl-build-options INTERFACE "${PKG_KMSDRM_INCLUDE_DIRS}") + set(PKG_CONFIG_LIBDRM_SPEC libdrm) + set(PKG_CONFIG_GBM_SPEC gbm) + pkg_check_modules(PC_LIBDRM IMPORTED_TARGET ${PKG_CONFIG_LIBDRM_SPEC}) + pkg_check_modules(PC_GBM IMPORTED_TARGET ${PKG_CONFIG_GBM_SPEC}) + if(PC_LIBDRM_FOUND AND PC_GBM_FOUND AND HAVE_OPENGL_EGL) set(HAVE_KMSDRM TRUE) set(HAVE_SDL_VIDEO TRUE) - file(GLOB KMSDRM_SOURCES ${SDL3_SOURCE_DIR}/src/video/kmsdrm/*.c) - list(APPEND SOURCE_FILES ${KMSDRM_SOURCES}) - - target_include_directories(sdl-build-options SYSTEM INTERFACE ${PKG_KMSDRM_INCLUDE_DIRS}) + sdl_glob_sources("${SDL3_SOURCE_DIR}/src/video/kmsdrm/*.c") set(SDL_VIDEO_DRIVER_KMSDRM 1) if(SDL_KMSDRM_SHARED AND NOT HAVE_SDL_LOADSO) - message_warn("You must have SDL_LoadObject() support for dynamic KMS/DRM loading") + message(WARNING "You must have SDL_LoadObject() support for dynamic KMS/DRM loading") endif() + set(HAVE_KMSDRM_SHARED FALSE) if(SDL_KMSDRM_SHARED AND HAVE_SDL_LOADSO) - FindLibraryAndSONAME(drm LIBDIRS ${PKG_KMSDRM_LIBRARY_DIRS}) - FindLibraryAndSONAME(gbm LIBDIRS ${PKG_KMSDRM_LIBRARY_DIRS}) - set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "\"${DRM_LIB_SONAME}\"") - set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "\"${GBM_LIB_SONAME}\"") - set(HAVE_KMSDRM_SHARED TRUE) - else() - list(APPEND SDL_EXTRA_LIBS ${PKG_KMSDRM_LIBRARIES}) + FindLibraryAndSONAME(drm LIBDIRS ${PC_LIBDRM_LIBRARY_DIRS}) + FindLibraryAndSONAME(gbm LIBDIRS ${PC_GBM_LIBRARY_DIRS}) + if(DRM_LIB AND DRM_SHARED AND GBM_LIB AND GBM_SHARED) + set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC "\"${DRM_LIB_SONAME}\"") + set(SDL_VIDEO_DRIVER_KMSDRM_DYNAMIC_GBM "\"${GBM_LIB_SONAME}\"") + set(HAVE_KMSDRM_SHARED TRUE) + sdl_link_dependency(kmsdrm-drm INCLUDES $) + sdl_link_dependency(kmsdrm-gbm INCLUDES $) + endif() + endif() + if(NOT HAVE_KMSDRM_SHARED) + sdl_link_dependency(kmsdrm-libdrm LIBS PkgConfig::PC_LIBDRM PKG_CONFIG_PREFIX PC_LIBDRM PKG_CONFIG_SPECS ${PKG_CONFIG_LIBDRM_SPEC}) + sdl_link_dependency(kmsdrm-gbm LIBS PkgConfig::PC_GBM PKG_CONFIG_PREFIX PC_GBM PKG_CONFIG_SPECS ${PKG_CONFIG_GBM_SPEC}) endif() endif() endif() @@ -1159,13 +1156,62 @@ endmacro() macro(CheckLibUDev) if(SDL_LIBUDEV) - check_include_file("libudev.h" have_libudev_header) - if(have_libudev_header) + check_include_file("libudev.h" HAVE_LIBUDEV_HEADER) + if(HAVE_LIBUDEV_HEADER) set(HAVE_LIBUDEV_H TRUE) FindLibraryAndSONAME(udev) if(UDEV_LIB_SONAME) set(SDL_UDEV_DYNAMIC "\"${UDEV_LIB_SONAME}\"") + set(HAVE_LIBUDEV TRUE) endif() endif() endif() endmacro() + +macro(CheckLibUnwind) + if(TARGET SDL3_test) + set(found_libunwind FALSE) + set(_libunwind_src "#include \nint main() {unw_context_t context; unw_getcontext(&context); return 0;}") + + if(NOT found_libunwind) + cmake_push_check_state() + check_c_source_compiles("${_libunwind_src}" LIBC_HAS_WORKING_LIBUNWIND) + cmake_pop_check_state() + if(LIBC_HAS_WORKING_LIBUNWIND) + set(found_libunwind TRUE) + target_compile_definitions(SDL3_test PRIVATE HAVE_LIBUNWIND_H) + endif() + endif() + + if(NOT found_libunwind) + cmake_push_check_state() + list(APPEND CMAKE_REQUIRED_LIBRARIES "unwind") + check_c_source_compiles("${_libunwind_src}" LIBUNWIND_HAS_WORKINGLIBUNWIND) + cmake_pop_check_state() + if(LIBUNWIND_HAS_WORKINGLIBUNWIND) + set(found_libunwind TRUE) + sdl_test_link_dependency(UNWIND LIBS unwind) + endif() + endif() + + if(NOT found_libunwind) + set(LibUnwind_PKG_CONFIG_SPEC libunwind libunwind-generic) + pkg_check_modules(PC_LIBUNWIND IMPORTED_TARGET ${LibUnwind_PKG_CONFIG_SPEC}) + if(PC_LIBUNWIND_FOUND) + cmake_push_check_state() + list(APPEND CMAKE_REQUIRED_LIBRARIES ${PC_LIBUNWIND_LIBRARIES}) + list(APPEND CMAKE_REQUIRED_INCLUDES ${PC_LIBUNWIND_INCLUDE_DIRS}) + check_c_source_compiles("${_libunwind_src}" PC_LIBUNWIND_HAS_WORKING_LIBUNWIND) + cmake_pop_check_state() + if(PC_LIBUNWIND_HAS_WORKING_LIBUNWIND) + set(found_libunwind TRUE) + sdl_test_link_dependency(UNWIND LIBS PkgConfig::PC_LIBUNWIND PKG_CONFIG_PREFIX PC_LIBUNWIND PKG_CONFIG_SPECS ${LibUnwind_PKG_CONFIG_SPEC}) + endif() + endif() + endif() + + if(found_libunwind) + target_compile_definitions(SDL3_test PRIVATE HAVE_LIBUNWIND_H) + endif() + endif() +endmacro() diff --git a/cmake/sdlcompilers.cmake b/cmake/sdlcompilers.cmake new file mode 100644 index 000000000..40bb3b6dc --- /dev/null +++ b/cmake/sdlcompilers.cmake @@ -0,0 +1,128 @@ +macro(SDL_DetectCompiler) + set(USE_CLANG FALSE) + set(USE_GCC FALSE) + set(USE_INTELCC FALSE) + set(USE_QCC FALSE) + if(CMAKE_C_COMPILER_ID MATCHES "Clang|IntelLLVM") + set(USE_CLANG TRUE) + # Visual Studio 2019 v16.2 added support for Clang/LLVM. + # Check if a Visual Studio project is being generated with the Clang toolset. + if(MSVC) + set(MSVC_CLANG TRUE) + endif() + elseif(CMAKE_COMPILER_IS_GNUCC) + set(USE_GCC TRUE) + elseif(CMAKE_C_COMPILER_ID MATCHES "^Intel$") + set(USE_INTELCC TRUE) + elseif(CMAKE_C_COMPILER_ID MATCHES "QCC") + set(USE_QCC TRUE) + endif() +endmacro() + +function(SDL_AddCommonCompilerFlags TARGET) + option(SDL_WERROR "Enable -Werror" OFF) + + if(USE_GCC OR USE_CLANG OR USE_INTELCC OR USE_QCC) + if(MINGW) + # See if GCC's -gdwarf-4 is supported + # See https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101377 for why this is needed on Windows + cmake_push_check_state() + check_c_compiler_flag("-gdwarf-4" HAVE_GDWARF_4) + if(HAVE_GDWARF_4) + target_compile_options(${TARGET} PRIVATE "-gdwarf-4") + endif() + cmake_pop_check_state() + endif() + + # Check for -Wall first, so later things can override pieces of it. + # Note: clang-cl treats -Wall as -Weverything (which is very loud), + # /W3 as -Wall, and /W4 as -Wall -Wextra. So: /W3 is enough. + check_c_compiler_flag(-Wall HAVE_GCC_WALL) + if(MSVC_CLANG) + target_compile_options(${TARGET} PRIVATE "/W3") + elseif(HAVE_GCC_WALL) + target_compile_options(${TARGET} PRIVATE "-Wall") + if(HAIKU) + target_compile_options(${TARGET} PRIVATE "-Wno-multichar") + endif() + endif() + + check_c_compiler_flag(-Wundef HAVE_GCC_WUNDEF) + if(HAVE_GCC_WUNDEF) + target_compile_options(${TARGET} PRIVATE "-Wundef") + endif() + + check_c_compiler_flag(-fno-strict-aliasing HAVE_GCC_NO_STRICT_ALIASING) + if(HAVE_GCC_NO_STRICT_ALIASING) + target_compile_options(${TARGET} PRIVATE "-fno-strict-aliasing") + endif() + + check_c_compiler_flag(-Wdocumentation HAVE_GCC_WDOCUMENTATION) + if(HAVE_GCC_WDOCUMENTATION) + if(SDL_WERROR) + check_c_compiler_flag(-Werror=documentation HAVE_GCC_WERROR_DOCUMENTATION) + if(HAVE_GCC_WERROR_DOCUMENTATION) + target_compile_options(${TARGET} PRIVATE "-Werror=documentation") + endif() + endif() + target_compile_options(${TARGET} PRIVATE "-Wdocumentation") + endif() + + check_c_compiler_flag(-Wdocumentation-unknown-command HAVE_GCC_WDOCUMENTATION_UNKNOWN_COMMAND) + if(HAVE_GCC_WDOCUMENTATION_UNKNOWN_COMMAND) + if(SDL_WERROR) + check_c_compiler_flag(-Werror=documentation-unknown-command HAVE_GCC_WERROR_DOCUMENTATION_UNKNOWN_COMMAND) + if(HAVE_GCC_WERROR_DOCUMENTATION_UNKNOWN_COMMAND) + target_compile_options(${TARGET} PRIVATE "-Werror=documentation-unknown-command") + endif() + endif() + target_compile_options(${TARGET} PRIVATE "-Wdocumentation-unknown-command") + endif() + + check_c_compiler_flag(-fcomment-block-commands=threadsafety HAVE_GCC_COMMENT_BLOCK_COMMANDS) + if(HAVE_GCC_COMMENT_BLOCK_COMMANDS) + target_compile_options(${TARGET} PRIVATE "-fcomment-block-commands=threadsafety") + else() + check_c_compiler_flag(/clang:-fcomment-block-commands=threadsafety HAVE_CLANG_COMMENT_BLOCK_COMMANDS) + if(HAVE_CLANG_COMMENT_BLOCK_COMMANDS) + target_compile_options(${TARGET} PRIVATE "/clang:-fcomment-block-commands=threadsafety") + endif() + endif() + + check_c_compiler_flag(-Wshadow HAVE_GCC_WSHADOW) + if(HAVE_GCC_WSHADOW) + target_compile_options(${TARGET} PRIVATE "-Wshadow") + endif() + + check_c_compiler_flag(-Wunused-local-typedefs HAVE_GCC_WUNUSED_LOCAL_TYPEDEFS) + if(HAVE_GCC_WUNUSED_LOCAL_TYPEDEFS) + target_compile_options(${TARGET} PRIVATE "-Wno-unused-local-typedefs") + endif() + endif() + + if(SDL_WERROR) + if(MSVC) + check_c_compiler_flag(/WX HAVE_WX) + if(HAVE_WX) + target_compile_options(${TARGET} PRIVATE "/WX") + endif() + elseif(USE_GCC OR USE_CLANG OR USE_INTELCC OR USE_QNX) + check_c_compiler_flag(-Werror HAVE_WERROR) + if(HAVE_WERROR) + target_compile_options(${TARGET} PRIVATE "-Werror") + endif() + endif() + endif() + + if(USE_CLANG) + check_c_compiler_flag("-fcolor-diagnostics" COMPILER_SUPPORTS_FCOLOR_DIAGNOSTICS) + if(COMPILER_SUPPORTS_FCOLOR_DIAGNOSTICS) + target_compile_options(${TARGET} PRIVATE "-fcolor-diagnostics") + endif() + else() + check_c_compiler_flag("-fdiagnostics-color=always" COMPILER_SUPPORTS_FDIAGNOSTICS_COLOR_ALWAYS) + if(COMPILER_SUPPORTS_FDIAGNOSTICS_COLOR_ALWAYS) + target_compile_options(${TARGET} PRIVATE "-fdiagnostics-color=always") + endif() + endif() +endfunction() diff --git a/cmake/sdlfind.cmake b/cmake/sdlfind.cmake deleted file mode 100644 index 3f49a5788..000000000 --- a/cmake/sdlfind.cmake +++ /dev/null @@ -1,8 +0,0 @@ -macro(sdlFindALSA) - find_package(ALSA MODULE) - if(ALSA_FOUND AND NOT TARGET ALSA::ALSA) - add_Library(ALSA::ALSA UNKNOWN IMPORTED) - set_property(TARGET ALSA::ALSA PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${ALSA_INCLUDE_DIRS}") - set_property(TARGET ALSA::ALSA APPEND PROPERTY IMPORTED_LOCATION "${ALSA_LIBRARY}") - endif() -endmacro() diff --git a/cmake/sdlplatform.cmake b/cmake/sdlplatform.cmake index 4524867de..ebb2077fb 100644 --- a/cmake/sdlplatform.cmake +++ b/cmake/sdlplatform.cmake @@ -13,10 +13,7 @@ macro(SDL_DetectCMakePlatform) elseif(CMAKE_SYSTEM_NAME MATCHES ".*tvOS.*") set(SDL_CMAKE_PLATFORM tvOS) elseif(CMAKE_SYSTEM_NAME MATCHES ".*iOS.*") - # !!! FIXME: remove the version check when we start requiring >= 3.14.0 - if(CMAKE_VERSION VERSION_LESS 3.14) - set(SDL_CMAKE_PLATFORM iOS) - endif() + set(SDL_CMAKE_PLATFORM iOS) endif() elseif(CMAKE_SYSTEM_NAME MATCHES "Haiku.*") set(SDL_CMAKE_PLATFORM Haiku) @@ -57,7 +54,7 @@ macro(SDL_DetectCMakePlatform) elseif(CMAKE_SYSTEM_NAME MATCHES "QNX.*") set(SDL_CMAKE_PLATFORM QNX) elseif(CMAKE_SYSTEM_NAME MATCHES "BeOS.*") - message_error("BeOS support has been removed as of SDL 2.0.2.") + message(FATAL_ERROR "BeOS support has been removed as of SDL 2.0.2.") endif() if(SDL_CMAKE_PLATFORM) diff --git a/cmake/sdltargets.cmake b/cmake/sdltargets.cmake new file mode 100644 index 000000000..46496239e --- /dev/null +++ b/cmake/sdltargets.cmake @@ -0,0 +1,361 @@ +add_library(SDL3-collector INTERFACE) +add_library(SDL3_test-collector INTERFACE) + +# Use sdl_glob_sources to add glob sources to SDL3-shared, to SDL3-static, or to both. +function(sdl_glob_sources) + cmake_parse_arguments(ARGS "" "" "SHARED;STATIC" ${ARGN}) + file(GLOB shared_sources ${ARGS_SHARED}) + file(GLOB static_sources ${ARGS_STATIC}) + file(GLOB both_sources ${ARGS_UNPARSED_ARGUMENTS}) + if(TARGET SDL3-shared) + target_sources(SDL3-shared PRIVATE ${shared_sources} ${both_sources}) + endif() + if(TARGET SDL3-static) + target_sources(SDL3-static PRIVATE ${static_sources} ${both_sources}) + endif() + set_property(TARGET SDL3-collector APPEND PROPERTY INTERFACE_SOURCES ${shared_sources} ${static_sources} ${both_sources}) +endfunction() + +# Use sdl_sources to add sources to SDL3-shared, to SDL3-static, or to both. +function(sdl_sources) + cmake_parse_arguments(ARGS "" "" "SHARED;STATIC" ${ARGN}) + if(TARGET SDL3-shared) + target_sources(SDL3-shared PRIVATE ${ARGS_SHARED} ${ARGS_UNPARSED_ARGUMENTS}) + endif() + if(TARGET SDL3-static) + target_sources(SDL3-static PRIVATE ${ARGS_STATIC} ${ARGS_UNPARSED_ARGUMENTS}) + endif() + set_property(TARGET SDL3-collector APPEND PROPERTY INTERFACE_SOURCES ${ARGS_SHARED} ${ARGS_STATIC} ${ARGS_UNPARSED_ARGUMENTS}) +endfunction() + +# Use sdl_generic_link_dependency to describe a private depency of SDL3. All options are optional. +# Users should use sdl_link_dependency and sdl_test_link_dependency instead +# - SHARED_TARGETS: shared targets to add this dependency to +# - STATIC_TARGETS: static targets to add this dependency to +# - COLLECTOR: target that stores information, for pc and Config.cmake generation. +# - INCLUDES: the include directories of the dependency +# - PKG_CONFIG_PREFIX: name of the prefix, when using the functions of FindPkgConfig +# - PKG_CONFIG_SPECS: pkg-config spec, used as argument for the functions of FindPkgConfig +# - PKG_CONFIG_LIBS: libs that will only end up in the Libs.private of sdl3.pc +# - CMAKE_MODULE: CMake module name of the dependency, used as argument of find_package +# - LIBS: list of libraries to link to +# - LINK_OPTIONS: list of link options +function(sdl_generic_link_dependency ID) + cmake_parse_arguments(ARGS "" "COLLECTOR" "SHARED_TARGETS;STATIC_TARGETS;INCLUDES;PKG_CONFIG_LIBS;PKG_CONFIG_PREFIX;PKG_CONFIG_SPECS;CMAKE_MODULE;LIBS;LINK_OPTIONS" ${ARGN}) + foreach(target IN LISTS ARGS_SHARED_TARGETS) + if(TARGET ${target}) + target_include_directories(${target} SYSTEM PRIVATE ${ARGS_INCLUDES}) + target_link_libraries(${target} PRIVATE ${ARGS_LIBS}) + target_link_options(${target} PRIVATE ${ARGS_LINK_OPTIONS}) + endif() + endforeach() + foreach(target IN LISTS ARGS_STATIC_TARGETS) + if(TARGET ${target}) + target_include_directories(${target} SYSTEM PRIVATE ${ARGS_INCLUDES}) + target_link_libraries(${target} PRIVATE ${ARGS_LIBS}) + target_link_options(${target} INTERFACE ${ARGS_LINK_OPTIONS}) + endif() + endforeach() + get_property(ids TARGET ${ARGS_COLLECTOR} PROPERTY INTERFACE_SDL_DEP_IDS) + if(NOT ID IN_LIST ids) + set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_IDS ${ID}) + endif() + set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_PREFIX ${ARGS_PKG_CONFIG_PREFIX}) + set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_SPECS ${ARGS_PKG_CONFIG_SPECS}) + set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_LIBS ${ARGS_PKG_CONFIG_LIBS}) + set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_LIBS ${ARGS_LIBS}) + set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_LINK_OPTIONS ${ARGS_LINK_OPTIONS}) + set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_CMAKE_MODULE ${ARGS_CMAKE_MODULE}) + set_property(TARGET ${ARGS_COLLECTOR} APPEND PROPERTY INTERFACE_SDL_DEP_${ID}_INCLUDES ${ARGS_INCLUDES}) +endfunction() + +function(sdl_link_dependency ) + sdl_generic_link_dependency(${ARGN} COLLECTOR SDL3-collector SHARED_TARGETS SDL3-shared STATIC_TARGETS SDL3-static) +endfunction() + +function(sdl_test_link_dependency ) + sdl_generic_link_dependency(${ARGN} COLLECTOR SDL3_test-collector STATIC_TARGETS SDL3_test) +endfunction() + +macro(_get_ARGS_visibility) + set(_conflict FALSE) + set(visibility) + if(ARGS_PRIVATE) + set(visibility PRIVATE) + elseif(ARGS_PUBLIC) + if(visibility) + set(_conflict TRUE) + endif() + set(visibility PUBLIC) + elseif(ARGS_INTERFACE) + if(visibility) + set(_conflict TRUE) + endif() + set(visibility INTERFACE) + endif() + if(_conflict OR NOT visibility) + message(FATAL_ERROR "PRIVATE/PUBLIC/INTERFACE must be used exactly once") + endif() + unset(_conflict) +endmacro() + +# Use sdl_link_dependency to add compile definitions to the SDL3 libraries. +function(sdl_compile_definitions) + cmake_parse_arguments(ARGS "PRIVATE;PUBLIC;INTERFACE;NO_EXPORT" "" "" ${ARGN}) + _get_ARGS_visibility() + if(TARGET SDL3-shared) + target_compile_definitions(SDL3-shared ${visibility} ${ARGS_UNPARSED_ARGUMENTS}) + endif() + if(TARGET SDL3-static) + target_compile_definitions(SDL3-static ${visibility} ${ARGS_UNPARSED_ARGUMENTS}) + endif() + if(NOT ARGS_NO_EXPORT AND (ARGS_PUBLIC OR ARGS_INTERFACE)) + set_property(TARGET SDL3-collector APPEND PROPERTY INTERFACE_COMPILE_DEFINITIONS "${ARGS_UNPARSED_ARGUMENTS}") + endif() +endfunction() + +# Use sdl_link_dependency to add compile options to the SDL3 libraries. +function(sdl_compile_options) + cmake_parse_arguments(ARGS "PRIVATE;PUBLIC;INTERFACE;NO_EXPORT" "" "" ${ARGN}) + _get_ARGS_visibility() + set(escaped_opts ${ARGS_UNPARSED_ARGUMENTS}) + if(ARGS_NO_EXPORT) + set(escaped_opts "$") + endif() + if(TARGET SDL3-shared) + target_compile_options(SDL3-shared ${visibility} ${escaped_opts}) + endif() + if(TARGET SDL3-static) + target_compile_options(SDL3-static ${visibility} ${escaped_opts}) + endif() + if(NOT ARGS_NO_EXPORT AND (ARGS_PUBLIC OR ARGS_INTERFACE)) + set_property(TARGET SDL3-collector APPEND PROPERTY INTERFACE_COMPILE_COMPILE_OPTIONS "${ARGS_UNPARSED_ARGUMENTS}") + endif() +endfunction() + +# Use sdl_link_dependency to add incude directories to the SDL3 libraries. +function(sdl_include_directories) + cmake_parse_arguments(ARGS "SYSTEM;BEFORE;AFTER;PRIVATE;PUBLIC;INTERFACE;NO_EXPORT" "" "" ${ARGN}) + set(system "") + if(ARGS_SYSTEM) + set(system "SYSTEM") + endif() + set(before_after ) + if(ARGS_AFTER) + set(before_after "AFTER") + endif() + if(ARGS_BEFORE) + if(before_after) + message(FATAL_ERROR "before and after are exclusive options") + endif() + set(before_after "BEFORE") + endif() + _get_ARGS_visibility() + if(TARGET SDL3-shared) + target_include_directories(SDL3-shared ${system} ${before_after} ${visibility} ${ARGS_UNPARSED_ARGUMENTS}) + endif() + if(TARGET SDL3-static) + target_include_directories(SDL3-static ${system} ${before_after} ${visibility} ${ARGS_UNPARSED_ARGUMENTS}) + endif() + if(NOT NO_EXPORT AND (ARGS_PUBLIC OR ARGS_INTERFACE)) + set_property(TARGET SDL3-collector APPEND PROPERTY INTERFACE_INCLUDE_DIRECTORIES "${ARGS_UNPARSED_ARGUMENTS}") + endif() +endfunction() + +# Use sdl_link_dependency to add link directories to the SDL3 libraries. +function(sdl_link_directories) + if(TARGET SDL3-shared) + target_link_directories(SDL3-shared PRIVATE ${ARGN}) + endif() + if(TARGET SDL3-static) + target_link_directories(SDL3-static INTERFACE ${ARGN}) + endif() +endfunction() + +# Use sdl_pc_link_options to add a link option, only visible in sdl3.pc +function(sdl_pc_link_options) + set_property(TARGET SDL3-collector APPEND PROPERTY INTERFACE_SDL_PC_LINK_OPTIONS "${ARGN}") +endfunction() + +# Use sdl_pc_link_options to add a link option only to SDL3-shared +function(sdl_shared_link_options) + if(TARGET SDL3-shared) + target_link_options(SDL3-shared PRIVATE ${ARGN}) + endif() +endfunction() + +# Return minimum list of custom SDL CMake modules, used for finding dependencies of SDL. +function(sdl_cmake_config_required_modules OUTPUT) + set(cmake_modules) + foreach(collector SDL3-collector SDL3_test-collector) + get_property(ids TARGET ${collector} PROPERTY INTERFACE_SDL_DEP_IDS) + foreach(ID IN LISTS ids) + get_property(CMAKE_MODULE TARGET ${collector} PROPERTY INTERFACE_SDL_DEP_${ID}_CMAKE_MODULE) + if(CMAKE_MODULE) + if(EXISTS "${SDL3_SOURCE_DIR}/cmake/Find${CMAKE_MODULE}.cmake") + list(APPEND cmake_modules "${SDL3_SOURCE_DIR}/cmake/Find${CMAKE_MODULE}.cmake") + endif() + endif() + endforeach() + if(cmake_modules) + list(APPEND cmake_modules "${SDL3_SOURCE_DIR}/cmake/PkgConfigHelper.cmake") + endif() + endforeach() + set(${OUTPUT} "${cmake_modules}" PARENT_SCOPE) +endfunction() + +# Generate string for SDL3Config.cmake, finding all pkg-config dependencies of SDL3. +function(sdl_cmake_config_find_pkg_config_commands OUTPUT) + cmake_parse_arguments(ARGS "" "COLLECTOR;CONFIG_COMPONENT_FOUND_NAME" "" ${ARGN}) + if(NOT ARGS_COLLECTOR OR NOT ARGS_CONFIG_COMPONENT_FOUND_NAME) + message(FATAL_ERROR "COLLECTOR AND CONFIG_COMPONENT_FOUND_NAME are required arguments") + endif() + get_property(ids TARGET ${ARGS_COLLECTOR} PROPERTY INTERFACE_SDL_DEP_IDS) + + set(static_pkgconfig_deps_checks) + set(static_module_deps_checks) + set(cmake_modules_seen) + + foreach(ID IN LISTS ids) + get_property(PKG_CONFIG_PREFIX TARGET ${ARGS_COLLECTOR} PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_PREFIX) + get_property(PKG_CONFIG_SPECS TARGET ${ARGS_COLLECTOR} PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_SPECS) + get_property(CMAKE_MODULE TARGET ${ARGS_COLLECTOR} PROPERTY INTERFACE_SDL_DEP_${ID}_CMAKE_MODULE) + if(CMAKE_MODULE AND NOT CMAKE_MODULE IN_LIST cmake_modules_seen) + list(APPEND static_module_deps_checks + "find_package(${CMAKE_MODULE})" + "if(NOT ${CMAKE_MODULE}_FOUND)" + " set(${ARGS_CONFIG_COMPONENT_FOUND_NAME} OFF)" + "endif()" + ) + list(APPEND cmake_modules_seen ${CMAKE_MODULE}) + endif() + if(PKG_CONFIG_PREFIX AND PKG_CONFIG_SPECS) + string(JOIN " " pkg_config_specs_str ${PKG_CONFIG_SPECS}) + list(APPEND static_pkgconfig_deps_checks + " pkg_check_modules(${PKG_CONFIG_PREFIX} QUIET IMPORTED_TARGET ${pkg_config_specs_str})" + " if(NOT ${PKG_CONFIG_PREFIX}_FOUND)" + " set(${ARGS_CONFIG_COMPONENT_FOUND_NAME} OFF)" + " endif()" + ) + endif() + endforeach() + + set(prefix " ") + + set(static_module_deps_texts) + if(static_module_deps_checks) + set(static_module_deps_texts + [[set(_original_module_path "${CMAKE_MODULE_PATH}")]] + [[list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}")]] + ${static_module_deps_checks} + [[set(CMAKE_MODULE_PATH "${_original_module_path}")]] + [[unset(_original_module_path)]] + ) + endif() + + set(static_pkgconfig_deps_texts) + if(static_pkgconfig_deps_checks) + string(JOIN "\n${prefix}" static_deps_texts_str ${static_deps_texts}) + list(APPEND static_pkgconfig_deps_texts + "find_package(PkgConfig)" + "if(PkgConfig_FOUND)" + ${static_pkgconfig_deps_checks} + "else()" + " set(${ARGS_CONFIG_COMPONENT_FOUND_NAME} OFF)" + "endif()" + ) + endif() + + set(text) + string(JOIN "\n${prefix}" text ${static_module_deps_texts} ${static_pkgconfig_deps_texts}) + if(text) + set(text "${prefix}${text}") + endif() + + set(${OUTPUT} "${text}" PARENT_SCOPE) +endfunction() + +# Create sdl3.pc. +function(configure_sdl3_pc) + # Clean up variables for sdl3.pc + if(TARGET SDL3-shared) + set(SDL_PC_SECTION_LIBS_PRIVATE "\nLibs.private:") + else() + set(SDL_PC_SECTION_LIBS_PRIVATE "") + endif() + + get_property(ids TARGET SDL3-collector PROPERTY SDL3-collector PROPERTY INTERFACE_SDL_DEP_IDS) + + set(private_requires) + set(private_libs) + set(private_ldflags) + + foreach(ID IN LISTS ids) + get_property(CMAKE_MODULE TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_CMAKE_MODULE) + get_property(PKG_CONFIG_SPECS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_SPECS) + get_property(PKG_CONFIG_LIBS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_LIBS) + get_property(LIBS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_LIBS) + get_property(LINK_OPTIONS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_LINK_OPTIONS) + + list(APPEND private_requires ${PKG_CONFIG_SPECS}) + list(APPEND private_libs ${PKG_CONFIG_LIBS}) + if(NOT PKG_CONFIG_SPECS AND NOT CMAKE_MODULE) + list(APPEND private_libs ${LIBS}) + list(APPEND private_ldflags ${LINK_OPTIONS}) + endif() + endforeach() + + list(TRANSFORM private_libs PREPEND "-l") + set(SDL_PC_STATIC_LIBS ${private_ldflags} ${private_libs}) + list(REMOVE_DUPLICATES SDL_PC_STATIC_LIBS) + string(JOIN " " SDL_PC_STATIC_LIBS ${SDL_PC_STATIC_LIBS}) + + string(JOIN " " SDL_PC_PRIVATE_REQUIRES ${private_requires}) + string(REGEX REPLACE "(>=|>|=|<|<=)" [[ \1 ]] SDL_PC_PRIVATE_REQUIRES "${SDL_PC_PRIVATE_REQUIRES}") + + get_property(interface_defines TARGET SDL3-collector PROPERTY INTERFACE_COMPILE_DEFINITIONS) + list(TRANSFORM interface_defines PREPEND "-D") + get_property(interface_includes TARGET SDL3-collector PROPERTY INTERFACE_INCLUDE_DIRECTORIES) + list(TRANSFORM interface_includes PREPEND "-I") + set(SDL_PC_CFLAGS ${interface_defines} ${interface_includes}) + string(JOIN " " SDL_PC_CFLAGS ${SDL_PC_CFLAGS}) + + get_property(SDL_PC_LIBS TARGET SDL3-collector PROPERTY INTERFACE_SDL_PC_LINK_OPTIONS) + string(JOIN " " SDL_PC_LIBS ${SDL_PC_LIBS}) + + string(REGEX REPLACE "-lSDL3( |$)" "-l${sdl_static_libname} " SDL_PC_STATIC_LIBS "${SDL_PC_STATIC_LIBS}") + if(NOT SDL_SHARED) + string(REGEX REPLACE "-lSDL3( |$)" "-l${sdl_static_libname} " SDL_PC_LIBS "${SDL_PC_LIBS}") + endif() + if(TARGET SDL3-shared AND TARGET SDL3-static AND NOT sdl_static_libname STREQUAL "SDL3") + message(STATUS "\"pkg-config --static --libs sdl3\" will return invalid information") + endif() + + # Calculate prefix relative to location of sdl3.pc + file(RELATIVE_PATH SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG "${CMAKE_INSTALL_PREFIX}/${SDL_PKGCONFIG_INSTALLDIR}" "${CMAKE_INSTALL_PREFIX}") + string(REGEX REPLACE "[/]+$" "" SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG "${SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG}") + set(SDL_PKGCONFIG_PREFIX "\${pcfiledir}/${SDL_PATH_PREFIX_RELATIVE_TO_PKGCONFIG}") + + configure_file("${SDL3_SOURCE_DIR}/cmake/sdl3.pc.in" "${SDL3_BINARY_DIR}/sdl3.pc" @ONLY) +endfunction() + +# Write list of dependencies to output. Only visible when configuring with --log-level=DEBUG. +function(debug_show_sdl_deps) + get_property(ids TARGET SDL3-collector PROPERTY SDL3-collector PROPERTY INTERFACE_SDL_DEP_IDS) + + foreach(ID IN LISTS ids) + message(DEBUG "- id: ${ID}") + get_property(INCLUDES TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_INCLUDES) + get_property(CMAKE_MODULE TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_CMAKE_MODULE) + get_property(PKG_CONFIG_PREFIX TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_PREFIX) + get_property(PKG_CONFIG_SPECS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_PKG_CONFIG_SPECS) + get_property(LIBS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_LIBS) + get_property(LINK_OPTIONS TARGET SDL3-collector PROPERTY INTERFACE_SDL_DEP_${ID}_LINK_OPTIONS) + message(DEBUG " INCLUDES: ${INCLUDES}") + message(DEBUG " CMAKE_MODULE: ${CMAKE_MODULE}") + message(DEBUG " PKG_CONFIG_PREFIX: ${PKG_CONFIG_PREFIX}") + message(DEBUG " PKG_CONFIG_SPECS: ${PKG_CONFIG_SPECS}") + message(DEBUG " LIBS: ${LIBS}") + message(DEBUG " LINK_OPTIONS: ${LINK_OPTIONS}") + endforeach() +endfunction() diff --git a/include/build_config/SDL_build_config.h.cmake b/include/build_config/SDL_build_config.h.cmake index 8629f33dd..9ce6c437a 100644 --- a/include/build_config/SDL_build_config.h.cmake +++ b/include/build_config/SDL_build_config.h.cmake @@ -67,7 +67,6 @@ #cmakedefine HAVE_SYS_TYPES_H 1 #cmakedefine HAVE_WCHAR_H 1 #cmakedefine HAVE_PTHREAD_NP_H 1 -#cmakedefine HAVE_LIBUNWIND_H 1 /* C library functions */ #cmakedefine HAVE_DLOPEN 1 @@ -195,7 +194,6 @@ #cmakedefine HAVE_SYSCTLBYNAME 1 #cmakedefine HAVE_CLOCK_GETTIME 1 #cmakedefine HAVE_GETPAGESIZE 1 -#cmakedefine HAVE_MPROTECT 1 #cmakedefine HAVE_ICONV 1 #cmakedefine HAVE_PTHREAD_SETNAME_NP 1 #cmakedefine HAVE_PTHREAD_SET_NAME_NP 1 diff --git a/include/build_config/SDL_build_config_emscripten.h b/include/build_config/SDL_build_config_emscripten.h index 625ae5ff9..2503e98df 100644 --- a/include/build_config/SDL_build_config_emscripten.h +++ b/include/build_config/SDL_build_config_emscripten.h @@ -152,7 +152,6 @@ #define HAVE_SYSCONF 1 #define HAVE_CLOCK_GETTIME 1 /* #undef HAVE_GETPAGESIZE */ -#define HAVE_MPROTECT 1 #define HAVE_ICONV 1 /* SDL internal assertion support */ diff --git a/include/build_config/SDL_build_config_ios.h b/include/build_config/SDL_build_config_ios.h index 6e480a005..c180ef849 100644 --- a/include/build_config/SDL_build_config_ios.h +++ b/include/build_config/SDL_build_config_ios.h @@ -42,8 +42,6 @@ #define HAVE_STRING_H 1 #define HAVE_SYS_TYPES_H 1 #define HAVE_WCHAR_H 1 -/* The libunwind functions are only available on x86 */ -/* #undef HAVE_LIBUNWIND_H */ /* C library functions */ #define HAVE_DLOPEN 1 diff --git a/src/video/x11/SDL_x11modes.c b/src/video/x11/SDL_x11modes.c index b62402329..dad39d813 100644 --- a/src/video/x11/SDL_x11modes.c +++ b/src/video/x11/SDL_x11modes.c @@ -367,7 +367,7 @@ static SDL_bool CheckXRandR(Display *display, int *major, int *minor) #endif return SDL_FALSE; } -#endif /* XRANDR_ENABLED_BY_DEFAULT */ +#endif /* XRANDR_DISABLED_BY_DEFAULT */ if (!SDL_X11_HAVE_XRANDR) { #ifdef X11MODES_DEBUG diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 40b18c073..679a602aa 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -1,13 +1,12 @@ # # CMake script for building the SDL tests # - if(SDL_TESTS_LINK_SHARED) set(sdl_name_component SDL3-shared) else() set(sdl_name_component SDL3-static) endif() -set(HAVE_TESTS_LINK_SHARED "${SDL_TESTS_LINK_SHARED}") +set(HAVE_TESTS_LINK_SHARED "${SDL_TESTS_LINK_SHARED}" PARENT_SCOPE) # CMake incorrectly detects opengl32.lib being present on MSVC ARM64 if(NOT (MSVC AND SDL_CPU_ARM64)) @@ -18,11 +17,10 @@ endif() set(SDL_TEST_EXECUTABLES) -# FIXME: can be OBJECT library for CMake 3.16 -add_library(sdltests_utils STATIC +add_library(sdltests_utils OBJECT testutils.c ) -target_link_libraries(sdltests_utils PRIVATE SDL3::${sdl_name_component}) +target_link_libraries(sdltests_utils PRIVATE SDL3::Headers) file(GLOB RESOURCE_FILES *.bmp *.wav *.hex moose.dat utf8.txt) set(RESOURCE_FILE_NAMES) @@ -43,6 +41,9 @@ macro(add_sdl_test_executable TARGET) if(NOT AST_SOURCES) message(FATAL_ERROR "add_sdl_test_executable needs at least one source") endif() + if(AST_TESTUTILS) + list(APPEND AST_SOURCES $) + endif() if(AST_NEEDS_RESOURCES) list(APPEND AST_SOURCES ${RESOURCE_FILES}) endif() @@ -51,10 +52,8 @@ macro(add_sdl_test_executable TARGET) else() add_executable(${TARGET} ${AST_SOURCES}) endif() + SDL_AddCommonCompilerFlags(${TARGET}) target_link_libraries(${TARGET} PRIVATE SDL3::SDL3_test SDL3::${sdl_name_component}) - if(AST_TESTUTILS) - target_link_libraries(${TARGET} PRIVATE sdltests_utils) - endif() if(NOT AST_NO_C90 AND NOT SDL_CMAKE_PLATFORM MATCHES "^(n3ds|ps2|psp)$") set_property(TARGET ${TARGET} PROPERTY C_STANDARD 90) set_property(TARGET ${TARGET} PROPERTY C_EXTENSIONS FALSE) @@ -86,7 +85,7 @@ macro(add_sdl_test_executable TARGET) set_property(TARGET ${TARGET} APPEND PROPERTY ADDITIONAL_CLEAN_FILES "$/$$/>") endif() if(AST_BUILD_DEPENDENT) - target_include_directories(${TARGET} BEFORE PRIVATE $) + target_include_directories(${TARGET} BEFORE PRIVATE $) target_include_directories(${TARGET} BEFORE PRIVATE ${SDL3_SOURCE_DIR}/src) endif() @@ -103,10 +102,7 @@ macro(add_sdl_test_executable TARGET) target_compile_definitions(${TARGET} PRIVATE HAVE_OPENGL) endif() - if(TARGET sdl-global-options) - target_link_libraries(${TARGET} PRIVATE $) - endif() - + # FIXME: only add "${SDL3_BINARY_DIR}/include-config-$>" + include paths of external dependencies target_include_directories(${TARGET} PRIVATE "$") endmacro() @@ -189,8 +185,8 @@ set(gamepad_images gamepad_touchpad.bmp ) set(gamepad_image_headers) -find_package(PythonInterp) -if(PYTHONINTERP_FOUND AND NOT PYTHON_VERSION_STRING VERSION_LESS "3.2") +find_package(Python3) +if(Python3_FOUND AND Python3_VERSION VERSION_GREATER_EQUAL "3.2") set(xxd "${CMAKE_CURRENT_SOURCE_DIR}/../cmake/xxd.py") foreach(bmp ${gamepad_images}) get_filename_component(bmp_we "${bmp}" NAME_WE) @@ -199,7 +195,7 @@ if(PYTHONINTERP_FOUND AND NOT PYTHON_VERSION_STRING VERSION_LESS "3.2") # Don't add the 'final' headers to the output, to avoid marking them as GENERATED # (generated files are removed when running the CLEAN target) add_custom_command(OUTPUT "${intermediate}" - COMMAND "${PYTHON_EXECUTABLE}" "${xxd}" -i "${CMAKE_CURRENT_SOURCE_DIR}/${bmp}" "-o" "${intermediate}" + COMMAND Python3::Interpreter "${xxd}" -i "${CMAKE_CURRENT_SOURCE_DIR}/${bmp}" "-o" "${intermediate}" COMMAND "${CMAKE_COMMAND}" -E copy_if_different "${intermediate}" "${final}" DEPENDS "${xxd}" "${bmp}" ) @@ -273,7 +269,7 @@ endif() cmake_push_check_state() if(HAVE_WFORMAT) # Some compilers ignore -Wformat-extra-args without -Wformat - set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wformat") + string(APPEND CMAKE_REQUIRED_FLAGS " -Wformat") endif() check_c_compiler_flag(-Wformat-extra-args HAVE_WFORMAT_EXTRA_ARGS) cmake_pop_check_state() @@ -390,19 +386,13 @@ endif() # Set Apple App ID / Bundle ID. This is needed to launch apps on some Apple # platforms (iOS, for example). if(APPLE) - if(CMAKE_VERSION VERSION_LESS "3.7.0") - # CMake's 'BUILDSYSTEM_TARGETS' property is only available in - # CMake 3.7 and above. - message(WARNING "Unable to set Bundle ID for Apple .app builds due to old CMake (pre 3.7).") - else() - foreach(CURRENT_TARGET ${SDL_TEST_EXECUTABLES}) - set_target_properties("${CURRENT_TARGET}" PROPERTIES - MACOSX_BUNDLE_GUI_IDENTIFIER "org.libsdl.${CURRENT_TARGET}" - MACOSX_BUNDLE_BUNDLE_VERSION "${SDL3_VERSION}" - MACOSX_BUNDLE_SHORT_VERSION_STRING "${SDL3_VERSION}" - ) - endforeach() - endif() + foreach(CURRENT_TARGET ${SDL_TEST_EXECUTABLES}) + set_target_properties("${CURRENT_TARGET}" PROPERTIES + MACOSX_BUNDLE_GUI_IDENTIFIER "org.libsdl.${CURRENT_TARGET}" + MACOSX_BUNDLE_BUNDLE_VERSION "${SDL3_VERSION}" + MACOSX_BUNDLE_SHORT_VERSION_STRING "${SDL3_VERSION}" + ) + endforeach() endif() set(TESTS_ENVIRONMENT