1
1
# - Check whether the C compiler supports a given flag.
2
# CHECK_C_COMPILER_FLAG(FLAG VARIABLE)
4
# FLAG - the compiler flag
5
# VARIABLE - variable to store the result
7
# This actually calls the check_c_source_compiles macro.
8
# See help for CheckCSourceCompiles for a listing of variables
9
# that can modify the build.
11
# Copyright (c) 2006, Alexander Neundorf, <neundorf@kde.org>
13
# Redistribution and use is allowed according to the terms of the BSD license.
14
# For details see the accompanying COPYING-CMAKE-SCRIPTS file.
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-2009 Kitware, Inc.
11
# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
13
# Distributed under the OSI-approved BSD License (the "License");
14
# see accompanying file Copyright.txt for details.
16
# This software is distributed WITHOUT ANY WARRANTY; without even the
17
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18
# See the License for more information.
19
#=============================================================================
20
# (To distributed this file outside of CMake, substitute the full
21
# License text for the above reference.)
17
23
INCLUDE(CheckCSourceCompiles)
19
25
MACRO (CHECK_C_COMPILER_FLAG _FLAG _RESULT)
20
26
SET(SAFE_CMAKE_REQUIRED_DEFINITIONS "${CMAKE_REQUIRED_DEFINITIONS}")
21
27
SET(CMAKE_REQUIRED_DEFINITIONS "${_FLAG}")
22
CHECK_C_SOURCE_COMPILES("int main() { return 0;}" ${_RESULT})
28
CHECK_C_SOURCE_COMPILES("int main() { return 0;}" ${_RESULT}
29
# Some compilers do not fail with a bad flag
30
FAIL_REGEX "unrecognized .*option" # GNU
31
FAIL_REGEX "ignoring unknown option" # MSVC
32
FAIL_REGEX "[Uu]nknown option" # HP
33
FAIL_REGEX "[Ww]arning: [Oo]ption" # SunPro
34
FAIL_REGEX "command option .* is not recognized" # XL
23
36
SET (CMAKE_REQUIRED_DEFINITIONS "${SAFE_CMAKE_REQUIRED_DEFINITIONS}")
24
37
ENDMACRO (CHECK_C_COMPILER_FLAG)