diff options
Diffstat (limited to 'src/contrib/SDL-2.30.2/cmake/macros.cmake')
-rw-r--r-- | src/contrib/SDL-2.30.2/cmake/macros.cmake | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/src/contrib/SDL-2.30.2/cmake/macros.cmake b/src/contrib/SDL-2.30.2/cmake/macros.cmake new file mode 100644 index 0000000..5060923 --- /dev/null +++ b/src/contrib/SDL-2.30.2/cmake/macros.cmake | |||
@@ -0,0 +1,148 @@ | |||
1 | macro(ADD_TO_ALLOPTIONS _NEWNAME) | ||
2 | list(APPEND ALLOPTIONS ${_NEWNAME}) | ||
3 | string(LENGTH ${_NEWNAME} _SLEN) | ||
4 | if(${LONGESTOPTIONNAME} LESS ${_SLEN}) | ||
5 | set(LONGESTOPTIONNAME ${_SLEN}) | ||
6 | endif() | ||
7 | endmacro() | ||
8 | |||
9 | macro(SET_OPTION _NAME _DESC) | ||
10 | add_to_alloptions(${_NAME}) | ||
11 | if(${ARGC} EQUAL 3) | ||
12 | set(_DEFLT ${ARGV2}) | ||
13 | else() | ||
14 | set(_DEFLT OFF) | ||
15 | endif() | ||
16 | option(${_NAME} ${_DESC} ${_DEFLT}) | ||
17 | endmacro() | ||
18 | |||
19 | macro(DEP_OPTION _NAME _DESC _DEFLT _DEPTEST _FAILDFLT) | ||
20 | add_to_alloptions("${_NAME}") | ||
21 | cmake_dependent_option("${_NAME}" "${_DESC}" "${_DEFLT}" "${_DEPTEST}" "${_FAILDFLT}") | ||
22 | endmacro() | ||
23 | |||
24 | macro(OPTION_STRING _NAME _DESC _VALUE) | ||
25 | add_to_alloptions(${_NAME}) | ||
26 | set(${_NAME} ${_VALUE} CACHE STRING "${_DESC}") | ||
27 | set(HAVE_${_NAME} ${_VALUE}) | ||
28 | ENDMACRO() | ||
29 | |||
30 | # Message Output | ||
31 | macro(MESSAGE_WARN _TEXT) | ||
32 | message(WARNING "${_TEXT}") | ||
33 | endmacro() | ||
34 | |||
35 | macro(MESSAGE_ERROR _TEXT) | ||
36 | message(FATAL_ERROR "*** ERROR: ${_TEXT}") | ||
37 | endmacro() | ||
38 | |||
39 | macro(MESSAGE_BOOL_OPTION _NAME _VALUE) | ||
40 | if(${_VALUE}) | ||
41 | message(STATUS " ${_NAME}:\tON") | ||
42 | else() | ||
43 | message(STATUS " ${_NAME}:\tOFF") | ||
44 | endif() | ||
45 | endmacro() | ||
46 | |||
47 | macro(MESSAGE_TESTED_OPTION _NAME) | ||
48 | set(_REQVALUE ${${_NAME}}) | ||
49 | set(_PAD " ") | ||
50 | if(${ARGC} EQUAL 2) | ||
51 | set(_PAD ${ARGV1}) | ||
52 | endif() | ||
53 | string(SUBSTRING "${_NAME}" 0 4 _NAMESTART) | ||
54 | if(_NAMESTART STREQUAL "SDL_") | ||
55 | string(SUBSTRING "${_NAME}" 4 -1 _STRIPPEDNAME) | ||
56 | else() | ||
57 | set(_STRIPPEDNAME "${_NAME}") | ||
58 | endif() | ||
59 | if(NOT HAVE_${_STRIPPEDNAME}) | ||
60 | set(HAVE_${_STRIPPEDNAME} OFF) | ||
61 | elseif("${HAVE_${_STRIPPEDNAME}}" MATCHES "1|TRUE|YES|Y") | ||
62 | set(HAVE_${_STRIPPEDNAME} ON) | ||
63 | endif() | ||
64 | message(STATUS " ${_NAME}${_PAD}(Wanted: ${_REQVALUE}): ${HAVE_${_STRIPPEDNAME}}") | ||
65 | endmacro() | ||
66 | |||
67 | function(LISTTOSTR _LIST _OUTPUT) | ||
68 | if(${ARGC} EQUAL 3) | ||
69 | # prefix for each element | ||
70 | set(_LPREFIX ${ARGV2}) | ||
71 | else() | ||
72 | set(_LPREFIX "") | ||
73 | endif() | ||
74 | # Do not use string(REPLACE ";" " ") here to avoid messing up list | ||
75 | # entries | ||
76 | set(res) | ||
77 | foreach(_ITEM ${${_LIST}}) | ||
78 | set(res "${res} ${_LPREFIX}${_ITEM}") | ||
79 | endforeach() | ||
80 | set(${_OUTPUT} "${res}" PARENT_SCOPE) | ||
81 | endfunction() | ||
82 | |||
83 | macro(LISTTOSTRREV _LIST _OUTPUT) | ||
84 | if(${ARGC} EQUAL 3) | ||
85 | # prefix for each element | ||
86 | set(_LPREFIX ${ARGV2}) | ||
87 | else() | ||
88 | set(_LPREFIX "") | ||
89 | endif() | ||
90 | # Do not use string(REPLACE ";" " ") here to avoid messing up list | ||
91 | # entries | ||
92 | foreach(_ITEM ${${_LIST}}) | ||
93 | set(${_OUTPUT} "${_LPREFIX}${_ITEM} ${${_OUTPUT}}") | ||
94 | endforeach() | ||
95 | endmacro() | ||
96 | |||
97 | if(CMAKE_VERSION VERSION_LESS 3.16.0 OR SDL2_SUBPROJECT) | ||
98 | # - CMake versions <3.16 do not support the OBJC language | ||
99 | # - When SDL is built as a subproject and when the main project does not enable OBJC, | ||
100 | # CMake fails due to missing internal CMake variables (CMAKE_OBJC_COMPILE_OBJECT) | ||
101 | # (reproduced with CMake 3.24.2) | ||
102 | macro(CHECK_OBJC_SOURCE_COMPILES SOURCE VAR) | ||
103 | set(PREV_REQUIRED_DEFS "${CMAKE_REQUIRED_DEFINITIONS}") | ||
104 | set(CMAKE_REQUIRED_DEFINITIONS "-x objective-c ${PREV_REQUIRED_DEFS}") | ||
105 | CHECK_C_SOURCE_COMPILES("${SOURCE}" ${VAR}) | ||
106 | set(CMAKE_REQUIRED_DEFINITIONS "${PREV_REQUIRED_DEFS}") | ||
107 | endmacro() | ||
108 | else() | ||
109 | include(CheckOBJCSourceCompiles) | ||
110 | if (APPLE) | ||
111 | enable_language(OBJC) | ||
112 | endif() | ||
113 | endif() | ||
114 | |||
115 | if(APPLE) | ||
116 | check_language(OBJC) | ||
117 | if(NOT CMAKE_OBJC_COMPILER) | ||
118 | message(WARNING "Cannot find working OBJC compiler.") | ||
119 | endif() | ||
120 | endif() | ||
121 | |||
122 | if(CMAKE_VERSION VERSION_LESS 3.13.0) | ||
123 | macro(target_link_directories _TARGET _SCOPE) | ||
124 | link_directories(${ARGN}) | ||
125 | endmacro() | ||
126 | endif() | ||
127 | |||
128 | # CMP0087: install(CODE) and install(SCRIPT) support generator expressions. | ||
129 | if(POLICY CMP0087) | ||
130 | cmake_policy(SET CMP0087 NEW) | ||
131 | endif() | ||
132 | function(SDL_install_pdb TARGET DIRECTORY) | ||
133 | get_property(type TARGET ${TARGET} PROPERTY TYPE) | ||
134 | if(type MATCHES "^(SHARED_LIBRARY|EXECUTABLE)$") | ||
135 | if(NOT CMAKE_VERSION VERSION_LESS 3.1) | ||
136 | install(FILES $<TARGET_PDB_FILE:${TARGET}> DESTINATION "${DIRECTORY}" OPTIONAL) | ||
137 | endif() | ||
138 | elseif(type STREQUAL "STATIC_LIBRARY") | ||
139 | if(NOT CMAKE_VERSION VERSION_LESS 3.15) | ||
140 | # FIXME: Use $<TARGET_COMPILE_PDB_FILE:${TARGET} once it becomes available (https://gitlab.kitware.com/cmake/cmake/-/issues/25244) | ||
141 | if(CMAKE_GENERATOR MATCHES "^Visual Studio.*") | ||
142 | install(CODE "file(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${DIRECTORY}\" TYPE FILE OPTIONAL FILES \"${CMAKE_CURRENT_BINARY_DIR}/\${CMAKE_INSTALL_CONFIG_NAME}/${TARGET}.pdb\")") | ||
143 | else() | ||
144 | install(CODE "file(INSTALL DESTINATION \"\${CMAKE_INSTALL_PREFIX}/${DIRECTORY}\" TYPE FILE OPTIONAL FILES \"${CMAKE_CURRENT_BINARY_DIR}/CMakeFiles/${TARGET}.dir/${TARGET}.pdb\")") | ||
145 | endif() | ||
146 | endif() | ||
147 | endif() | ||
148 | endfunction() | ||