get_filename_component.rst 2.1 KB

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