cmake/Help/command/separate_arguments.rst

81 lines
2.5 KiB
ReStructuredText
Raw Normal View History

2014-08-03 19:52:23 +02:00
separate_arguments
------------------
2019-11-11 23:01:05 +01:00
Parse command-line arguments into a semicolon-separated list.
2014-08-03 19:52:23 +02:00
2019-11-11 23:01:05 +01:00
.. code-block:: cmake
2014-08-03 19:52:23 +02:00
2021-09-14 00:13:48 +02:00
separate_arguments(<variable> <mode> [PROGRAM [SEPARATE_ARGS]] <args>)
2014-08-03 19:52:23 +02:00
2019-11-11 23:01:05 +01:00
Parses a space-separated string ``<args>`` into a list of items,
and stores this list in semicolon-separated standard form in ``<variable>``.
2014-08-03 19:52:23 +02:00
2019-11-11 23:01:05 +01:00
This function is intended for parsing command-line arguments.
The entire command line must be passed as one string in the
argument ``<args>``.
2014-08-03 19:52:23 +02:00
2019-11-11 23:01:05 +01:00
The exact parsing rules depend on the operating system.
They are specified by the ``<mode>`` argument which must
be one of the following keywords:
2016-10-30 18:24:19 +01:00
2019-11-11 23:01:05 +01:00
``UNIX_COMMAND``
2020-08-30 11:54:41 +02:00
Arguments are separated by unquoted whitespace.
2019-11-11 23:01:05 +01:00
Both single-quote and double-quote pairs are respected.
A backslash escapes the next literal character (``\"`` is ``"``);
there are no special escapes (``\n`` is just ``n``).
``WINDOWS_COMMAND``
A Windows command-line is parsed using the same
syntax the runtime library uses to construct argv at startup. It
separates arguments by whitespace that is not double-quoted.
Backslashes are literal unless they precede double-quotes. See the
MSDN article `Parsing C Command-Line Arguments`_ for details.
``NATIVE_COMMAND``
2021-09-14 00:13:48 +02:00
.. versionadded:: 3.9
2019-11-11 23:01:05 +01:00
Proceeds as in ``WINDOWS_COMMAND`` mode if the host system is Windows.
Otherwise proceeds as in ``UNIX_COMMAND`` mode.
2017-07-20 19:35:53 +02:00
2021-09-14 00:13:48 +02:00
``PROGRAM``
.. versionadded:: 3.19
The first item in ``<args>`` is assumed to be an executable and will be
searched in the system search path or left as a full path. If not found,
``<variable>`` will be empty. Otherwise, ``<variable>`` is a list of 2
elements:
0. Absolute path of the program
1. Any command-line arguments present in ``<args>`` as a string
For example:
.. code-block:: cmake
separate_arguments (out UNIX_COMMAND PROGRAM "cc -c main.c")
* First element of the list: ``/path/to/cc``
* Second element of the list: ``" -c main.c"``
``SEPARATE_ARGS``
When this sub-option of ``PROGRAM`` option is specified, command-line
arguments will be split as well and stored in ``<variable>``.
For example:
.. code-block:: cmake
separate_arguments (out UNIX_COMMAND PROGRAM SEPARATE_ARGS "cc -c main.c")
The contents of ``out`` will be: ``/path/to/cc;-c;main.c``
2016-10-30 18:24:19 +01:00
.. _`Parsing C Command-Line Arguments`: https://msdn.microsoft.com/library/a1y7w461.aspx
2014-08-03 19:52:23 +02:00
2019-11-11 23:01:05 +01:00
.. code-block:: cmake
2014-08-03 19:52:23 +02:00
2016-10-30 18:24:19 +01:00
separate_arguments(<var>)
2014-08-03 19:52:23 +02:00
2016-10-30 18:24:19 +01:00
Convert the value of ``<var>`` to a semi-colon separated list. All
2014-08-03 19:52:23 +02:00
spaces are replaced with ';'. This helps with generating command
lines.