-
Notifications
You must be signed in to change notification settings - Fork 982
Use environment variables to specify compiler preferences. #5731
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Use environment variables to specify compiler preferences. #5731
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.
|
Learn Build status updates of commit 55088ae: ✅ Validation status: passed
For more details, please refer to the build report. |
|
Can you review the proposed changes? Important: When the changes are ready for publication, adding a #label:"aq-pr-triaged" |
|
Learn Build status updates of commit a78f16c: ✅ Validation status: passed
For more details, please refer to the build report. |
|
Learn Build status updates of commit 453dc40: ✅ Validation status: passed
For more details, please refer to the build report. |
TylerMSFT
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for improving the doc!
|
#sign-off |
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.