Use environment variables to specify compiler preferences. #5731
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The documentation is using a problematic way to specify the compiler in a preset, namely by setting the
CMAKE_<LANG>_COMPILER
cache variables. This should be avoided, as it can cause problems with subsequent cache configuration runs. An example for where this becomes problematic is described here.The CMake docs for those variables state:
However, specifying a cache variable in a CMake preset will cause the variable to be reset with every subsequent cache configuration run. This usually results in a warning like the following:
In the best case, this will simply delete and re-create the entire cache. In the worst case, however, this re-creation will cause problems as previously cached entries are reset. I frequently encountered this problem when resolving packages from vcpkg. The directories to the *Config.cmake files were removed during this process and the actual configuration step then failed because the package could no longer be resolved. This is the same problem as observed in the linked post above.
Instead of setting those cache variables directly, I've changed the documentation to use the
CXX
andCC
environment variables. Those are used only during the initial cache configuration run to initialize theCMAKE_C_COMPILER
andCMAKE_CXX_COMPILER
variables. This fixes the aforementioned issues in all projects, I've tested it.