File: load_cache.rst

package info (click to toggle)
cmake 4.2.1-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 152,348 kB
  • sloc: ansic: 403,894; cpp: 303,807; sh: 4,097; python: 3,582; yacc: 3,106; lex: 1,279; f90: 538; asm: 471; lisp: 375; cs: 270; java: 266; fortran: 239; objc: 215; perl: 213; xml: 198; makefile: 108; javascript: 83; pascal: 63; tcl: 55; php: 25; ruby: 22
file content (110 lines) | stat: -rw-r--r-- 3,558 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
load_cache
----------

Load in the values from another project's ``CMakeCache.txt`` cache file.  This
is useful for projects that depend on another project built in a separate
directory tree.

This command has two signatures.  The recommended signature is:

.. signature::
  load_cache(<build-dir> READ_WITH_PREFIX <prefix> <entry>...)
  :target: READ_WITH_PREFIX

  Loads the cache file from the specified ``<build-dir>`` build directory and
  retrieves the listed cache entries.  The retrieved values are stored in local
  variables, with their names prefixed by the provided ``<prefix>``.  This only
  reads the cache values; it does not create or modify entries in the local
  project's cache.

  ``READ_WITH_PREFIX <prefix>``
    For each cache ``<entry>``, a local variable is created using the specified
    ``<prefix>`` followed by the entry name.

  This signature can be also used in :option:`cmake -P` script mode.

The following signature of this command is strongly discouraged, but it is
provided for backward compatibility:

.. signature::
  load_cache(<build-dir> [EXCLUDE <entry>...] [INCLUDE_INTERNALS <entry>...])
  :target: raw

  This form loads the cache file from the specified ``<build-dir>`` build
  directory and imports all its non-internal cache entries into the local
  project's cache as internal cache variables.  By default, only non-internal
  entries are imported, unless the ``INCLUDE_INTERNALS`` option is used.

  The options are:

  ``EXCLUDE <entry>...``
    This option can be used to exclude a given list of non-internal cache
    entries when importing values.
  ``INCLUDE_INTERNALS <entry>...``
    This option can be used to provide a list of internal cache entries to
    include in addition to the non-internal cache entries.

  This signature can be used only in CMake projects.  Script mode is not
  supported.

.. note::

  Instead of loading the outside project's cache file and manually accessing
  variables, a more robust and convenient approach is to use the
  :command:`export` command in the outside project, when available.  This allows
  the project to provide its targets, configuration, or features in a
  structured and maintainable way, making integration simpler and less
  error-prone.

Examples
^^^^^^^^

Reading specific cache variables from another project and storing them as local
variables:

.. code-block:: cmake

  load_cache(
    path/to/other-project/build-dir
    READ_WITH_PREFIX prefix_
    OTHER_PROJECT_CACHE_VAR_1
    OTHER_PROJECT_CACHE_VAR_2
  )

  message(STATUS "${prefix_OTHER_PROJECT_CACHE_VAR_1")
  message(STATUS "${prefix_OTHER_PROJECT_CACHE_VAR_2")
  # Outputs:
  # -- some-value...
  # -- another-value...

Reading all non-internal cache entries from another project and storing them as
internal cache variables using the obsolete signature:

.. code-block:: cmake

  load_cache(path/to/other-project/build-dir)

  message(STATUS "${OTHER_PROJECT_CACHE_VAR_1")
  message(STATUS "${OTHER_PROJECT_CACHE_VAR_2")
  # Outputs:
  # -- some-value...
  # -- another-value...

Excluding specific non-internal cache entries and including internal ones using
the obsolete signature:

.. code-block:: cmake

  load_cache(
    path/to/other-project/build-dir
    EXCLUDE OTHER_PROJECT_CACHE_VAR_2
    INCLUDE_INTERNALS OTHER_PROJECT_INTERNAL_CACHE_VAR
  )

  message(STATUS "${OTHER_PROJECT_CACHE_VAR_1")
  message(STATUS "${OTHER_PROJECT_CACHE_VAR_2")
  message(STATUS "${OTHER_PROJECT_INTERNAL_CACHE_VAR}")
  # Outputs:
  # -- some-value...
  # --
  # -- some-internal-value...