get_filename_component.rst 2.5 KB

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