Use environment variables to specify compiler preferences. - #5731
Merged
Regan Downer (v-regandowner) merged 3 commits intoSep 18, 2025
Merged
Regan Downer (v-regandowner) merged 3 commits into
Regan Downer (v-regandowner) merged 3 commits into
Conversation
The cache variables `CMAKE_C_COMPILER` and `CMAKE_CXX_COMPILER` must only be set during the initial cache creation. Specifying them in a preset will cause them to be reset during subsequent cache configurations, resulting in a cache invalidation, which can break the build. Using the `CC` and `CXX` environment variables to initialize those cache variables is the proper way to avoid this issue.
Contributor
|
Learn Build status updates of commit 55088ae: ✅ Validation status: passed
For more details, please refer to the build report. |
Contributor
|
Can you review the proposed changes? Important: When the changes are ready for publication, adding a #label:"aq-pr-triaged" |
Contributor
|
Learn Build status updates of commit a78f16c: ✅ Validation status: passed
For more details, please refer to the build report. |
Contributor
|
Learn Build status updates of commit 453dc40: ✅ Validation status: passed
For more details, please refer to the build report. |
Tyler Whitney (TylerMSFT)
approved these changes
Sep 18, 2025
Tyler Whitney (TylerMSFT)
left a comment
Collaborator
There was a problem hiding this comment.
Thank you for improving the doc!
Collaborator
|
#sign-off |
Regan Downer (v-regandowner)
merged commit Sep 18, 2025
42c515f
into
MicrosoftDocs:main
2 checks passed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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>_COMPILERcache 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
CXXandCCenvironment variables. Those are used only during the initial cache configuration run to initialize theCMAKE_C_COMPILERandCMAKE_CXX_COMPILERvariables. This fixes the aforementioned issues in all projects, I've tested it.