diff --git a/CMakeLists.txt b/CMakeLists.txt index a5188e538..0baea1903 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -423,7 +423,7 @@ if(WINDOWS_STORE) 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) +check_linker_supports_version_file(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() diff --git a/cmake/macros.cmake b/cmake/macros.cmake index 32fc9f1a1..de9680047 100644 --- a/cmake/macros.cmake +++ b/cmake/macros.cmake @@ -82,16 +82,25 @@ if(APPLE) enable_language(OBJC) endif() +function(check_linker_supports_version_file VAR) + cmake_push_check_state() + file(WRITE "${CMAKE_CURRENT_BINARY_DIR}/dummy.sym" "n_0 {\n global:\n func;\n local: *;\n};\n") + list(APPEND CMAKE_REQUIRED_LINK_OPTIONS "-Wl,--version-script=${CMAKE_CURRENT_BINARY_DIR}/dummy.sym") + check_c_source_compiles("int func(void) {return 0;} int main(int argc,char*argv[]){(void)argc;(void)argv;return func();}" LINKER_SUPPORTS_VERSION_SCRIPT FAIL_REGEX "(unsupported|syntax error)") + cmake_pop_check_state() + set(${VAR} "${LINKER_SUPPORTS_VERSION_SCRIPT}" PARENT_SCOPE) +endfunction() + 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") + check_c_source_compiles("int main(int argc,char*argv[]){(void)argc;(void)argv;return 0;}" ${VAR} FAIL_REGEX "(unsupported|syntax error)") 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") + check_cxx_source_compiles("int main(int argc,char*argv[]){(void)argc;(void)argv;return 0;}" ${VAR} FAIL_REGEX "(unsupported|syntax error)") else() message(FATAL_ERROR "Unsupported language: ${LANG}") endif()