Merge topic 'separate_arguments-program'

d832c1cc7d separate_arguments: add option PROGRAM
f4c21d4953 separate_arguments: refactoring

Acked-by: Kitware Robot <kwrobot@kitware.com>
Merge-request: !5253
This commit is contained in:
Brad King
2020-09-23 16:05:16 +00:00
committed by Kitware Robot
19 changed files with 297 additions and 74 deletions

View File

@@ -44,12 +44,6 @@ Paths are returned with forward slashes and have no trailing slashes. If the
optional ``CACHE`` argument is specified, the result variable is added to the
cache.
.. note::
All previous sub-commands has been superseded by
:command:`cmake_path` command, except ``REALPATH`` now offered by
:ref:`file(REAL_PATH) <REAL_PATH>` command.
.. code-block:: cmake
get_filename_component(<var> <FileName> PROGRAM [PROGRAM_ARGS <arg_var>] [CACHE])
@@ -59,3 +53,9 @@ left as a full path. If ``PROGRAM_ARGS`` is present with ``PROGRAM``, then
any command-line arguments present in the ``<FileName>`` string are split
from the program name and stored in ``<arg_var>``. This is used to
separate a program name from its arguments in a command line string.
.. note::
This command been superseded by :command:`cmake_path` command, except
``REALPATH`` now offered by :ref:`file(REAL_PATH) <REAL_PATH>` command and
``PROGRAM`` now available in :command:`separate_arguments(PROGRAM)` command.

View File

@@ -5,7 +5,7 @@ Parse command-line arguments into a semicolon-separated list.
.. code-block:: cmake
separate_arguments(<variable> <mode> <args>)
separate_arguments(<variable> <mode> [PROGRAM [SEPARATE_ARGS]] <args>)
Parses a space-separated string ``<args>`` into a list of items,
and stores this list in semicolon-separated standard form in ``<variable>``.
@@ -35,6 +35,36 @@ be one of the following keywords:
Proceeds as in ``WINDOWS_COMMAND`` mode if the host system is Windows.
Otherwise proceeds as in ``UNIX_COMMAND`` mode.
``PROGRAM``
The first item in ``<args>`` is assumed to be an executable and will be
search 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``
.. _`Parsing C Command-Line Arguments`: https://msdn.microsoft.com/library/a1y7w461.aspx
.. code-block:: cmake