cmake/Help/command/get_filename_component.rst

66 lines
2.3 KiB
ReStructuredText
Raw Normal View History

2014-08-03 19:52:23 +02:00
get_filename_component
----------------------
Get a specific component of a full filename.
2021-09-14 00:13:48 +02:00
.. versionchanged:: 3.20
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.
2019-11-11 23:01:05 +01:00
.. code-block:: cmake
2015-11-17 17:22:37 +01:00
2019-11-11 23:01:05 +01:00
get_filename_component(<var> <FileName> <mode> [CACHE])
2014-08-03 19:52:23 +02:00
2019-11-11 23:01:05 +01:00
Sets ``<var>`` to a component of ``<FileName>``, where ``<mode>`` is one of:
2014-08-03 19:52:23 +02:00
::
DIRECTORY = Directory without file name
NAME = File name without directory
EXT = File name longest extension (.b.c from d/a.b.c)
2021-09-14 00:13:48 +02:00
NAME_WE = File name with neither the directory nor the longest extension
2019-11-11 23:01:05 +01:00
LAST_EXT = File name last extension (.c from d/a.b.c)
2021-09-14 00:13:48 +02:00
NAME_WLE = File name with neither the directory nor the last extension
2014-08-03 19:52:23 +02:00
PATH = Legacy alias for DIRECTORY (use for CMake <= 2.8.11)
2021-09-14 00:13:48 +02:00
.. versionadded:: 3.14
Added the ``LAST_EXT`` and ``NAME_WLE`` modes.
2015-11-17 17:22:37 +01:00
Paths are returned with forward slashes and have no trailing slashes.
2019-11-11 23:01:05 +01:00
If the optional ``CACHE`` argument is specified, the result variable is
added to the cache.
2015-11-17 17:22:37 +01:00
2019-11-11 23:01:05 +01:00
.. code-block:: cmake
2015-11-17 17:22:37 +01:00
2019-11-11 23:01:05 +01:00
get_filename_component(<var> <FileName> <mode> [BASE_DIR <dir>] [CACHE])
2015-11-17 17:22:37 +01:00
2021-09-14 00:13:48 +02:00
.. versionadded:: 3.4
2019-11-11 23:01:05 +01:00
Sets ``<var>`` to the absolute path of ``<FileName>``, where ``<mode>`` is one
2015-11-17 17:22:37 +01:00
of:
::
ABSOLUTE = Full path to file
REALPATH = Full path to existing file with symlinks resolved
If the provided ``<FileName>`` is a relative path, it is evaluated relative
2019-11-11 23:01:05 +01:00
to the given base directory ``<dir>``. If no base directory is
2015-11-17 17:22:37 +01:00
provided, the default base directory will be
:variable:`CMAKE_CURRENT_SOURCE_DIR`.
2018-08-09 18:06:22 +02:00
Paths are returned with forward slashes and have no trailing slashes. If the
2015-11-17 17:22:37 +01:00
optional ``CACHE`` argument is specified, the result variable is added to the
2014-08-03 19:52:23 +02:00
cache.
2019-11-11 23:01:05 +01:00
.. code-block:: cmake
2014-08-03 19:52:23 +02:00
2019-11-11 23:01:05 +01:00
get_filename_component(<var> <FileName> PROGRAM [PROGRAM_ARGS <arg_var>] [CACHE])
2014-08-03 19:52:23 +02:00
2015-11-17 17:22:37 +01:00
The program in ``<FileName>`` will be found in the system search path or
left as a full path. If ``PROGRAM_ARGS`` is present with ``PROGRAM``, then
any command-line arguments present in the ``<FileName>`` string are split
2019-11-11 23:01:05 +01:00
from the program name and stored in ``<arg_var>``. This is used to
2014-08-03 19:52:23 +02:00
separate a program name from its arguments in a command line string.