Skip to content

Commit 593881a

Browse files
committed
Moved extra_variable from GenericSystemBlock to new block which will be executed later
1 parent d0491bd commit 593881a

File tree

2 files changed

+18
-11
lines changed

2 files changed

+18
-11
lines changed

conan/tools/cmake/toolchain/blocks.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -795,11 +795,6 @@ class GenericSystemBlock(Block):
795795
message(STATUS "Conan toolchain: CMAKE_GENERATOR_TOOLSET={{ toolset }}")
796796
set(CMAKE_GENERATOR_TOOLSET "{{ toolset }}" CACHE STRING "" FORCE)
797797
{% endif %}
798-
{% if extra_variables %}
799-
{% for key, value in extra_variables.items() %}
800-
set({{ key }} "{{ value }}")
801-
{% endfor %}
802-
{% endif %}
803798
""")
804799

805800
@staticmethod
@@ -960,19 +955,30 @@ def context(self):
960955
result = self._get_winsdk_version(system_version, generator_platform)
961956
system_version, winsdk_version, gen_platform_sdk_version = result
962957

963-
# Reading configuration from "tools.cmake.cmaketoolchain:extra_variables"
964-
extra_variables = self._conanfile.conf.get("tools.cmake.cmaketoolchain:extra_variables", default={}, check_type=dict)
965-
966958
return {"toolset": toolset,
967959
"generator_platform": generator_platform,
968960
"cmake_system_name": system_name,
969961
"cmake_system_version": system_version,
970962
"cmake_system_processor": system_processor,
971963
"cmake_sysroot": cmake_sysroot,
972964
"winsdk_version": winsdk_version,
973-
"gen_platform_sdk_version": gen_platform_sdk_version,
974-
"extra_variables": extra_variables}
965+
"gen_platform_sdk_version": gen_platform_sdk_version}
975966

967+
class ExtraVariablesBlock(Block):
968+
template = textwrap.dedent(r"""
969+
{% if extra_variables %}
970+
{% for key, value in extra_variables.items() %}
971+
set({{ key }} "{{ value }}")
972+
{% endfor %}
973+
{% endif %}
974+
""")
975+
976+
def context(self):
977+
# Reading configuration from "tools.cmake.cmaketoolchain:extra_variables"
978+
extra_variables = self._conanfile.conf.get("tools.cmake.cmaketoolchain:extra_variables", default={}, check_type=dict)
979+
980+
# Map the possible languages
981+
return {"extra_variables": extra_variables}
976982

977983
class OutputDirsBlock(Block):
978984

conan/tools/cmake/toolchain/toolchain.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from conan.tools.build import use_win_mingw
1010
from conan.tools.cmake.presets import write_cmake_presets
1111
from conan.tools.cmake.toolchain import CONAN_TOOLCHAIN_FILENAME
12-
from conan.tools.cmake.toolchain.blocks import ToolchainBlocks, UserToolchain, GenericSystemBlock, \
12+
from conan.tools.cmake.toolchain.blocks import ExtraVariablesBlock, ToolchainBlocks, UserToolchain, GenericSystemBlock, \
1313
AndroidSystemBlock, AppleSystemBlock, FPicBlock, ArchitectureBlock, GLibCXXBlock, VSRuntimeBlock, \
1414
CppStdBlock, ParallelBlock, CMakeFlagsInitBlock, TryCompileBlock, FindFiles, PkgConfigBlock, \
1515
SkipRPath, SharedLibBock, OutputDirsBlock, ExtraFlagsBlock, CompilersBlock, LinkerScriptsBlock, \
@@ -153,6 +153,7 @@ 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),
156157
("compilers", CompilersBlock),
157158
("android_system", AndroidSystemBlock),
158159
("apple_system", AppleSystemBlock),

0 commit comments

Comments
 (0)