-
Notifications
You must be signed in to change notification settings - Fork 991
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
Define compiler variables in CMakePresets.json #16762
Define compiler variables in CMakePresets.json #16762
Conversation
b5ec82e
to
c09a252
Compare
c09a252
to
7f694c9
Compare
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.
I think this can be moved forward for next release, thanks very much for your contribution!
Asking @jcar87 for an extra review, thanks!
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.
LGTM!
@memsharded, I would consider passing cl.exe
to both C and CXX compilers if compiler=msvc
, the cmake generator is Ninja, even when tools.build.compiler_executables
is undefined.
@@ -158,6 +158,13 @@ def _configure_preset(conanfile, generator, cache_variables, toolchain_file, mul | |||
"strategy": "external" | |||
} | |||
|
|||
# Set the compiler like in the toolchain. Some IDEs like VS or VSCode require the compiler | |||
# being set to cl.exe in order to activate the environment using vcvarsall.bat according to |
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.
interesting! I've not found this documented for VS Code, but have verified that it indeed works that way. Thanks so much for figuring this out! :D
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.
I thought it was documented somewhere, but I couldn't find it either and can't remember how I learned about it in the first place. But I have used this trick successfully for some time now and seeing this comment this has been a thing for at least 3 years.
[settings] | ||
os=Windows | ||
arch=x86_64 | ||
compiler=clang |
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.
I can see the output is as expected, but wouldn't he compiler executables be clang
or clang-cl.exe
instead?
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.
I think this is being directly overriden by tools.build:compiler_executables
and most likely the intention of the test was to have compiler=msvc
, can you please confirm @petwu?
I'll check if it makes sense or is possible to introduce some check for this.
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.
I suspect this is derived from copy&paste the test above called test_set_cmake_lang_compilers_and_launchers
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.
Exactly, I have pushed some changes to the test to define compiler=msvc
instead.
Indeed, the compiler_executables
is being written no matter what the compiler
setting is, it is the responsibility of the user to define the profiles consistently. I have checked if it is possible to introduce some check that made sense for potential misalignments like this one (defining compiler_executable
with cl.exe
for other compiler not msvc
, but it looks a bit too dirty, so leaving it out of this PR, might reconsider later.
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.
You are right, I just copied the test above. Setting compiler=clang
and then saying your executable is called cl.exe
of course doesn't make sense in a real-world scenario. The test should just verify that the compiler_executable
setting ended up in the generated preset.
This reverts commit 60df72c.
Changelog: Feature: Define
CMAKE_<LANG>_COMPILER
variables in CMakePresets.json.Docs: Omit
Fixes #13136
The compiler variables are set to the same values as in the
cmake_toolchain.cmake
, and only when definingtools.build:compiler_executables
.I've tested it with both VS an VS Code, which successfully initialize the correct vcvars environment and select the correct compiler as specified by the toolset version, host and target architecture. From a non-IDE perspective, this does influence the CMake configuration in any way, as the compiler variables would be set in the toolchain to the same value anyway.
profile
conanfile.txt
CMakePresets.json after
conan install -pr profile -s build_type=Debug .
develop
branch, documenting this one.