get_filename_component.rst 1.8 KB

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