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 #=============================================================================
10 # Copyright 2006-2009 Kitware, Inc.
11 # Copyright 2006 Alexander Neundorf <neundorf@kde.org>
12 # Copyright 2011-2013 Matthias Kretz <kretz@kde.org>
14 # Redistribution and use in source and binary forms, with or without
15 # modification, are permitted provided that the following conditions are
18 # * Redistributions of source code must retain the above copyright notice,
19 # this list of conditions and the following disclaimer.
21 # * Redistributions in binary form must reproduce the above copyright notice,
22 # this list of conditions and the following disclaimer in the documentation
23 # and/or other materials provided with the distribution.
25 # * The names of Kitware, Inc., the Insight Consortium, or the names of
26 # any consortium members, or of any contributors, may not be used to
27 # endorse or promote products derived from this software without
28 # specific prior written permission.
30 # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS ``AS IS''
31 # AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
32 # IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
33 # ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHORS OR CONTRIBUTORS BE LIABLE FOR
34 # ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
35 # DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
36 # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
37 # CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
38 # OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
39 # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40 #=============================================================================
42 INCLUDE(CheckCXXSourceCompiles)
44 MACRO (CHECK_CXX_COMPILER_FLAG _FLAG _RESULT)
45 SET(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
46 SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
48 SET(TEST_SOURCE "${ARGV2}")
50 SET(TEST_SOURCE "int main() { return 0;}")
52 CHECK_CXX_SOURCE_COMPILES("${TEST_SOURCE}" ${_RESULT}
53 # Some compilers do not fail with a bad flag
54 FAIL_REGEX "error: bad value (.*) for .* switch" # GNU
55 FAIL_REGEX "argument unused during compilation" # clang
56 FAIL_REGEX "is valid for .* but not for C\\\\+\\\\+" # GNU
57 FAIL_REGEX "unrecognized .*option" # GNU
58 FAIL_REGEX "ignored for target" # GNU
59 FAIL_REGEX "ignoring unknown option" # MSVC
60 FAIL_REGEX "[Uu]nknown option" # HP
61 FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro
62 FAIL_REGEX "command option .* is not recognized" # XL
63 FAIL_REGEX "WARNING: unknown flag:" # Open64
64 FAIL_REGEX " #10159: " # ICC
65 FAIL_REGEX " #10353: " # ICC: option '-mfma' ignored, suggest using '-march=core-avx2'
67 SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
68 ENDMACRO (CHECK_CXX_COMPILER_FLAG)