Fix CHECK_(C|CXX)_COMPILER_FLAG for GNU and MSVC

These compilers warn and return 0 for unrecognized flags.  We fix the
compiler flag check macros by looking for a warning in the output.
See issue #9516.
This commit is contained in:
Brad King 2009-09-17 15:32:54 -04:00
parent ca76645ab7
commit 7e3d437d0a
2 changed files with 10 additions and 2 deletions

View File

@ -17,7 +17,11 @@ INCLUDE(CheckCSourceCompiles)
MACRO (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
SET(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
CHECK_C_SOURCE_COMPILES("int main() { return 0;}" ${_RESULT})
CHECK_C_SOURCE_COMPILES("int main() { return 0;}" ${_RESULT}
# Some compilers do not fail with a bad flag
FAIL_REGEX "unrecognized option" # GNU
FAIL_REGEX "ignoring unknown option" # MSVC
)
SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
ENDMACRO (CHECK_C_COMPILER_FLAG)

View File

@ -17,7 +17,11 @@ INCLUDE(CheckCXXSourceCompiles)
MACRO (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT)
SET(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
CHECK_CXX_SOURCE_COMPILES("int main() { return 0;}" ${_RESULT})
CHECK_CXX_SOURCE_COMPILES("int main() { return 0;}" ${_RESULT}
# Some compilers do not fail with a bad flag
FAIL_REGEX "unrecognized option" # GNU
FAIL_REGEX "ignoring unknown option" # MSVC
)
SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
ENDMACRO (CHECK_CXX_COMPILER_FLAG)