• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1get_filename_component
2----------------------
3
4Get a specific component of a full filename.
5
6.. versionchanged:: 3.20
7  This command been superseded by :command:`cmake_path` command, except
8  ``REALPATH`` now offered by :ref:`file(REAL_PATH) <REAL_PATH>` command and
9  ``PROGRAM`` now available in :command:`separate_arguments(PROGRAM)` command.
10
11.. code-block:: cmake
12
13  get_filename_component(<var> <FileName> <mode> [CACHE])
14
15Sets ``<var>`` to a component of ``<FileName>``, where ``<mode>`` is one of:
16
17::
18
19 DIRECTORY = Directory without file name
20 NAME      = File name without directory
21 EXT       = File name longest extension (.b.c from d/a.b.c)
22 NAME_WE   = File name with neither the directory nor the longest extension
23 LAST_EXT  = File name last extension (.c from d/a.b.c)
24 NAME_WLE  = File name with neither the directory nor the last extension
25 PATH      = Legacy alias for DIRECTORY (use for CMake <= 2.8.11)
26
27.. versionadded:: 3.14
28  Added the ``LAST_EXT`` and ``NAME_WLE`` modes.
29
30Paths are returned with forward slashes and have no trailing slashes.
31If the optional ``CACHE`` argument is specified, the result variable is
32added to the cache.
33
34.. code-block:: cmake
35
36  get_filename_component(<var> <FileName> <mode> [BASE_DIR <dir>] [CACHE])
37
38.. versionadded:: 3.4
39
40Sets ``<var>`` to the absolute path of ``<FileName>``, where ``<mode>`` is one
41of:
42
43::
44
45 ABSOLUTE  = Full path to file
46 REALPATH  = Full path to existing file with symlinks resolved
47
48If the provided ``<FileName>`` is a relative path, it is evaluated relative
49to the given base directory ``<dir>``.  If no base directory is
50provided, the default base directory will be
51:variable:`CMAKE_CURRENT_SOURCE_DIR`.
52
53Paths are returned with forward slashes and have no trailing slashes.  If the
54optional ``CACHE`` argument is specified, the result variable is added to the
55cache.
56
57.. code-block:: cmake
58
59  get_filename_component(<var> <FileName> PROGRAM [PROGRAM_ARGS <arg_var>] [CACHE])
60
61The program in ``<FileName>`` will be found in the system search path or
62left as a full path.  If ``PROGRAM_ARGS`` is present with ``PROGRAM``, then
63any command-line arguments present in the ``<FileName>`` string are split
64from the program name and stored in ``<arg_var>``.  This is used to
65separate a program name from its arguments in a command line string.
66