diff options
author | Robert Maynard <robert.maynard@kitware.com> | 2020-10-25 16:26:42 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2020-10-26 14:57:55 (GMT) |
commit | d192918586364b98e916887b190da825c1373f7f (patch) | |
tree | 5c753be8114cfd322a88a117c922b4cd20081907 /Modules/CheckCompilerFlag.cmake | |
parent | 9fa7afe7d332ced27264f1ef7c921aa1d95bc476 (diff) | |
download | CMake-d192918586364b98e916887b190da825c1373f7f.zip CMake-d192918586364b98e916887b190da825c1373f7f.tar.gz CMake-d192918586364b98e916887b190da825c1373f7f.tar.bz2 |
Modules: Do not implicitly add new functions via old Check Modules
The conversion of Check<Lang>CompilerFlag, SourceCompiles, and
SourceRuns over to the new functions has the possibility of breaking
projects that had functions with those existing names.
To reduce the possibility of collisions we now have all the
legacy code call functions that start with `cmake_`, and users
will need to explicitly include the new modules to get the
non-prefixed versions
Fixes: #21359
Diffstat (limited to 'Modules/CheckCompilerFlag.cmake')
-rw-r--r-- | Modules/CheckCompilerFlag.cmake | 76 |
1 files changed, 3 insertions, 73 deletions
diff --git a/Modules/CheckCompilerFlag.cmake b/Modules/CheckCompilerFlag.cmake index d7789df..77c07b9 100644 --- a/Modules/CheckCompilerFlag.cmake +++ b/Modules/CheckCompilerFlag.cmake @@ -34,78 +34,8 @@ effect or even a specific one is beyond the scope of this module. #]=======================================================================] include_guard(GLOBAL) -include(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 +include(Internal/CheckCompilerFlag) function(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") - 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\\+\\+") - 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 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() - - 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) - check_source_compiles(${_lang} - "${_lang_src}" - ${_var} - ${_lang_fail_regex} - ${_common_patterns} - ) - - foreach(v IN LISTS _locale_vars) - set(ENV{${v}} ${_locale_vars_saved_${v}}) - endforeach() - set(${_var} "${${_var}}" PARENT_SCOPE) -endfunction () - -cmake_policy(POP) + cmake_check_compiler_flag(${_lang} "${_flag}" ${_var}) +endfunction() |