1
0

get_filename_component.rst 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 the :command:`cmake_path` command, except
  6. for ``REALPATH``, which is now offered by :command:`file(REAL_PATH)`, and
  7. ``PROGRAM``, now available in :command:`separate_arguments(PROGRAM)`.
  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. * ``DIRECTORY`` - directory without file name.
  17. * ``NAME`` - file name without directory.
  18. * ``EXT`` - file name longest extension (``.b.c`` from ``d/a.b.c``).
  19. * ``NAME_WE`` - file name with neither the directory nor the longest extension.
  20. * ``LAST_EXT`` - file name last extension (``.c`` from ``d/a.b.c``).
  21. * ``NAME_WLE`` - file name with neither the directory nor the last extension.
  22. * ``PATH`` - legacy alias for ``DIRECTORY`` (use for CMake <= 2.8.11).
  23. .. versionadded:: 3.14
  24. Added the ``LAST_EXT`` and ``NAME_WLE`` modes.
  25. Paths are returned with forward slashes and have no trailing slashes.
  26. If the optional ``CACHE`` argument is specified, the result variable is
  27. added to the cache.
  28. .. code-block:: cmake
  29. get_filename_component(<var> <FileName> <mode> [BASE_DIR <dir>] [CACHE])
  30. .. versionadded:: 3.4
  31. Sets ``<var>`` to the absolute path of ``<FileName>``, where ``<mode>`` is one
  32. of:
  33. * ``ABSOLUTE`` - full path to file.
  34. * ``REALPATH`` - full path to existing file with symlinks resolved.
  35. If the provided ``<FileName>`` is a relative path, it is evaluated relative
  36. to the given base directory ``<dir>``. If no base directory is
  37. provided, the default base directory will be
  38. :variable:`CMAKE_CURRENT_SOURCE_DIR`.
  39. Paths are returned with forward slashes and have no trailing slashes. If the
  40. optional ``CACHE`` argument is specified, the result variable is added to the
  41. cache.
  42. .. code-block:: cmake
  43. get_filename_component(<var> <FileName> PROGRAM [PROGRAM_ARGS <arg_var>] [CACHE])
  44. The program in ``<FileName>`` will be found in the system search path or
  45. left as a full path. If ``PROGRAM_ARGS`` is present with ``PROGRAM``, then
  46. any command-line arguments present in the ``<FileName>`` string are split
  47. from the program name and stored in ``<arg_var>``. This is used to
  48. separate a program name from its arguments in a command line string.
  49. See Also
  50. ^^^^^^^^
  51. * :command:`cmake_path`