Skip to content

Commit d489019

Browse files
authored
Link to libncursesw in CMake (#55054)
1 parent de82384 commit d489019

File tree

2 files changed

+343
-116
lines changed

2 files changed

+343
-116
lines changed
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
#=============================================================================
2+
# Copyright 2000-2022 Kitware, Inc. and Contributors
3+
# All rights reserved.
4+
#
5+
# Redistribution and use in source and binary forms, with or without
6+
# modification, are permitted provided that the following conditions
7+
# are met:
8+
#
9+
# * Redistributions of source code must retain the above copyright
10+
# notice, this list of conditions and the following disclaimer.
11+
#
12+
# * Redistributions in binary form must reproduce the above copyright
13+
# notice, this list of conditions and the following disclaimer in the
14+
# documentation and/or other materials provided with the distribution.
15+
#
16+
# * Neither the name of Kitware, Inc. nor the names of Contributors
17+
# may be used to endorse or promote products derived from this
18+
# software without specific prior written permission.
19+
#
20+
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21+
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22+
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23+
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
24+
# HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
25+
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
26+
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
27+
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
28+
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29+
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
30+
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31+
#=============================================================================
32+
33+
#[=======================================================================[.rst:
34+
CMakePushCheckState
35+
-------------------
36+
37+
38+
39+
This module defines three macros: ``CMAKE_PUSH_CHECK_STATE()``
40+
``CMAKE_POP_CHECK_STATE()`` and ``CMAKE_RESET_CHECK_STATE()`` These macros can
41+
be used to save, restore and reset (i.e., clear contents) the state of
42+
the variables ``CMAKE_REQUIRED_FLAGS``, ``CMAKE_REQUIRED_DEFINITIONS``,
43+
``CMAKE_REQUIRED_LINK_OPTIONS``, ``CMAKE_REQUIRED_LIBRARIES``,
44+
``CMAKE_REQUIRED_INCLUDES`` and ``CMAKE_EXTRA_INCLUDE_FILES`` used by the
45+
various Check-files coming with CMake, like e.g. ``check_function_exists()``
46+
etc.
47+
The variable contents are pushed on a stack, pushing multiple times is
48+
supported. This is useful e.g. when executing such tests in a Find-module,
49+
where they have to be set, but after the Find-module has been executed they
50+
should have the same value as they had before.
51+
52+
``CMAKE_PUSH_CHECK_STATE()`` macro receives optional argument ``RESET``.
53+
Whether it's specified, ``CMAKE_PUSH_CHECK_STATE()`` will set all
54+
``CMAKE_REQUIRED_*`` variables to empty values, same as
55+
``CMAKE_RESET_CHECK_STATE()`` call will do.
56+
57+
Usage:
58+
59+
.. code-block:: cmake
60+
61+
cmake_push_check_state(RESET)
62+
set(CMAKE_REQUIRED_DEFINITIONS -DSOME_MORE_DEF)
63+
check_function_exists(...)
64+
cmake_reset_check_state()
65+
set(CMAKE_REQUIRED_DEFINITIONS -DANOTHER_DEF)
66+
check_function_exists(...)
67+
cmake_pop_check_state()
68+
#]=======================================================================]
69+
70+
macro(CMAKE_RESET_CHECK_STATE)
71+
72+
set(CMAKE_EXTRA_INCLUDE_FILES)
73+
set(CMAKE_REQUIRED_INCLUDES)
74+
set(CMAKE_REQUIRED_DEFINITIONS)
75+
set(CMAKE_REQUIRED_LINK_OPTIONS)
76+
set(CMAKE_REQUIRED_LIBRARIES)
77+
set(CMAKE_REQUIRED_FLAGS)
78+
set(CMAKE_REQUIRED_QUIET)
79+
80+
endmacro()
81+
82+
macro(CMAKE_PUSH_CHECK_STATE)
83+
84+
if(NOT DEFINED _CMAKE_PUSH_CHECK_STATE_COUNTER)
85+
set(_CMAKE_PUSH_CHECK_STATE_COUNTER 0)
86+
endif()
87+
88+
math(EXPR _CMAKE_PUSH_CHECK_STATE_COUNTER "${_CMAKE_PUSH_CHECK_STATE_COUNTER}+1")
89+
90+
set(_CMAKE_EXTRA_INCLUDE_FILES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_EXTRA_INCLUDE_FILES})
91+
set(_CMAKE_REQUIRED_INCLUDES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_INCLUDES})
92+
set(_CMAKE_REQUIRED_DEFINITIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_DEFINITIONS})
93+
set(_CMAKE_REQUIRED_LINK_OPTIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_LINK_OPTIONS})
94+
set(_CMAKE_REQUIRED_LIBRARIES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_LIBRARIES})
95+
set(_CMAKE_REQUIRED_FLAGS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_FLAGS})
96+
set(_CMAKE_REQUIRED_QUIET_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER} ${CMAKE_REQUIRED_QUIET})
97+
98+
if (${ARGC} GREATER 0 AND "${ARGV0}" STREQUAL "RESET")
99+
cmake_reset_check_state()
100+
endif()
101+
102+
endmacro()
103+
104+
macro(CMAKE_POP_CHECK_STATE)
105+
106+
# don't pop more than we pushed
107+
if("${_CMAKE_PUSH_CHECK_STATE_COUNTER}" GREATER "0")
108+
109+
set(CMAKE_EXTRA_INCLUDE_FILES ${_CMAKE_EXTRA_INCLUDE_FILES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
110+
set(CMAKE_REQUIRED_INCLUDES ${_CMAKE_REQUIRED_INCLUDES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
111+
set(CMAKE_REQUIRED_DEFINITIONS ${_CMAKE_REQUIRED_DEFINITIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
112+
set(CMAKE_REQUIRED_LINK_OPTIONS ${_CMAKE_REQUIRED_LINK_OPTIONS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
113+
set(CMAKE_REQUIRED_LIBRARIES ${_CMAKE_REQUIRED_LIBRARIES_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
114+
set(CMAKE_REQUIRED_FLAGS ${_CMAKE_REQUIRED_FLAGS_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
115+
set(CMAKE_REQUIRED_QUIET ${_CMAKE_REQUIRED_QUIET_SAVE_${_CMAKE_PUSH_CHECK_STATE_COUNTER}})
116+
117+
math(EXPR _CMAKE_PUSH_CHECK_STATE_COUNTER "${_CMAKE_PUSH_CHECK_STATE_COUNTER}-1")
118+
endif()
119+
120+
endmacro()

0 commit comments

Comments
 (0)