Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / CMakePushCheckState.cmake
1 # This module defines two macros:
2 # CMAKE_PUSH_CHECK_STATE()
3 # and
4 # CMAKE_POP_CHECK_STATE()
5 # These two macros can be used to save and restore the state of the variables
6 # CMAKE_REQUIRED_FLAGS, CMAKE_REQUIRED_DEFINITIONS, CMAKE_REQUIRED_LIBRARIES
7 # and CMAKE_REQUIRED_INCLUDES used by the various Check-files coming with CMake,
8 # like e.g. check_function_exists() etc.
9 # The variable contents are pushed on a stack, pushing multiple times is supported.
10 # This is useful e.g. when executing such tests in a Find-module, where they have to be set,
11 # but after the Find-module has been executed they should have the same value
12 # as they had before.
13 #
14 # Usage:
15 #   cmake_push_check_state()
16 #   set(CMAKE_REQUIRED_DEFINITIONS ${CMAKE_REQUIRED_DEFINITIONS} -DSOME_MORE_DEF)
17 #   check_function_exists(...)
18 #   cmake_pop_check_state()
19
20 #=============================================================================
21 # Copyright 2006-2011 Alexander Neundorf, <neundorf@kde.org>
22 #
23 # Distributed under the OSI-approved BSD License (the "License");
24 # see accompanying file Copyright.txt for details.
25 #
26 # This software is distributed WITHOUT ANY WARRANTY; without even the
27 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28 # See the License for more information.
29 #=============================================================================
30 # (To distribute this file outside of CMake, substitute the full
31 #  License text for the above reference.)
32
33
34 macro(CMAKE_PUSH_CHECK_STATE)
35
36    if(NOT DEFINED _CMAKE_PUSH_CHECK_STATE_COUNTER)
37       set(_CMAKE_PUSH_CHECK_STATE_COUNTER 0)
38    endif()
39
40    math(EXPR _CMAKE_PUSH_CHECK_STATE_COUNTER "${_CMAKE_PUSH_CHECK_STATE_COUNTER}+1")
41
42    set(_CMAKE_REQUIRED_INCLUDES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}    ${CMAKE_REQUIRED_INCLUDES})
43    set(_CMAKE_REQUIRED_DEFINITIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_DEFINITIONS})
44    set(_CMAKE_REQUIRED_LIBRARIES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}   ${CMAKE_REQUIRED_LIBRARIES})
45    set(_CMAKE_REQUIRED_FLAGS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}       ${CMAKE_REQUIRED_FLAGS})
46 endmacro()
47
48 macro(CMAKE_POP_CHECK_STATE)
49
50 # don't pop more than we pushed
51    if("${_CMAKE_PUSH_CHECK_STATE_COUNTER}" GREATER "0")
52
53       set(CMAKE_REQUIRED_INCLUDES    ${_CMAKE_REQUIRED_INCLUDES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
54       set(CMAKE_REQUIRED_DEFINITIONS ${_CMAKE_REQUIRED_DEFINITIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
55       set(CMAKE_REQUIRED_LIBRARIES   ${_CMAKE_REQUIRED_LIBRARIES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
56       set(CMAKE_REQUIRED_FLAGS       ${_CMAKE_REQUIRED_FLAGS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
57
58       math(EXPR _CMAKE_PUSH_CHECK_STATE_COUNTER "${_CMAKE_PUSH_CHECK_STATE_COUNTER}-1")
59    endif()
60
61 endmacro()