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
main
Anonymous Maarten 2023-02-28 04:20:30 +01:00 committed by Anonymous Maarten
parent a3a9019265
commit 3ab4665956
17 changed files with 1836 additions and 1533 deletions

File diff suppressed because it is too large Load Diff

View File

@ -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()

View File

@ -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()

View File

@ -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()

View File

@ -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)

View File

@ -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()

View File

@ -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@

File diff suppressed because it is too large Load Diff

128
cmake/sdlcompilers.cmake Normal file
View File

@ -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()

View File

@ -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()

View File

@ -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)

361
cmake/sdltargets.cmake Normal file
View File

@ -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 "$<BUILD_INTERFACE:${ARGS_UNPARSED_ARGUMENTS}>")
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()

View File

@ -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

View File

@ -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 */

View File

@ -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

View File

@ -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

View File

@ -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 $<TARGET_OBJECTS:sdltests_utils>)
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 "$<TARGET_FILE_DIR:${TARGET}>/$<JOIN:${RESOURCE_FILE_NAMES},$<SEMICOLON>$<TARGET_FILE_DIR:${TARGET}>/>")
endif()
if(AST_BUILD_DEPENDENT)
target_include_directories(${TARGET} BEFORE PRIVATE $<TARGET_PROPERTY:sdl-build-options,INTERFACE_INCLUDE_DIRECTORIES>)
target_include_directories(${TARGET} BEFORE PRIVATE $<TARGET_PROPERTY:SDL3::${sdl_name_component},INCLUDE_DIRECTORIES>)
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 $<BUILD_INTERFACE:sdl-global-options>)
endif()
# FIXME: only add "${SDL3_BINARY_DIR}/include-config-$<LOWER_CASE:$<CONFIG>>" + include paths of external dependencies
target_include_directories(${TARGET} PRIVATE "$<TARGET_PROPERTY:SDL3::${sdl_name_component},INCLUDE_DIRECTORIES>")
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