summaryrefslogtreecommitdiffstats
path: root/Modules/CheckCXXCompilerFlag.cmake
diff options
context:
space:
mode:
authorBrad King <brad.king@kitware.com>2009-09-17 19:32:54 (GMT)
committerBrad King <brad.king@kitware.com>2009-09-17 19:32:54 (GMT)
commit7e3d437d0af7e625e19bbeac37e025d16cf8be11 (patch)
treeb1f25b9f149ce11f8d36c56f4b93e7d8addd771a /Modules/CheckCXXCompilerFlag.cmake
parentca76645ab7f235fdad652fcff7ad9a899bc12424 (diff)
downloadCMake-7e3d437d0af7e625e19bbeac37e025d16cf8be11.zip
CMake-7e3d437d0af7e625e19bbeac37e025d16cf8be11.tar.gz
CMake-7e3d437d0af7e625e19bbeac37e025d16cf8be11.tar.bz2
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.
Diffstat (limited to 'Modules/CheckCXXCompilerFlag.cmake')
-rw-r--r--Modules/CheckCXXCompilerFlag.cmake6
1 files changed, 5 insertions, 1 deletions
diff --git a/Modules/CheckCXXCompilerFlag.cmake b/Modules/CheckCXXCompilerFlag.cmake
index cd728fa..e883282 100644
--- a/Modules/CheckCXXCompilerFlag.cmake
+++ b/Modules/CheckCXXCompilerFlag.cmake
@@ -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)