Check*CompilerFlag: Revert to previous method used to pass flags (#15641)

Since commit v3.3.0-rc1~397^2 (Check*CompilerFlag: Refactor method used
to pass flags, 2015-02-24) these check modules pass the flags to the
compiler front-end during linking as well as during compilation.  This
breaks checks for flags like '-x c++' that are meant only for the
compilation step.  Revert the change and add a test covering a
compiler-only flag.
This commit is contained in:
Brad King 2015-07-08 09:55:16 -04:00
parent 5d5067ae57
commit a639689c16
4 changed files with 19 additions and 12 deletions

View File

@ -13,7 +13,7 @@
# Will be created as an internal cache variable. # Will be created as an internal cache variable.
# #
# This internally calls the check_c_source_compiles macro and sets # This internally calls the check_c_source_compiles macro and sets
# CMAKE_REQUIRED_FLAGS to <flag>. See help for # CMAKE_REQUIRED_DEFINITIONS to <flag>. See help for
# CheckCSourceCompiles for a listing of variables that can otherwise # CheckCSourceCompiles for a listing of variables that can otherwise
# modify the build. The result only tells that the compiler does not # modify the build. The result only tells that the compiler does not
# give an error message when it encounters the flag. If the flag has # give an error message when it encounters the flag. If the flag has
@ -38,8 +38,8 @@ include(CheckCSourceCompiles)
include(CMakeCheckCompilerFlagCommonPatterns) include(CMakeCheckCompilerFlagCommonPatterns)
macro (CHECK_C_COMPILER_FLAG _FLAG _RESULT) macro (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
set(CMAKE_REQUIRED_FLAGS "${_FLAG}") set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
# Normalize locale during test compilation. # Normalize locale during test compilation.
set(_CheckCCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG) set(_CheckCCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG)
@ -60,5 +60,5 @@ macro (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
unset(_CheckCCompilerFlag_LOCALE_VARS) unset(_CheckCCompilerFlag_LOCALE_VARS)
unset(_CheckCCompilerFlag_COMMON_PATTERNS) unset(_CheckCCompilerFlag_COMMON_PATTERNS)
set (CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") set (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
endmacro () endmacro ()

View File

@ -12,7 +12,7 @@
# <var> - variable to store the result # <var> - variable to store the result
# #
# This internally calls the check_cxx_source_compiles macro and sets # This internally calls the check_cxx_source_compiles macro and sets
# CMAKE_REQUIRED_FLAGS to <flag>. See help for # CMAKE_REQUIRED_DEFINITIONS to <flag>. See help for
# CheckCXXSourceCompiles for a listing of variables that can otherwise # CheckCXXSourceCompiles for a listing of variables that can otherwise
# modify the build. The result only tells that the compiler does not # modify the build. The result only tells that the compiler does not
# give an error message when it encounters the flag. If the flag has # give an error message when it encounters the flag. If the flag has
@ -37,8 +37,8 @@ include(CheckCXXSourceCompiles)
include(CMakeCheckCompilerFlagCommonPatterns) include(CMakeCheckCompilerFlagCommonPatterns)
macro (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT) macro (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
set(CMAKE_REQUIRED_FLAGS "${_FLAG}") set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
# Normalize locale during test compilation. # Normalize locale during test compilation.
set(_CheckCXXCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG) set(_CheckCXXCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG)
@ -59,6 +59,6 @@ macro (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT)
unset(_CheckCXXCompilerFlag_LOCALE_VARS) unset(_CheckCXXCompilerFlag_LOCALE_VARS)
unset(_CheckCXXCompilerFlag_COMMON_PATTERNS) unset(_CheckCXXCompilerFlag_COMMON_PATTERNS)
set (CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") set (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
endmacro () endmacro ()

View File

@ -13,7 +13,7 @@
# Will be created as an internal cache variable. # Will be created as an internal cache variable.
# #
# This internally calls the check_fortran_source_compiles macro and # This internally calls the check_fortran_source_compiles macro and
# sets CMAKE_REQUIRED_FLAGS to <flag>. See help for # sets CMAKE_REQUIRED_DEFINITIONS to <flag>. See help for
# CheckFortranSourceCompiles for a listing of variables that can # CheckFortranSourceCompiles for a listing of variables that can
# otherwise modify the build. The result only tells that the compiler # otherwise modify the build. The result only tells that the compiler
# does not give an error message when it encounters the flag. If the # does not give an error message when it encounters the flag. If the
@ -40,8 +40,8 @@ include(CheckFortranSourceCompiles)
include(CMakeCheckCompilerFlagCommonPatterns) include(CMakeCheckCompilerFlagCommonPatterns)
macro (CHECK_Fortran_COMPILER_FLAG _FLAG _RESULT) macro (CHECK_Fortran_COMPILER_FLAG _FLAG _RESULT)
set(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}") set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
set(CMAKE_REQUIRED_FLAGS "${_FLAG}") set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
# Normalize locale during test compilation. # Normalize locale during test compilation.
set(_CheckFortranCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG) set(_CheckFortranCompilerFlag_LOCALE_VARS LC_ALL LC_MESSAGES LANG)
@ -62,5 +62,5 @@ macro (CHECK_Fortran_COMPILER_FLAG _FLAG _RESULT)
unset(_CheckFortranCompilerFlag_LOCALE_VARS) unset(_CheckFortranCompilerFlag_LOCALE_VARS)
unset(_CheckFortranCompilerFlag_COMMON_PATTERNS) unset(_CheckFortranCompilerFlag_COMMON_PATTERNS)
set (CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}") set (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
endmacro () endmacro ()

View File

@ -56,3 +56,10 @@ if(CMAKE_COMPILER_IS_GNUCXX)
else() else()
message("Unhandled Platform") message("Unhandled Platform")
endif() endif()
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
check_cxx_compiler_flag("-x c++" HAVE_X_CXX)
if(NOT HAVE_X_CXX)
message(FATAL_ERROR "${CMAKE_CXX_COMPILER_ID} compiler flag '-x c++' check failed")
endif()
endif()