diff options
Diffstat (limited to 'Modules/CheckCCompilerFlag.cmake')
-rw-r--r-- | Modules/CheckCCompilerFlag.cmake | 33 |
1 files changed, 14 insertions, 19 deletions
diff --git a/Modules/CheckCCompilerFlag.cmake b/Modules/CheckCCompilerFlag.cmake index a3e2da3..6d65313 100644 --- a/Modules/CheckCCompilerFlag.cmake +++ b/Modules/CheckCCompilerFlag.cmake @@ -36,28 +36,23 @@ include_guard(GLOBAL) include(CheckCSourceCompiles) include(CMakeCheckCompilerFlagCommonPatterns) -macro (CHECK_C_COMPILER_FLAG _FLAG _RESULT) - set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}") - set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}") - - # Normalize locale during test compilation. - set(_CheckCCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG) - foreach(v ${_CheckCCompilerFlag_LOCALE_VARS}) - set(_CheckCCompilerFlag_SAVED_${v} "$ENV{${v}}") +function(check_c_compiler_flag _flag _var) + 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(_CheckCCompilerFlag_COMMON_PATTERNS) - CHECK_C_SOURCE_COMPILES("int main(void) { return 0; }" ${_RESULT} + check_compiler_flag_common_patterns(_common_patterns) + check_c_source_compiles("int main(void) { return 0; }" ${_var} # Some compilers do not fail with a bad flag FAIL_REGEX "command line option .* is valid for .* but not for C" # GNU - ${_CheckCCompilerFlag_COMMON_PATTERNS} + ${_common_patterns} ) - foreach(v ${_CheckCCompilerFlag_LOCALE_VARS}) - set(ENV{${v}} ${_CheckCCompilerFlag_SAVED_${v}}) - unset(_CheckCCompilerFlag_SAVED_${v}) + foreach(v IN LISTS _locale_vars) + set(ENV{${v}} ${_locale_vars_saved_${v}}) endforeach() - unset(_CheckCCompilerFlag_LOCALE_VARS) - unset(_CheckCCompilerFlag_COMMON_PATTERNS) - - set (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}") -endmacro () + set(${_var} "${${_var}}" PARENT_SCOPE) +endfunction() |