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