Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / TestCXXAcceptsFlag.cmake
1 # - Test CXX compiler for a flag
2 # Check if the CXX compiler accepts a flag
3 #
4 #  Macro CHECK_CXX_ACCEPTS_FLAG(FLAGS VARIABLE) -
5 #     checks if the function exists
6 #  FLAGS - the flags to try
7 #  VARIABLE - variable to store the result
8 #
9
10 #=============================================================================
11 # Copyright 2002-2009 Kitware, Inc.
12 #
13 # Distributed under the OSI-approved BSD License (the "License");
14 # see accompanying file Copyright.txt for details.
15 #
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 distribute this file outside of CMake, substitute the full
21 #  License text for the above reference.)
22
23 macro(CHECK_CXX_ACCEPTS_FLAG FLAGS  VARIABLE)
24   if(NOT DEFINED ${VARIABLE})
25     message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS}")
26     try_compile(${VARIABLE}
27       ${CMAKE_BINARY_DIR}
28       ${CMAKE_ROOT}/Modules/DummyCXXFile.cxx
29       CMAKE_FLAGS -DCOMPILE_DEFINITIONS:STRING=${FLAGS}
30       OUTPUT_VARIABLE OUTPUT)
31     if(${VARIABLE})
32       message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - yes")
33       file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeOutput.log
34         "Determining if the CXX compiler accepts the flag ${FLAGS} passed with "
35         "the following output:\n${OUTPUT}\n\n")
36     else()
37       message(STATUS "Checking to see if CXX compiler accepts flag ${FLAGS} - no")
38       file(APPEND ${CMAKE_BINARY_DIR}${CMAKE_FILES_DIRECTORY}/CMakeError.log
39         "Determining if the CXX compiler accepts the flag ${FLAGS} failed with "
40         "the following output:\n${OUTPUT}\n\n")
41     endif()
42   endif()
43 endmacro()