load_cache.rst 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  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. This signature can be also used in :option:`cmake -P` script mode.
  19. The following signature of this command is strongly discouraged, but it is
  20. provided for backward compatibility:
  21. .. signature::
  22. load_cache(<build-dir> [EXCLUDE <entry>...] [INCLUDE_INTERNALS <entry>...])
  23. :target: raw
  24. This form loads the cache file from the specified ``<build-dir>`` build
  25. directory and imports all its non-internal cache entries into the local
  26. project's cache as internal cache variables. By default, only non-internal
  27. entries are imported, unless the ``INCLUDE_INTERNALS`` option is used.
  28. The options are:
  29. ``EXCLUDE <entry>...``
  30. This option can be used to exclude a given list of non-internal cache
  31. entries when importing values.
  32. ``INCLUDE_INTERNALS <entry>...``
  33. This option can be used to provide a list of internal cache entries to
  34. include in addition to the non-internal cache entries.
  35. This signature can be used only in CMake projects. Script mode is not
  36. supported.
  37. Examples
  38. ^^^^^^^^
  39. Reading specific cache variables from another project and storing them as local
  40. variables:
  41. .. code-block:: cmake
  42. load_cache(
  43. path/to/other-project/build-dir
  44. READ_WITH_PREFIX prefix_
  45. OTHER_PROJECT_CACHE_VAR_1
  46. OTHER_PROJECT_CACHE_VAR_2
  47. )
  48. message(STATUS "${prefix_OTHER_PROJECT_CACHE_VAR_1")
  49. message(STATUS "${prefix_OTHER_PROJECT_CACHE_VAR_2")
  50. # Outputs:
  51. # -- some-value...
  52. # -- another-value...
  53. Reading all non-internal cache entries from another project and storing them as
  54. internal cache variables using the obsolete signature:
  55. .. code-block:: cmake
  56. load_cache(path/to/other-project/build-dir)
  57. message(STATUS "${OTHER_PROJECT_CACHE_VAR_1")
  58. message(STATUS "${OTHER_PROJECT_CACHE_VAR_2")
  59. # Outputs:
  60. # -- some-value...
  61. # -- another-value...
  62. Excluding specific non-internal cache entries and including internal ones using
  63. the obsolete signature:
  64. .. code-block:: cmake
  65. load_cache(
  66. path/to/other-project/build-dir
  67. EXCLUDE OTHER_PROJECT_CACHE_VAR_2
  68. INCLUDE_INTERNALS OTHER_PROJECT_INTERNAL_CACHE_VAR
  69. )
  70. message(STATUS "${OTHER_PROJECT_CACHE_VAR_1")
  71. message(STATUS "${OTHER_PROJECT_CACHE_VAR_2")
  72. message(STATUS "${OTHER_PROJECT_INTERNAL_CACHE_VAR}")
  73. # Outputs:
  74. # -- some-value...
  75. # --
  76. # -- some-internal-value...