mirror of
https://github.com/Kitware/CMake.git
synced 2026-01-11 08:20:18 -06:00
CheckLinkerFlag: rely now on internal implementation
This internal implementation share the configuration with CheckCompilerFlag.
This commit is contained in:
@@ -38,53 +38,8 @@ effect or even a specific one is beyond the scope of this module.
|
||||
#]=======================================================================]
|
||||
|
||||
include_guard(GLOBAL)
|
||||
|
||||
include(CMakeCheckCompilerFlagCommonPatterns)
|
||||
|
||||
cmake_policy(PUSH)
|
||||
cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced
|
||||
cmake_policy(SET CMP0057 NEW) # if() supports IN_LIST
|
||||
include(Internal/CheckLinkerFlag)
|
||||
|
||||
function(CHECK_LINKER_FLAG _lang _flag _var)
|
||||
get_property (_supported_languages GLOBAL PROPERTY ENABLED_LANGUAGES)
|
||||
if (NOT _lang IN_LIST _supported_languages)
|
||||
message (SEND_ERROR "check_linker_flag: ${_lang}: unknown language.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
include (CheckSourceCompiles)
|
||||
|
||||
set(CMAKE_REQUIRED_LINK_OPTIONS "${_flag}")
|
||||
|
||||
# Normalize locale during test compilation.
|
||||
set(_locale_vars LC_ALL LC_MESSAGES LANG)
|
||||
foreach(v IN LISTS _locale_vars)
|
||||
set(_locale_vars_saved_${v} "$ENV{${v}}")
|
||||
set(ENV{${v}} C)
|
||||
endforeach()
|
||||
|
||||
if (_lang MATCHES "^(C|CXX)$")
|
||||
set (_source "int main() { return 0; }")
|
||||
elseif (_lang STREQUAL "Fortran")
|
||||
set (_source " program test\n stop\n end program")
|
||||
elseif (_lang MATCHES "CUDA")
|
||||
set (_source "__host__ int main() { return 0; }")
|
||||
elseif (_lang MATCHES "HIP")
|
||||
set (_source "__host__ int main() { return 0; }")
|
||||
elseif (_lang MATCHES "^(OBJC|OBJCXX)$")
|
||||
set (_source "#ifndef __OBJC__\n# error \"Not an Objective-C++ compiler\"\n#endif\nint main(void) { return 0; }")
|
||||
else()
|
||||
message (SEND_ERROR "check_linker_flag: ${_lang}: unsupported language.")
|
||||
return()
|
||||
endif()
|
||||
check_compiler_flag_common_patterns(_common_patterns)
|
||||
|
||||
check_source_compiles(${_lang} "${_source}" ${_var} ${_common_patterns})
|
||||
|
||||
foreach(v IN LISTS _locale_vars)
|
||||
set(ENV{${v}} ${_locale_vars_saved_${v}})
|
||||
endforeach()
|
||||
set(${_var} "${${_var}}" PARENT_SCOPE)
|
||||
cmake_check_linker_flag(${_lang} "${_flag}" ${_var})
|
||||
endfunction()
|
||||
|
||||
cmake_policy(POP)
|
||||
|
||||
35
Modules/Internal/CheckLinkerFlag.cmake
Normal file
35
Modules/Internal/CheckLinkerFlag.cmake
Normal file
@@ -0,0 +1,35 @@
|
||||
# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
|
||||
# file Copyright.txt or https://cmake.org/licensing for details.
|
||||
|
||||
include_guard(GLOBAL)
|
||||
include(Internal/CheckFlagCommonConfig)
|
||||
include(Internal/CheckSourceCompiles)
|
||||
include(CMakeCheckCompilerFlagCommonPatterns)
|
||||
|
||||
cmake_policy(PUSH)
|
||||
cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced
|
||||
|
||||
function(CMAKE_CHECK_LINKER_FLAG _lang _flag _var)
|
||||
# link step supports less languages than the compiler
|
||||
# so do a first check about the requested language
|
||||
if (_lang STREQUAL "ISPC")
|
||||
message (SEND_ERROR "check_linker_flag: ${_lang}: unsupported language.")
|
||||
return()
|
||||
endif()
|
||||
|
||||
cmake_check_flag_common_init("check_linker_flag" ${_lang} _lang_src _lang_fail_regex)
|
||||
|
||||
set(CMAKE_REQUIRED_LINK_OPTIONS "${_flag}")
|
||||
|
||||
check_compiler_flag_common_patterns(_common_patterns)
|
||||
cmake_check_source_compiles(${_lang}
|
||||
"${_lang_src}"
|
||||
${_var}
|
||||
${_lang_fail_regex}
|
||||
${_common_patterns}
|
||||
)
|
||||
|
||||
cmake_check_flag_common_finish()
|
||||
endfunction()
|
||||
|
||||
cmake_policy(POP)
|
||||
Reference in New Issue
Block a user