get_filename_component.rst 1.9 KB

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