2022-12-16 19:49:46 -07:00
|
|
|
macro(add_to_alloptions _NEWNAME)
|
2021-10-05 08:54:06 -06:00
|
|
|
list(APPEND ALLOPTIONS ${_NEWNAME})
|
|
|
|
string(LENGTH ${_NEWNAME} _SLEN)
|
|
|
|
if(${LONGESTOPTIONNAME} LESS ${_SLEN})
|
|
|
|
set(LONGESTOPTIONNAME ${_SLEN})
|
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2022-12-16 19:49:46 -07:00
|
|
|
macro(set_option _NAME _DESC)
|
2021-10-05 08:54:06 -06:00
|
|
|
add_to_alloptions(${_NAME})
|
2015-06-21 09:33:46 -06:00
|
|
|
if(${ARGC} EQUAL 3)
|
|
|
|
set(_DEFLT ${ARGV2})
|
|
|
|
else()
|
|
|
|
set(_DEFLT OFF)
|
|
|
|
endif()
|
|
|
|
option(${_NAME} ${_DESC} ${_DEFLT})
|
|
|
|
endmacro()
|
|
|
|
|
2022-12-16 19:49:46 -07:00
|
|
|
macro(dep_option _NAME _DESC _DEFLT _DEPTEST _FAILDFLT)
|
2022-06-06 20:28:55 -06:00
|
|
|
add_to_alloptions("${_NAME}")
|
|
|
|
cmake_dependent_option("${_NAME}" "${_DESC}" "${_DEFLT}" "${_DEPTEST}" "${_FAILDFLT}")
|
2015-06-21 09:33:46 -06:00
|
|
|
endmacro()
|
|
|
|
|
2022-12-16 19:49:46 -07:00
|
|
|
macro(option_string _NAME _DESC _VALUE)
|
2021-10-05 08:54:06 -06:00
|
|
|
add_to_alloptions(${_NAME})
|
2015-06-21 09:33:46 -06:00
|
|
|
set(${_NAME} ${_VALUE} CACHE STRING "${_DESC}")
|
|
|
|
set(HAVE_${_NAME} ${_VALUE})
|
|
|
|
ENDMACRO()
|
|
|
|
|
|
|
|
# Message Output
|
2022-12-16 19:49:46 -07:00
|
|
|
macro(message_warn _TEXT)
|
2022-12-11 16:18:06 -07:00
|
|
|
message(WARNING "${_TEXT}")
|
2015-06-21 09:33:46 -06:00
|
|
|
endmacro()
|
|
|
|
|
2022-12-16 19:49:46 -07:00
|
|
|
macro(message_error _TEXT)
|
2015-06-21 09:33:46 -06:00
|
|
|
message(FATAL_ERROR "*** ERROR: ${_TEXT}")
|
|
|
|
endmacro()
|
|
|
|
|
2022-12-16 19:49:46 -07:00
|
|
|
macro(message_bool_option _NAME _VALUE)
|
2022-08-21 20:11:39 -06:00
|
|
|
set(_PAD "\t")
|
|
|
|
if(${ARGC} EQUAL 3)
|
|
|
|
set(_PAD ${ARGV2})
|
|
|
|
endif()
|
2015-06-21 09:33:46 -06:00
|
|
|
if(${_VALUE})
|
2022-08-21 20:11:39 -06:00
|
|
|
message(STATUS " ${_NAME}:${_PAD}ON")
|
2015-06-21 09:33:46 -06:00
|
|
|
else()
|
2022-08-21 20:11:39 -06:00
|
|
|
message(STATUS " ${_NAME}:${_PAD}OFF")
|
2015-06-21 09:33:46 -06:00
|
|
|
endif()
|
|
|
|
endmacro()
|
|
|
|
|
2022-12-16 19:49:46 -07:00
|
|
|
macro(message_tested_option _NAME)
|
2015-06-21 09:33:46 -06:00
|
|
|
set(_REQVALUE ${${_NAME}})
|
|
|
|
set(_PAD " ")
|
|
|
|
if(${ARGC} EQUAL 2)
|
|
|
|
set(_PAD ${ARGV1})
|
|
|
|
endif()
|
2021-10-05 08:43:35 -06:00
|
|
|
string(SUBSTRING "${_NAME}" 0 4 _NAMESTART)
|
|
|
|
if(_NAMESTART STREQUAL "SDL_")
|
|
|
|
string(SUBSTRING "${_NAME}" 4 -1 _STRIPPEDNAME)
|
|
|
|
else()
|
|
|
|
set(_STRIPPEDNAME "${_NAME}")
|
|
|
|
endif()
|
|
|
|
if(NOT HAVE_${_STRIPPEDNAME})
|
|
|
|
set(HAVE_${_STRIPPEDNAME} OFF)
|
|
|
|
elseif("${HAVE_${_STRIPPEDNAME}}" MATCHES "1|TRUE|YES|Y")
|
|
|
|
set(HAVE_${_STRIPPEDNAME} ON)
|
2015-06-21 09:33:46 -06:00
|
|
|
endif()
|
2021-10-05 08:43:35 -06:00
|
|
|
message(STATUS " ${_NAME}${_PAD}(Wanted: ${_REQVALUE}): ${HAVE_${_STRIPPEDNAME}}")
|
2015-06-21 09:33:46 -06:00
|
|
|
endmacro()
|
|
|
|
|
2022-12-17 18:24:42 -07:00
|
|
|
function(listtostr LIST OUTPUT)
|
2015-06-21 09:33:46 -06:00
|
|
|
if(${ARGC} EQUAL 3)
|
|
|
|
# prefix for each element
|
2022-12-17 18:24:42 -07:00
|
|
|
set(LPREFIX ${ARGV2})
|
2015-06-21 09:33:46 -06:00
|
|
|
else()
|
2022-12-17 18:24:42 -07:00
|
|
|
set(LPREFIX "")
|
2015-06-21 09:33:46 -06:00
|
|
|
endif()
|
2022-12-17 18:24:42 -07:00
|
|
|
# Do not use string(REPLACE ";" " ") here to avoid messing up list entries
|
|
|
|
set(res)
|
|
|
|
foreach(ITEM ${${LIST}})
|
2023-01-07 08:55:32 -07:00
|
|
|
string(SUBSTRING "${ITEM}" 0 6 start)
|
|
|
|
if(start STREQUAL "SHELL:")
|
|
|
|
string(SUBSTRING "${ITEM}" 6 -1 ITEM)
|
|
|
|
endif()
|
2022-12-17 18:24:42 -07:00
|
|
|
if(ITEM)
|
|
|
|
set(res "${res} ${LPREFIX}${ITEM}")
|
|
|
|
endif()
|
2015-06-21 09:33:46 -06:00
|
|
|
endforeach()
|
2023-01-07 08:55:32 -07:00
|
|
|
string(STRIP "${res}" res)
|
2022-12-17 18:24:42 -07:00
|
|
|
set(${OUTPUT} "${res}" PARENT_SCOPE)
|
|
|
|
endfunction()
|
2015-06-21 09:33:46 -06:00
|
|
|
|
2022-08-21 20:11:39 -06:00
|
|
|
function(find_stringlength_longest_item inList outLength)
|
|
|
|
set(maxLength 0)
|
|
|
|
foreach(item IN LISTS ${inList})
|
|
|
|
string(LENGTH "${item}" slen)
|
|
|
|
if(slen GREATER maxLength)
|
|
|
|
set(maxLength ${slen})
|
|
|
|
endif()
|
|
|
|
endforeach()
|
|
|
|
set("${outLength}" ${maxLength} PARENT_SCOPE)
|
|
|
|
endfunction()
|
|
|
|
|
|
|
|
function(message_dictlist inList)
|
|
|
|
find_stringlength_longest_item(${inList} maxLength)
|
|
|
|
foreach(name IN LISTS ${inList})
|
|
|
|
# Get the padding
|
|
|
|
string(LENGTH ${name} nameLength)
|
|
|
|
math(EXPR padLength "(${maxLength} + 1) - ${nameLength}")
|
|
|
|
string(RANDOM LENGTH ${padLength} ALPHABET " " padding)
|
|
|
|
message_tested_option(${name} ${padding})
|
|
|
|
endforeach()
|
|
|
|
endfunction()
|
|
|
|
|
2022-11-21 21:28:58 -07:00
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.16.0 OR SDL3_SUBPROJECT)
|
2022-10-28 19:14:54 -06:00
|
|
|
# - 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)
|
2022-02-05 08:28:24 -07:00
|
|
|
macro(CHECK_OBJC_SOURCE_COMPILES SOURCE VAR)
|
|
|
|
set(PREV_REQUIRED_DEFS "${CMAKE_REQUIRED_DEFINITIONS}")
|
|
|
|
set(CMAKE_REQUIRED_DEFINITIONS "-x objective-c ${PREV_REQUIRED_DEFS}")
|
2022-09-21 01:37:02 -06:00
|
|
|
CHECK_C_SOURCE_COMPILES("${SOURCE}" ${VAR})
|
2022-02-05 08:28:24 -07:00
|
|
|
set(CMAKE_REQUIRED_DEFINITIONS "${PREV_REQUIRED_DEFS}")
|
|
|
|
endmacro()
|
|
|
|
else()
|
|
|
|
include(CheckOBJCSourceCompiles)
|
2022-02-05 08:50:00 -07:00
|
|
|
if (APPLE)
|
|
|
|
enable_language(OBJC)
|
|
|
|
endif()
|
2022-02-05 08:28:24 -07:00
|
|
|
endif()
|
2015-06-21 09:33:46 -06:00
|
|
|
|
build: add symbol versioning for SDL
If a program built against one version of SDL is run in an
environment where there is an earlier version of the SDL .so library
installed, the result varies depending on platform configuration; in
the best case, it won't start at all, at worst it aborts in the
middle of the user doing "something important" (systems implementing
lazy symbol resolution). verdefs on the other hand are always checked
on startup.
The dependency information present in programs and shared libraries
is not only of value to the dynamic linker, but also to a
distribution's package management. If the dynamic linker is able to
tell that a program is not runnable per the above, a package manager
is able to come to the same conclusion — and block the installation
of a nonfunctional program+library ensemble.
Because there are a lot more symbols than there are libraries (I am
going to throw in "10^4 to 1 or worse"), package managers generally
do not evaluate symbols, but only e.g. the SONAME, NEEDED and VERNEED
fields/blocks. Because the SONAME is the same between two SDL
versions like 2.0.24, and 2.0.26, everything rests on having verdefs.
This patch proposes the addition of verdefs.
2022-11-24 12:58:10 -07:00
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.18)
|
|
|
|
function(check_linker_flag LANG FLAG VAR)
|
|
|
|
cmake_push_check_state()
|
|
|
|
list(APPEND CMAKE_REQUIRED_LINK_OPTIONS ${FLAG} )
|
|
|
|
if(LANG STREQUAL "C")
|
|
|
|
include(CheckCSourceCompiles)
|
|
|
|
check_c_source_compiles("int main(int argc,char*argv[]){(void)argc;(void)argv;return 0;}" ${VAR} FAIL_REGEX "warning")
|
|
|
|
elseif(LANG STREQUAL "CXX")
|
|
|
|
include(CheckCXXSourceCompiles)
|
|
|
|
check_cxx_source_compiles("int main(int argc,char*argv[]){(void)argc;(void)argv;return 0;}" ${VAR} FAIL_REGEX "warning")
|
|
|
|
else()
|
|
|
|
message(FATAL_ERROR "Unsupported language: ${LANG}")
|
|
|
|
endif()
|
|
|
|
cmake_pop_check_state()
|
|
|
|
endfunction()
|
|
|
|
else()
|
|
|
|
cmake_policy(SET CMP0057 NEW) # Support new if() IN_LIST operator. (used inside check_linker_flag, used in CMake 3.18)
|
|
|
|
include(CheckLinkerFlag)
|
|
|
|
endif()
|
|
|
|
|
2022-10-28 19:20:30 -06:00
|
|
|
if(APPLE)
|
|
|
|
check_language(OBJC)
|
|
|
|
if(NOT CMAKE_OBJC_COMPILER)
|
|
|
|
message(WARNING "Cannot find working OBJC compiler.")
|
|
|
|
endif()
|
|
|
|
endif()
|
|
|
|
|
2021-12-18 07:14:32 -07:00
|
|
|
if(CMAKE_VERSION VERSION_LESS 3.13.0)
|
|
|
|
macro(target_link_directories _TARGET _SCOPE)
|
|
|
|
link_directories(${ARGN})
|
|
|
|
endmacro()
|
|
|
|
endif()
|