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:
parent
ca76645ab7
commit
7e3d437d0a
|
@ -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)
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
||||
|
|
Loading…
Reference in New Issue