|
3 | 3 | include(CheckCCompilerFlag) |
4 | 4 | include(CheckCSourceCompiles) |
5 | 5 | include(CMakePushCheckState) |
| 6 | +if(NOT CMAKE_VERSION VERSION_LESS "3.18") |
| 7 | + include(CheckLinkerFlag) |
| 8 | +endif() |
6 | 9 |
|
7 | 10 | macro(sdl_calculate_derived_version_variables MAJOR MINOR MICRO) |
8 | 11 | set(SO_VERSION_MAJOR "0") |
@@ -233,11 +236,14 @@ function(sdl_check_project_in_subfolder relative_subfolder name vendored_option) |
233 | 236 | endfunction() |
234 | 237 |
|
235 | 238 | macro(sdl_check_linker_flag flag var) |
236 | | - # FIXME: Use CheckLinkerFlag module once cmake minimum version >= 3.18 |
237 | | - cmake_push_check_state(RESET) |
238 | | - set(CMAKE_REQUIRED_LINK_OPTIONS "${flag}") |
239 | | - check_c_source_compiles("int main() { return 0; }" ${var} FAIL_REGEX "(unsupported|syntax error|unrecognized option)") |
240 | | - cmake_pop_check_state() |
| 239 | + if(NOT CMAKE_VERSION VERSION_LESS "3.18") |
| 240 | + check_linker_flag(C "${flag}" "${var}") |
| 241 | + else() |
| 242 | + cmake_push_check_state(RESET) |
| 243 | + set(CMAKE_REQUIRED_LINK_OPTIONS "${flag}") |
| 244 | + check_c_source_compiles("int main() { return 0; }" ${var} FAIL_REGEX "(unsupported|syntax error|unrecognized option)") |
| 245 | + cmake_pop_check_state() |
| 246 | + endif() |
241 | 247 | endmacro() |
242 | 248 |
|
243 | 249 | function(SDL_detect_linker) |
@@ -275,7 +281,6 @@ endfunction() |
275 | 281 | function(sdl_target_link_options_no_undefined TARGET) |
276 | 282 | if(NOT MSVC AND NOT CMAKE_SYSTEM_NAME MATCHES ".*OpenBSD.*") |
277 | 283 | if(CMAKE_C_COMPILER_ID MATCHES "AppleClang") |
278 | | - target_link_options(${TARGET} PRIVATE "-Wl,-undefined,error") |
279 | 284 | else() |
280 | 285 | sdl_check_linker_flag("-Wl,--no-undefined" HAVE_WL_NO_UNDEFINED) |
281 | 286 | if(HAVE_WL_NO_UNDEFINED AND NOT ((CMAKE_C_COMPILER_ID MATCHES "Clang") AND WIN32)) |
@@ -310,6 +315,15 @@ function(sdl_add_warning_options TARGET) |
310 | 315 | else() |
311 | 316 | target_compile_options(${TARGET} PRIVATE -Werror) |
312 | 317 | endif() |
| 318 | + get_property(target_type TARGET ${TARGET} PROPERTY TYPE) |
| 319 | + if(NOT (APPLE OR MSVC)) |
| 320 | + if(target_type MATCHES "SHARED_LIBRARY|MODULE_LIBRARY") |
| 321 | + sdl_check_linker_flag("-Wl,-fatal-warnings" HAVE_WL_FATAL_WARNINGS) |
| 322 | + if(HAVE_WL_FATAL_WARNINGS) |
| 323 | + target_link_options(${TARGET} PRIVATE "-Wl,-fatal-warnings") |
| 324 | + endif() |
| 325 | + endif() |
| 326 | + endif() |
313 | 327 | endif() |
314 | 328 | endfunction() |
315 | 329 |
|
|
0 commit comments