From 3ab46659564ad25df08a9a5e34d788396aa32bc6 Mon Sep 17 00:00:00 2001
From: Anonymous Maarten <[EMAIL REDACTED]>
Date: Tue, 28 Feb 2023 04:20:30 +0100
Subject: [PATCH] cmake: bump minimum required CMake version to 3.16
main features:
- No more sdl-build-options/sdl-shared-build-options/sdl-global-options
- Dependency information is stored on SDL3-collector for sdl3.pc
- Use helper functions to modify the SDL targets;
- sdl_sources to add sources
- sdl_glob_sources to add glob soruces
- sdl_link_dependency to add a link dependency that might also
appear in sdl3.pc/SDL3Config.cmake
- sdl_compile_definitions to add macro's
- sdl_compile_options for compile options
- sdl_include_directories for include directories
They avoid repeated checks for existence of the SDL targets
- A nice feature of the previous is the ability to generate
a sdl3.pc or SDL3Config.cmake that describes its dependencies
accurately.
various:
- remove duplicate libc symbol list
- add CheckVulkan
- remove unused HAVE_MPROTECT
- add checks for getpagesize
---
CMakeLists.txt | 1878 +++++++----------
cmake/FindRPi_BcmHost.cmake | 75 +
cmake/FindRPi_BrcmEGL.cmake | 59 +
cmake/PkgConfigHelper.cmake | 39 +
cmake/SDL3Config.cmake.in | 34 +-
cmake/macros.cmake | 116 +-
cmake/sdl3.pc.in | 5 +-
cmake/sdlchecks.cmake | 590 +++---
cmake/sdlcompilers.cmake | 128 ++
cmake/sdlfind.cmake | 8 -
cmake/sdlplatform.cmake | 7 +-
cmake/sdltargets.cmake | 361 ++++
include/build_config/SDL_build_config.h.cmake | 2 -
.../SDL_build_config_emscripten.h | 1 -
include/build_config/SDL_build_config_ios.h | 2 -
src/video/x11/SDL_x11modes.c | 2 +-
test/CMakeLists.txt | 50 +-
17 files changed, 1830 insertions(+), 1527 deletions(-)
create mode 100644 cmake/FindRPi_BcmHost.cmake
create mode 100644 cmake/FindRPi_BrcmEGL.cmake
create mode 100644 cmake/PkgConfigHelper.cmake
create mode 100644 cmake/sdlcompilers.cmake
delete mode 100644 cmake/sdlfind.cmake
create mode 100644 cmake/sdltargets.cmake
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c289ad043217..47d0fa62bd0f 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)
-
-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()
+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")
+
+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 )
-
-# When building shared lib for Windows with MinGW,
-# avoid the DLL having a "lib" prefix
-if(WINDOWS)
- set(CMAKE_SHARED_LIBRARY_PREFIX "")
-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)
- 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-$<LOWER_CASE:$<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_DEFAULT ON)
+set(SDL_STATIC_DEFAULT ON)
-set(SDL_SHARED_ENABLED_BY_DEFAULT ON)
-set(SDL_STATIC_ENABLED_BY_DEFAULT ON)
+set(SDL_SHARED_AVAILABLE 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 <SDL3/xxx.h>` 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-$<LOWER_CASE:$<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 "$<BUILD_INTERFACE:-idirafter${SDL3_SOURCE_DIR}/src/video/khronos>")
+else()
+ sdl_include_directories(NO_EXPORT SYSTEM PUBLIC "$<BUILD_INTERFACE:${SDL3_SOURCE_DIR}/src/video/khronos>")
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)
-
(Patch may be truncated, please check the link at the top of this post.)