| 1 |
# @HEADER |
| 2 |
# ***************************************************************************** |
| 3 |
# TriBITS: Tribal Build, Integrate, and Test System |
| 4 |
# |
| 5 |
# Copyright 2013-2016 NTESS and the TriBITS contributors. |
| 6 |
# SPDX-License-Identifier: BSD-3-Clause |
| 7 |
# ***************************************************************************** |
| 8 |
# @HEADER |
| 9 |
|
| 10 |
|
| 11 |
# @MACRO: dual_scope_set() |
| 12 |
# |
| 13 |
# Macro that sets a variable name both in the current scope and the |
| 14 |
# parent scope. |
| 15 |
# |
| 16 |
# Usage:: |
| 17 |
# |
| 18 |
# dual_scope_set(<varName> [other args]) |
| 19 |
# |
| 20 |
# It turns out that when one calls ``add_subdirectory(<someDir>)`` or enters a |
| 21 |
# ``FUNCTION`` that CMake actually creates a copy of all of the regular |
| 22 |
# non-cache variables in the current scope in order to create a new set of |
| 23 |
# variables for the ``CMakeLists.txt`` file in ``<someDir>``. This means that |
| 24 |
# if you call ``set(SOMEVAR Blah PARENT_SCOPE)`` that it will not affect the |
| 25 |
# value of ``SOMEVAR`` in the current scope! This macro therefore is designed |
| 26 |
# to set the value of the variable in the current scope and the parent scope |
| 27 |
# in one shot to avoid confusion. |
| 28 |
# |
| 29 |
# Global variables are different. When one moves to a subordinate |
| 30 |
# ``CMakeLists.txt`` file or enters a ``FUNCTION``, then a local copy of the |
| 31 |
# variable is *not* created. If one sets the variable locally, it will shadow |
| 32 |
# the global variable. However, if one sets the global cache value with |
| 33 |
# ``set(SOMEVAR someValue CACHE INTERNAL "")``, then the value will get |
| 34 |
# changed in the current subordinate scope and in all parent scopes all in one |
| 35 |
# shot! |
| 36 |
# |
| 37 |
macro(dual_scope_set VARNAME) |
| 38 |
set(${VARNAME} ${ARGN} PARENT_SCOPE) |
| 39 |
set(${VARNAME} ${ARGN}) |
| 40 |
endmacro() |