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 # ORIGINAL Copyright notice (from Copyright.txt):
16 # CMake - Cross Platform Makefile Generator
17 # Copyright 2000-2011 Kitware, Inc., Insight Software Consortium
18 # All rights reserved.
20 # Redistribution and use in source and binary forms, with or without
21 # modification, are permitted provided that the following conditions
24 # * Redistributions of source code must retain the above copyright
25 # notice, this list of conditions and the following disclaimer.
27 # * Redistributions in binary form must reproduce the above copyright
28 # notice, this list of conditions and the following disclaimer in the
29 # documentation and/or other materials provided with the distribution.
31 # * Neither the names of Kitware, Inc., the Insight Software Consortium,
32 # nor the names of their contributors may be used to endorse or promote
33 # products derived from this software without specific prior written
36 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
37 # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
38 # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
39 # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
40 # HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41 # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
43 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
44 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
45 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
46 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
47 #=============================================================================
49 INCLUDE(CheckCSourceCompiles)
51 MACRO (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
52 SET(SAFE_CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS}")
53 SET(CMAKE_REQUIRED_FLAGS "${_FLAG}")
54 CHECK_C_SOURCE_COMPILES("int main(void) { return 0; }" ${_RESULT}
55 # Some compilers do not fail with a bad flag
56 FAIL_REGEX "command line option .* is valid for .* but not for C" # GNU
57 FAIL_REGEX "unrecognized .*option" # GNU
58 FAIL_REGEX "unknown .*option" # Clang
59 FAIL_REGEX "ignoring unknown option" # MSVC
60 FAIL_REGEX "warning D9002" # MSVC, any lang
61 FAIL_REGEX "option.*not supported" # Intel
62 FAIL_REGEX "invalid argument .*option" # Intel
63 FAIL_REGEX "ignoring option .*argument required" # Intel
64 FAIL_REGEX "[Uu]nknown option" # HP
65 FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro
66 FAIL_REGEX "command option .* is not recognized" # XL
67 FAIL_REGEX "command option .* contains an incorrect subargument" # XL
68 FAIL_REGEX "not supported in this configuration. ignored" # AIX
69 FAIL_REGEX "File with unknown suffix passed to linker" # PGI
70 FAIL_REGEX "WARNING: unknown flag:" # Open64
71 FAIL_REGEX "Incorrect command line option:" # Borland
72 FAIL_REGEX "Warning: illegal option" # SunStudio 12
73 FAIL_REGEX "[Ww]arning: Invalid" # Fujitsu
75 SET (CMAKE_REQUIRED_FLAGS "${SAFE_CMAKE_REQUIRED_FLAGS}")
76 ENDMACRO (CHECK_C_COMPILER_FLAG)