diff options
author | Brad King <brad.king@kitware.com> | 2022-01-18 17:08:48 (GMT) |
---|---|---|
committer | Kitware Robot <kwrobot@kitware.com> | 2022-01-18 17:08:58 (GMT) |
commit | 0604c79c0781ae3e37fa5236fa2d6222f5f806d6 (patch) | |
tree | 545e0f707bee635641c390b385e32cc44304c581 /Modules | |
parent | 8ffa7b7957bf8dd5ec48f61465a72bd7485c411c (diff) | |
parent | 9d1b9a4aa1617e304b9eae1f93648278959717df (diff) | |
download | CMake-0604c79c0781ae3e37fa5236fa2d6222f5f806d6.zip CMake-0604c79c0781ae3e37fa5236fa2d6222f5f806d6.tar.gz CMake-0604c79c0781ae3e37fa5236fa2d6222f5f806d6.tar.bz2 |
Merge topic 'CheckLinkerFlag-update-implementation'
9d1b9a4aa1 CheckLinkerFlag: rely now on internal implementation
660e0d80ae internal/CheckCompilerFlag: rely on common configuration
Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !6860
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/CheckLinkerFlag.cmake | 49 | ||||
-rw-r--r-- | Modules/Internal/CheckCompilerFlag.cmake | 68 | ||||
-rw-r--r-- | Modules/Internal/CheckFlagCommonConfig.cmake | 75 | ||||
-rw-r--r-- | Modules/Internal/CheckLinkerFlag.cmake | 35 |
4 files changed, 116 insertions, 111 deletions
diff --git a/Modules/CheckLinkerFlag.cmake b/Modules/CheckLinkerFlag.cmake index e85e43e..8319216 100644 --- a/Modules/CheckLinkerFlag.cmake +++ b/Modules/CheckLinkerFlag.cmake @@ -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) diff --git a/Modules/Internal/CheckCompilerFlag.cmake b/Modules/Internal/CheckCompilerFlag.cmake index f6a4cc9..3a67691 100644 --- a/Modules/Internal/CheckCompilerFlag.cmake +++ b/Modules/Internal/CheckCompilerFlag.cmake @@ -2,71 +2,15 @@ # 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 -cmake_policy(SET CMP0057 NEW) # if() supports IN_LIST - function(CMAKE_CHECK_COMPILER_FLAG _lang _flag _var) - - if(_lang STREQUAL "C") - set(_lang_src "int main(void) { return 0; }") - set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for C" - FAIL_REGEX "-Werror=.* argument .* is not valid for C") - elseif(_lang STREQUAL "CXX") - set(_lang_src "int main() { return 0; }") - set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+" - FAIL_REGEX "-Werror=.* argument .* is not valid for C\\+\\+") - elseif(_lang STREQUAL "CUDA") - set(_lang_src "__host__ int main() { return 0; }") - set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+" # Host GNU - FAIL_REGEX "argument unused during compilation: .*") # Clang - elseif(_lang STREQUAL "Fortran") - set(_lang_src " program test\n stop\n end program") - set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for Fortran") - elseif(_lang STREQUAL "HIP") - set(_lang_src "__host__ int main() { return 0; }") - set(_lang_fail_regex FAIL_REGEX "argument unused during compilation: .*") # Clang - elseif(_lang STREQUAL "OBJC") - set(_lang_src [=[ -#ifndef __OBJC__ -# error "Not an Objective-C compiler" -#endif -int main(void) { return 0; }]=]) - set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C" # GNU - FAIL_REGEX "argument unused during compilation: .*") # Clang - elseif(_lang STREQUAL "OBJCXX") - set(_lang_src [=[ -#ifndef __OBJC__ -# error "Not an Objective-C++ compiler" -#endif -int main(void) { return 0; }]=]) - set(_lang_fail_regex FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C\\+\\+" # GNU - FAIL_REGEX "argument unused during compilation: .*") # Clang - elseif(_lang STREQUAL "ISPC") - set(_lang_src "float func(uniform int32, float a) { return a / 2.25; }") - else() - message (SEND_ERROR "check_compiler_flag: ${_lang}: unknown language.") - return() - endif() - - get_property (_supported_languages GLOBAL PROPERTY ENABLED_LANGUAGES) - if (NOT _lang IN_LIST _supported_languages) - message (SEND_ERROR "check_compiler_flag: ${_lang}: needs to be enabled before use.") - return() - endif() + cmake_check_flag_common_init("check_compiler_flag" ${_lang} _lang_src _lang_fail_regex) set(CMAKE_REQUIRED_DEFINITIONS ${_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() - check_compiler_flag_common_patterns(_common_patterns) cmake_check_source_compiles(${_lang} "${_lang_src}" @@ -75,9 +19,5 @@ int main(void) { return 0; }]=]) ${_common_patterns} ) - foreach(v IN LISTS _locale_vars) - set(ENV{${v}} ${_locale_vars_saved_${v}}) - endforeach() -endfunction () - -cmake_policy(POP) + cmake_check_flag_common_finish() +endfunction() diff --git a/Modules/Internal/CheckFlagCommonConfig.cmake b/Modules/Internal/CheckFlagCommonConfig.cmake new file mode 100644 index 0000000..3934c02 --- /dev/null +++ b/Modules/Internal/CheckFlagCommonConfig.cmake @@ -0,0 +1,75 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + + +# Do NOT include this module directly into any of your code. It is meant as +# a library for Check*CompilerFlag.cmake and Check*LinkerFlag.cma modules. +# It's content may change in any way between releases. + +include_guard(GLOBAL) +cmake_policy(PUSH) +cmake_policy(SET CMP0054 NEW) # if() quoted variables not dereferenced +cmake_policy(SET CMP0057 NEW) # if() supports IN_LIST + +macro(CMAKE_CHECK_FLAG_COMMON_INIT _FUNC _LANG _SRC _PATTERNS) + if("${_LANG}" STREQUAL "C") + set(${_SRC} "int main(void) { return 0; }") + set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for C" + FAIL_REGEX "-Werror=.* argument .* is not valid for C") + elseif("${_LANG}" STREQUAL "CXX") + set(${_SRC} "int main() { return 0; }") + set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+" + FAIL_REGEX "-Werror=.* argument .* is not valid for C\\+\\+") + elseif("${_LANG}" STREQUAL "CUDA") + set(${_SRC} "__host__ int main() { return 0; }") + set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for C\\+\\+" # Host GNU + FAIL_REGEX "argument unused during compilation: .*") # Clang + elseif("${_LANG}" STREQUAL "Fortran") + set(${_SRC} " program test\n stop\n end program") + set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for Fortran") + elseif("${_LANG}" STREQUAL "HIP") + set(${_SRC} "__host__ int main() { return 0; }") + set(${_PATTERNS} FAIL_REGEX "argument unused during compilation: .*") # Clang + elseif("${_LANG}" STREQUAL "OBJC") + set(${_SRC} [=[ + #ifndef __OBJC__ + # error "Not an Objective-C compiler" + #endif + int main(void) { return 0; }]=]) + set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C" # GNU + FAIL_REGEX "argument unused during compilation: .*") # Clang + elseif("${_LANG}" STREQUAL "OBJCXX") + set(${_SRC} [=[ + #ifndef __OBJC__ + # error "Not an Objective-C++ compiler" + #endif + int main(void) { return 0; }]=]) + set(${_PATTERNS} FAIL_REGEX "command[ -]line option .* is valid for .* but not for Objective-C\\+\\+" # GNU + FAIL_REGEX "argument unused during compilation: .*") # Clang + elseif("${_LANG}" STREQUAL "ISPC") + set(${_SRC} "float func(uniform int32, float a) { return a / 2.25; }") + else() + message (SEND_ERROR "${_FUNC}: ${_LANG}: unknown language.") + return() + endif() + + get_property (_supported_languages GLOBAL PROPERTY ENABLED_LANGUAGES) + if (NOT "${_LANG}" IN_LIST _supported_languages) + message (SEND_ERROR "${_FUNC}: ${_LANG}: needs to be enabled before use.") + return() + endif() + # Normalize locale during test compilation. + set(_locale_vars LC_ALL LC_MESSAGES LANG) + foreach(v IN LISTS _locale_vars) + set(_CMAKE_CHECK_FLAG_COMMON_CONFIG_locale_vars_saved_${v} "$ENV{${v}}") + set(ENV{${v}} C) + endforeach() +endmacro() + +macro(CMAKE_CHECK_FLAG_COMMON_FINISH) + foreach(v IN LISTS _CFCC_locale_vars) + set(ENV{${v}} ${_CMAKE_CHECK_FLAG_COMMON_CONFIG_locale_vars_saved_${v}}) + endforeach() +endmacro() + +cmake_policy(POP) diff --git a/Modules/Internal/CheckLinkerFlag.cmake b/Modules/Internal/CheckLinkerFlag.cmake new file mode 100644 index 0000000..285372a --- /dev/null +++ b/Modules/Internal/CheckLinkerFlag.cmake @@ -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) |