-
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
Added support for tools.cmake.cmaketoolchain:extra_variables #16242
Added support for tools.cmake.cmaketoolchain:extra_variables #16242
Conversation
033e2e0
to
d0491bd
Compare
UPDATE @jcar87 wonder what would happen if there is a collision in defining
[settings]
...
[conf]
tools.cmake.cmaketoolchain:extra_variables={'A':'hello'}
conan install . --profile=profile -c tools.cmake.cmaketoolchain:extra_variables="{'B': 'world'}"
def generate(self):
deps = CMakeDeps(self)
deps.generate()
tc = CMakeToolchain(self)
tc.blocks["generic_system"].values["extra_variables"] = {'C': 'good day'}
tc.generate() This may be the desired behaviour: set(A "hello")
set(B "world")
set(C "good day") But actually, tc.blocks["generic_system"].values["extra_variables"]["C"] = "good day" Also, from python things are easier, if we want to merge the whole dictionary from tc.blocks["generic_system"].values["extra_variables"] = tc.blocks["generic_system"].values["extra_variables"] | {'foo': 'bar'} This will generate: set(B "world")
set(C "good day") But still have the problem of preference order: |
To clarify the merge behavior in the case of Python dicts, it's already explained in this section of the Conan docs. |
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.
Looks good.
The only thing I'd consider, but this is something we need to discuss with @jcar87 too, is if we wanted to move this much later in the toolchain, so it can be used to overwrite other existing variables (see for example #16240). If we do that, in the same spirit we would like to have a user_toolchain_append
or similar that injects user files at the end of the toolchain, allowing users to overwrite other possible things that the toolchain is defining and doesn't have another way to fix them.
I've just pushed new changes which creates a new block to handle this new field. This block can be inserted later in order to inject variables later and override possible variables. |
Lets do the following:
|
593881a
to
aa753af
Compare
os=Windows | ||
arch=x86_64 | ||
[conf] | ||
tools.cmake.cmaketoolchain:extra_variables={'CMAKE_GENERATOR_INSTANCE': '"${GENERATOR_INSTANCE}/buildTools/"', 'FOO': '42 CACHE' } |
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 like the feature, but I'm not too sure about defining cache variables this way? having the spaces be separators for cmake syntax I'm not too sure.
set(FOO 42 CACHE)
IIRC, this is not valid CMake syntax:
CMake Error at CMakeLists.txt:5 (set):
set given invalid arguments for CACHE mode.
(I think the type and dosctring are missing, see docs)
I wonder if we could have something like what CMake uses for presets:
"cacheVariables": {
"FIRST_CACHE_VARIABLE": {
"type": "BOOL",
"value": "OFF"
},
"SECOND_CACHE_VARIABLE": "ON"
},
we could maybe have something like this, where we either take the value (which shouldn't allow spaces unless they are inside double quotes?) or a dictionary with the value, whether it is cache or not, and if it is cache, the other needed info (like the type)
tools.cmake.cmaketoolchain:extra_variables={'CMAKE_GENERATOR_INSTANCE': '"${GENERATOR_INSTANCE}/buildTools/"', 'FOO': {value:'42', cache: true, type: 'bool'}} }
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.
Alright, take a look at the new design. It is now fully working and tested.
Now we are supporting:
{
'A': 'string value',
'B': 42,
'C': 1.3,
'D': '${ENV}/test',
'DICT': {'value': '42 sense', 'cache': true, 'type': 'BOOL', 'docstring': 'test cache var'}
}
Dict values includes:
- Support for pythonic boolean inputs or string inputs (in
cache
variable) - Descriptive error if cache variable and not
type
ordocstring
defined - Descriptive error if cache type not in
BOOL, FILEPATH, PATH, STRING, INTERNAL
list
Generating following CMake output:
set(A 'string value')
set(B 42)
set(C 1.3)
set(D "${ENV}/test")
set(value "42 sense" CACHE BOOL "test cache var")
3ffb1f8
to
aa753af
Compare
…be executed later
This will allow users to re-define variables
Now it admits not only plain key:value pairs but dictionary values in the form: {'value': <value>, 'cache': <true/false>, 'type': <cache_type>, 'docstring': <cache docstring> }
3f209d7
to
a302915
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.
Updated code
a302915
to
79bb96f
Compare
79bb96f
to
ab9487f
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.
Nice
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!!!
I have test this feature with conan version 2.4.1
Here is generated toolchain file
CMake actually recognizes using the above parameters |
Hi @peterpuppy first of all thank you for your feedback! As you have seen, injecting "FORCE" parameter is still not available. Stay tuned! |
Changelog: Feature: add support for setting
tools.cmake.cmaketoolchain:extra_variables
Docs: conan-io/docs#3719
Closes: #16222
develop
branch, documenting this one.