Debian Codegraph @

cmake/tribits/core/utils/MessageWrapper.cmake

raw
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 include_guard()
11
12 include("${CMAKE_CURRENT_LIST_DIR}/GlobalSet.cmake")
13
14 # @FUNCTION: message_wrapper()
15 #
16 # Function that wraps the standard CMake/CTest ``message()`` function call in
17 # order to allow unit testing to intercept the output.
18 #
19 # Usage::
20 #
21 # message_wrapper(...)
22 #
23 # This function takes exactly the same arguments as built-in ``message()``
24 # function. However, when the variable ``MESSAGE_WRAPPER_UNIT_TEST_MODE`` is
25 # set to ``TRUE``, then this function will not call ``message(...)`` but
26 # instead will prepend set to the global variable ``MESSAGE_WRAPPER_INPUT``
27 # the input argument that would have gone to ``message()``. To capture just
28 # this call's input, first call::
29 #
30 # global_null_set(MESSAGE_WRAPPER_INPUT)
31 #
32 # before calling this function (or the functions/macros that call this
33 # function).
34 #
35 # This function allows one to unit test other user-defined CMake macros and
36 # functions that call this function to catch error conditions without stopping
37 # the CMake program. Otherwise, this is used to capture print messages to
38 # verify that they say the right thing.
39 #
40 function(message_wrapper)
41 cmake_parse_arguments(PARSE_ARGV 0 FWD "" "" "")
42 #message("MESSAGE_WRAPPER: ${FWD_UNPARSED_ARGUMENTS}")
43 if (MESSAGE_WRAPPER_UNIT_TEST_MODE)
44 global_set(MESSAGE_WRAPPER_INPUT "${MESSAGE_WRAPPER_INPUT}"
45 ${FWD_UNPARSED_ARGUMENTS})
46 else()
47 message(${FWD_UNPARSED_ARGUMENTS})
48 endif()
49 endfunction()
50