Debian Codegraph @

cmake/tribits/core/utils/Join.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
11 # @FUNCTION: join()
12 #
13 # Join a set of strings into a single string using a join string.
14 #
15 # Usage::
16 #
17 # join(<outputStrVar> "<sepStr>" <quoteElements>
18 # "<string0>" "<string1>" ...)
19 #
20 # Arguments:
21 #
22 # ``<outputStrVar>``
23 #
24 # The name of a variable that will hold the output string.
25 #
26 # ``"<sepStr>"``
27 #
28 # A string to use to join the list of strings.
29 #
30 # ``<quoteElements>``
31 #
32 # If ``TRUE``, then each ``<stringi>`` is quoted using an escaped quote
33 # char ``\"``. If ``FALSE`` then no escaped quote is used.
34 #
35 # ``"<string0>" "<string1>" ...``
36 #
37 # Zero or more string arguments to be joined.
38 #
39 # On output, the variable ``<outputStrVar>`` is set to::
40 #
41 # "<string0><sepStr><string1><sepStr>..."
42 #
43 # If ``<quoteElements>=TRUE``, then ``<outputStrVar>`` is set to::
44 #
45 # "\"<string0>\"<sepStr>\"<string1>\"<sepStr>..."
46 #
47 # For example, the latter can be used to set up a set of command-line
48 # arguments given a CMake array like::
49 #
50 # join(CMND_LINE_ARGS " " TRUE ${CMND_LINE_ARRAY})
51 #
52 # WARNING: Be careful to quote string arguments that have spaces because CMake
53 # interprets those as array boundaries.
54 #
55 function(join OUTPUT_STRING_VAR SEP_STR QUOTE_ELEMENTS)
56 set(QUOTE_CHAR)
57 if (QUOTE_ELEMENTS)
58 set(QUOTE_CHAR "\"")
59 endif()
60 set(OUTPUT_STRING "")
61 foreach(STRING_VAL ${ARGN})
62 if (OUTPUT_STRING STREQUAL "")
63 set(OUTPUT_STRING "${QUOTE_CHAR}${STRING_VAL}${QUOTE_CHAR}")
64 else()
65 set(OUTPUT_STRING "${OUTPUT_STRING}${SEP_STR}${QUOTE_CHAR}${STRING_VAL}${QUOTE_CHAR}")
66 endif()
67 endforeach()
68 set(${OUTPUT_STRING_VAR} "${OUTPUT_STRING}" PARENT_SCOPE)
69 endfunction()