get_filename_component.rst 2.3 KB

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