1 # - Check whether the CXX compiler supports a given flag.
2 # CHECK_CXX_COMPILER_FLAG(<flag> <var>)
3 # <flag> - the compiler flag
4 # <var> - variable to store the result
5 # This internally calls the check_cxx_source_compiles macro. See help
6 # for CheckCXXSourceCompiles for a listing of variables that can
9 # Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
11 # Redistribution and use is allowed according to the terms of the BSD license.
12 # For details see the accompanying COPYING-CMAKE-SCRIPTS file.
15 INCLUDE(CheckCXXSourceCompiles)
17 MACRO (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT)
18 SET(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
19 SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
20 CHECK_CXX_SOURCE_COMPILES("int main() { return 0;}" ${_RESULT}
21 # Some compilers do not fail with a bad flag
22 FAIL_REGEX "unrecognized .*option" # GNU
23 FAIL_REGEX "ignoring unknown option" # MSVC
24 FAIL_REGEX "[Uu]nknown option" # HP
25 FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro
26 FAIL_REGEX "command option .* is not recognized" # XL
28 SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
29 ENDMACRO (CHECK_CXX_COMPILER_FLAG)