1 # - Check whether the C compiler supports a given flag.
2 # CHECK_C_COMPILER_FLAG(<flag> <var>)
3 # <flag> - the compiler flag
4 # <var> - variable to store the result
5 # This internally calls the check_c_source_compiles macro.
6 # See help for CheckCSourceCompiles for a listing of variables
7 # that can modify the build.
9 #=============================================================================
10 # Copyright 2006-2011 Kitware, Inc.
11 # Copyright 2006 Alexander Neundorf <neundorf@kde.org>
12 # Copyright 2011 Matthias Kretz <kretz@kde.org>
14 # Distributed under the OSI-approved BSD License (the "License");
15 # see accompanying file Copyright.txt for details.
17 # This software is distributed WITHOUT ANY WARRANTY; without even the
18 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
19 # See the License for more information.
20 #=============================================================================
21 # (To distribute this file outside of CMake, substitute the full
22 # License text for the above reference.)
24 include(CheckCSourceCompiles)
26 macro (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
27 set(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
28 set(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
29 CHECK_C_SOURCE_COMPILES("int main(void) { return 0; }" ${_RESULT}
30 # Some compilers do not fail with a bad flag
31 FAIL_REGEX "command line option .* is valid for .* but not for C" # GNU
32 FAIL_REGEX "unrecognized .*option" # GNU
33 FAIL_REGEX "unknown .*option" # Clang
34 FAIL_REGEX "ignoring unknown option" # MSVC
35 FAIL_REGEX "warning D9002" # MSVC, any lang
36 FAIL_REGEX "option.*not supported" # Intel
37 FAIL_REGEX "invalid argument .*option" # Intel
38 FAIL_REGEX "ignoring option .*argument required" # Intel
39 FAIL_REGEX "[Uu]nknown option" # HP
40 FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro
41 FAIL_REGEX "command option .* is not recognized" # XL
42 FAIL_REGEX "WARNING: unknown flag:" # Open64
44 set (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")