load_cache.rst 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  1. load_cache
  2. ----------
  3. Load in the values from another project's ``CMakeCache.txt`` cache file. This
  4. is useful for projects that depend on another project built in a separate
  5. directory tree.
  6. This command has two signatures. The recommended signature is:
  7. .. signature::
  8. load_cache(<build-dir> READ_WITH_PREFIX <prefix> <entry>...)
  9. :target: READ_WITH_PREFIX
  10. Loads the cache file from the specified ``<build-dir>`` build directory and
  11. retrieves the listed cache entries. The retrieved values are stored in local
  12. variables, with their names prefixed by the provided ``<prefix>``. This only
  13. reads the cache values; it does not create or modify entries in the local
  14. project's cache.
  15. ``READ_WITH_PREFIX <prefix>``
  16. For each cache ``<entry>``, a local variable is created using the specified
  17. ``<prefix>`` followed by the entry name.
  18. The following signature of this command is strongly discouraged, but it is
  19. provided for backward compatibility:
  20. .. signature::
  21. load_cache(<build-dir> [EXCLUDE <entry>...] [INCLUDE_INTERNALS <entry>...])
  22. :target: raw
  23. This form loads the cache file from the specified ``<build-dir>`` build
  24. directory and imports all its non-internal cache entries into the local
  25. project's cache as internal cache variables. By default, only non-internal
  26. entries are imported, unless the ``INCLUDE_INTERNALS`` option is used.
  27. The options are:
  28. ``EXCLUDE <entry>...``
  29. This option can be used to exclude a given list of non-internal cache
  30. entries when importing values.
  31. ``INCLUDE_INTERNALS <entry>...``
  32. This option can be used to provide a list of internal cache entries to
  33. include in addition to the non-internal cache entries.
  34. Examples
  35. ^^^^^^^^
  36. Reading specific cache variables from another project and storing them as local
  37. variables:
  38. .. code-block:: cmake
  39. load_cache(
  40. path/to/other-project/build-dir
  41. READ_WITH_PREFIX prefix_
  42. OTHER_PROJECT_CACHE_VAR_1
  43. OTHER_PROJECT_CACHE_VAR_2
  44. )
  45. message(STATUS "${prefix_OTHER_PROJECT_CACHE_VAR_1")
  46. message(STATUS "${prefix_OTHER_PROJECT_CACHE_VAR_2")
  47. # Outputs:
  48. # -- some-value...
  49. # -- another-value...
  50. Reading all non-internal cache entries from another project and storing them as
  51. internal cache variables using the obsolete signature:
  52. .. code-block:: cmake
  53. load_cache(path/to/other-project/build-dir)
  54. message(STATUS "${OTHER_PROJECT_CACHE_VAR_1")
  55. message(STATUS "${OTHER_PROJECT_CACHE_VAR_2")
  56. # Outputs:
  57. # -- some-value...
  58. # -- another-value...
  59. Excluding specific non-internal cache entries and including internal ones using
  60. the obsolete signature:
  61. .. code-block:: cmake
  62. load_cache(
  63. path/to/other-project/build-dir
  64. EXCLUDE OTHER_PROJECT_CACHE_VAR_2
  65. INCLUDE_INTERNALS OTHER_PROJECT_INTERNAL_CACHE_VAR
  66. )
  67. message(STATUS "${OTHER_PROJECT_CACHE_VAR_1")
  68. message(STATUS "${OTHER_PROJECT_CACHE_VAR_2")
  69. message(STATUS "${OTHER_PROJECT_INTERNAL_CACHE_VAR}")
  70. # Outputs:
  71. # -- some-value...
  72. # --
  73. # -- some-internal-value...