[question] CMakeToolchain: When use cached_variables vs variables
See original GitHub issueThe documentation only explains CMakeToolchain.variables
and CMakeToolchain.cached_variables
features, one is better for multiple configuration and another is single configuration:
https://docs.conan.io/en/latest/reference/conanfile/tools/cmake/cmaketoolchain.html#variables
But it’s not clear when each one should be used, based on real examples.
So far, we are migrating recipes in CCI and there is a doubt about which one should be adopted by default when using CMakeToolchain
.
- I’ve read the CONTRIBUTING guide.
Issue Analytics
- State:
- Created a year ago
- Comments:7 (7 by maintainers)
Top Results From Across the Web
Check CMake Cache Variable in Toolchain File - Stack Overflow
Problem : CMake runs toolchain files multiple times, but can't read cache variables on some runs. # Workaround: On first run (in which...
Read more >Docs should mention that CMAKE_TOOLCHAIN_FILE does ...
I am unsure if this is intended behavior. When setting the CMAKE_SYSROOT variable in a Toolchain file, cache variables defined inside the ...
Read more >Variables and the Cache · Modern CMake
Variables and the Cache. Local Variables. We will cover variables first. A local variable is set like this: set(MY_VARIABLE "value"). The names of...
Read more >Configure and build with CMake Presets in Visual Studio
Use these files to drive CMake in Visual Studio and Visual Studio Code, in a ... Environment variables set in a Configure Preset...
Read more >System environment variable reading in CMakeSettings.json ...
when I want to read this variable in CMakeSettings.json Visual Studio does not retrieve this value and generating of CMake cache is hung....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
From what I’ve seen, they are passed as
set(VAR_NAME "var_value" CACHE <type> "Variable VAR_NAME conan-toolchain defined")
(https://github.com/conan-io/docs/issues/2689). So the new typecache_variables
is quite misleading (it’s cache_variables in CMakePresets terminology AFAIK). If they were not passed asCACHE
variables, they couldn’t override options until CMake >=3.13 policies. It’s what happens toBUILD_SHARED_LIBS
: https://github.com/conan-io/conan/issues/11840From my experimentations:
CMAKE_POLICY_DEFAULT_CMPxxxx
must be passed ascache_variables
.variables
.BUILD_SHARED_LIBS
orCMAKE_POSITION_INDEPENDENT_CODE
are turned asoption()
in upstream CMakeLists andcmake_minimum_required()
is lower than 3.13 , you have to either:CMAKE_POLICY_DEFAULT_CMP0077
(https://github.com/conan-io/conan/issues/11840)BUILD_SHARED_LIBS
/CMAKE_POSITION_INDEPENDENT_CODE
asvariables
(orcache_variables
).BUILD_SHARED_LIBS
orCMAKE_POSITION_INDEPENDENT_CODE
are turned asCACHE
variables in upstream CMakeLists, you have to passBUILD_SHARED_LIBS
/CMAKE_POSITION_INDEPENDENT_CODE
asvariables
(orcache_variables
).variables
(and it may not be obvious to see it), for example:cmake_minimum_required()
missing.project()
beforecmake_minimum_required()
.option()
orCACHE
variables betweencmake_minimum_required()
&project()
(pernicious, you may not see that recipe options injected through conan toolchain are not honored).@jwillikers Sorry! 😓