get_filename_component.rst 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 extention (.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. The longest file extension is always considered. If the optional
  17. ``CACHE`` argument is specified, the result variable is added to the
  18. cache.
  19. .. code-block:: cmake
  20. get_filename_component(<var> <FileName> <mode> [BASE_DIR <dir>] [CACHE])
  21. Sets ``<var>`` to the absolute path of ``<FileName>``, where ``<mode>`` is one
  22. of:
  23. ::
  24. ABSOLUTE = Full path to file
  25. REALPATH = Full path to existing file with symlinks resolved
  26. If the provided ``<FileName>`` is a relative path, it is evaluated relative
  27. to the given base directory ``<dir>``. If no base directory is
  28. provided, the default base directory will be
  29. :variable:`CMAKE_CURRENT_SOURCE_DIR`.
  30. Paths are returned with forward slashes and have no trailing slashes. If the
  31. optional ``CACHE`` argument is specified, the result variable is added to the
  32. cache.
  33. .. code-block:: cmake
  34. get_filename_component(<var> <FileName> PROGRAM [PROGRAM_ARGS <arg_var>] [CACHE])
  35. The program in ``<FileName>`` will be found in the system search path or
  36. left as a full path. If ``PROGRAM_ARGS`` is present with ``PROGRAM``, then
  37. any command-line arguments present in the ``<FileName>`` string are split
  38. from the program name and stored in ``<arg_var>``. This is used to
  39. separate a program name from its arguments in a command line string.