1separate_arguments
2------------------
3
4Parse command-line arguments into a semicolon-separated list.
5
6.. code-block:: cmake
7
8  separate_arguments(<variable> <mode> [PROGRAM [SEPARATE_ARGS]] <args>)
9
10Parses a space-separated string ``<args>`` into a list of items,
11and stores this list in semicolon-separated standard form in ``<variable>``.
12
13This function is intended for parsing command-line arguments.
14The entire command line must be passed as one string in the
15argument ``<args>``.
16
17The exact parsing rules depend on the operating system.
18They are specified by the ``<mode>`` argument which must
19be one of the following keywords:
20
21``UNIX_COMMAND``
22  Arguments are separated by unquoted whitespace.
23  Both single-quote and double-quote pairs are respected.
24  A backslash escapes the next literal character (``\"`` is ``"``);
25  there are no special escapes (``\n`` is just ``n``).
26
27``WINDOWS_COMMAND``
28  A Windows command-line is parsed using the same
29  syntax the runtime library uses to construct argv at startup.  It
30  separates arguments by whitespace that is not double-quoted.
31  Backslashes are literal unless they precede double-quotes.  See the
32  MSDN article `Parsing C Command-Line Arguments`_ for details.
33
34``NATIVE_COMMAND``
35  .. versionadded:: 3.9
36
37  Proceeds as in ``WINDOWS_COMMAND`` mode if the host system is Windows.
38  Otherwise proceeds as in ``UNIX_COMMAND`` mode.
39
40``PROGRAM``
41  .. versionadded:: 3.19
42
43  The first item in ``<args>`` is assumed to be an executable and will be
44  searched in the system search path or left as a full path. If not found,
45  ``<variable>`` will be empty. Otherwise, ``<variable>`` is a list of 2
46  elements:
47
48    0. Absolute path of the program
49    1. Any command-line arguments present in ``<args>`` as a string
50
51  For example:
52
53  .. code-block:: cmake
54
55    separate_arguments (out UNIX_COMMAND PROGRAM "cc -c main.c")
56
57  * First element of the list: ``/path/to/cc``
58  * Second element of the list: ``" -c main.c"``
59
60``SEPARATE_ARGS``
61  When this sub-option of ``PROGRAM`` option is specified, command-line
62  arguments will be split as well and stored in ``<variable>``.
63
64  For example:
65
66  .. code-block:: cmake
67
68    separate_arguments (out UNIX_COMMAND PROGRAM SEPARATE_ARGS "cc -c main.c")
69
70  The contents of ``out`` will be: ``/path/to/cc;-c;main.c``
71
72.. _`Parsing C Command-Line Arguments`: https://msdn.microsoft.com/library/a1y7w461.aspx
73
74.. code-block:: cmake
75
76  separate_arguments(<var>)
77
78Convert the value of ``<var>`` to a semi-colon separated list.  All
79spaces are replaced with ';'.  This helps with generating command
80lines.
81