Skip to content

Commit aa753af

Browse files
committed
Moved extra variables just before the try_compile block.
This will allow users to re-define variables
1 parent 6f35a50 commit aa753af

File tree

4 files changed

+9
-6
lines changed

4 files changed

+9
-6
lines changed

conan/tools/cmake/toolchain/blocks.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1007,7 +1007,7 @@ class ExtraVariablesBlock(Block):
10071007
template = textwrap.dedent(r"""
10081008
{% if extra_variables %}
10091009
{% for key, value in extra_variables.items() %}
1010-
set({{ key }} "{{ value }}")
1010+
set({{ key }} {{ value }})
10111011
{% endfor %}
10121012
{% endif %}
10131013
""")

conan/tools/cmake/toolchain/toolchain.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,6 @@ def __init__(self, conanfile, generator=None):
153153
self.blocks = ToolchainBlocks(self._conanfile, self,
154154
[("user_toolchain", UserToolchain),
155155
("generic_system", GenericSystemBlock),
156-
("extra_variables", ExtraVariablesBlock),
157156
("compilers", CompilersBlock),
158157
("android_system", AndroidSystemBlock),
159158
("apple_system", AppleSystemBlock),
@@ -167,6 +166,7 @@ def __init__(self, conanfile, generator=None):
167166
("parallel", ParallelBlock),
168167
("extra_flags", ExtraFlagsBlock),
169168
("cmake_flags_init", CMakeFlagsInitBlock),
169+
("extra_variables", ExtraVariablesBlock),
170170
("try_compile", TryCompileBlock),
171171
("find_paths", FindFiles),
172172
("pkg_config", PkgConfigBlock),

conans/model/conf.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"tools.cmake.cmaketoolchain:toolset_arch": "Toolset architecture to be used as part of CMAKE_GENERATOR_TOOLSET in CMakeToolchain",
7474
"tools.cmake.cmaketoolchain:toolset_cuda": "(Experimental) Path to a CUDA toolset to use, or version if installed at the system level",
7575
"tools.cmake.cmaketoolchain:presets_environment": "String to define wether to add or not the environment section to the CMake presets. Empty by default, will generate the environment section in CMakePresets. Can take values: 'disabled'.",
76-
"tools.cmake.cmaketoolchain:extra_variables": "Dictionary with variables to be injected in CMakeToolchain",
76+
"tools.cmake.cmaketoolchain:extra_variables": "Dictionary with variables to be injected in CMakeToolchain (potential override of CMakeToolchain defined variables)",
7777
"tools.cmake.cmake_layout:build_folder_vars": "Settings and Options that will produce a different build folder and different CMake presets names",
7878
"tools.cmake.cmake_layout:build_folder": "(Experimental) Allow configuring the base folder of the build for local builds",
7979
"tools.cmake.cmake_layout:test_folder": "(Experimental) Allow configuring the base folder of the build for test_package",

conans/test/integration/toolchains/cmake/test_cmaketoolchain.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1589,15 +1589,18 @@ def test_toolchain_extra_variables():
15891589
client.save({"conanfile.txt": "[generators]\nCMakeToolchain",
15901590
"windows": windows_profile})
15911591

1592-
# Test passing extra_variables from profile
1592+
# Test passing extra_variables from pro ile
15931593
client.run("install . --profile:build=windows --profile:host=windows")
15941594
toolchain = client.load("conan_toolchain.cmake")
15951595
assert 'set(CMAKE_GENERATOR_INSTANCE "${GENERATOR_INSTANCE}/buildTools/")' in toolchain
15961596
assert 'set(FOO 42 CACHE)' in toolchain
15971597

15981598
# Test input from command line passing dict between doble quotes
1599-
1600-
client.run("install . -c tools.cmake.cmaketoolchain:extra_variables=\"{'CMAKE_GENERATOR_INSTANCE': '\"\${GENERATOR_INSTANCE}/buildTools/\"', 'FOO': '42 CACHE'}\"")
1599+
client.run(textwrap.dedent(r"""
1600+
install . -c tools.cmake.cmaketoolchain:extra_variables="{'CMAKE_GENERATOR_INSTANCE': '\"${GENERATOR_INSTANCE}/buildTools/\"', 'FOO': '42 CACHE'}"
1601+
""")
1602+
)
16011603
toolchain = client.load("conan_toolchain.cmake")
1604+
print(toolchain)
16021605
assert 'set(CMAKE_GENERATOR_INSTANCE "${GENERATOR_INSTANCE}/buildTools/")' in toolchain
16031606
assert 'set(FOO 42 CACHE)' in toolchain

0 commit comments

Comments
 (0)