Confusion between CMake preset fields and cache variables

682 Views Asked by At

There is pretty new but cool feature in CMake: presets

I am confused with some of the possible values of preset: toolchainFile and installDir. This values could be set using simple cache variables, using cacheVariables entries (strictly CMAKE_TOOLCHAIN_FILE and CMAKE_INSTALL_PREFIX).

There is only a mention about toolchainFile in documentation, that states:

This field takes precedence over any CMAKE_TOOLCHAIN_FILE value.

This does not resolves my confusion. The question is: Which method should I use and what is the difference?

1

There are 1 best solutions below

0
On

[...] and what is the difference?

The docs explain the difference:

If a relative path is specified, it is calculated relative to the build directory, and if not found, relative to the source directory.

The cache variable is expected to be an absolute path (typically computed from ${sourceDir}).

The question is: Which method should I use[?]

You should probably use the more specific option. It's a bit clearer and marginally less typing. Not a huge deal either way.