Skip to content

Commit

Permalink
Adding new conf to allow specifying compiler update when ``compiler.v…
Browse files Browse the repository at this point in the history
…ersion=193`` with VS 17.10 (#16332)

* defaulting compiler.version=193 to latest update in CMake

* fix

* using conf

* removed test file
  • Loading branch information
memsharded authored May 28, 2024
1 parent 34f67be commit 54c1c08
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 4 deletions.
5 changes: 3 additions & 2 deletions conan/tools/cmake/toolchain/blocks.py
Original file line number Diff line number Diff line change
Expand Up @@ -810,9 +810,10 @@ def get_toolset(generator, conanfile):
toolset = settings.get_safe("compiler.toolset")
if toolset is None:
compiler_version = str(settings.compiler.version)
compiler_update = str(settings.compiler.update)
msvc_update = conanfile.conf.get("tools.microsoft:msvc_update")
compiler_update = msvc_update or settings.get_safe("compiler.update")
toolset = msvc_version_to_toolset_version(compiler_version)
if compiler_update != "None": # It is full one(19.28), not generic 19.2X
if compiler_update is not None: # It is full one(19.28), not generic 19.2X
# The equivalent of compiler 19.26 is toolset 14.26
toolset += ",version=14.{}{}".format(compiler_version[-1], compiler_update)
elif compiler == "clang":
Expand Down
3 changes: 2 additions & 1 deletion conan/tools/microsoft/visual.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ def check_min_vs(conanfile, version, raise_invalid=True):
"11": "170"}.get(compiler_version)
elif compiler == "msvc":
compiler_version = conanfile.settings.get_safe("compiler.version")
compiler_update = conanfile.settings.get_safe("compiler.update")
msvc_update = conanfile.conf.get("tools.microsoft:msvc_update")
compiler_update = msvc_update or conanfile.settings.get_safe("compiler.update")
if compiler_version and compiler_update is not None:
compiler_version += ".{}".format(compiler_update)

Expand Down
1 change: 1 addition & 0 deletions conans/model/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@
"tools.meson.mesontoolchain:backend": "Any Meson backend: ninja, vs, vs2010, vs2012, vs2013, vs2015, vs2017, vs2019, xcode",
"tools.meson.mesontoolchain:extra_machine_files": "List of paths for any additional native/cross file references to be appended to the existing Conan ones",
"tools.microsoft:winsdk_version": "Use this winsdk_version in vcvars",
"tools.microsoft:msvc_update": "Force the specific update irrespective of compiler.update (CMakeToolchain and VCVars)",
"tools.microsoft.msbuild:vs_version": "Defines the IDE version (15, 16, 17) when using the msvc compiler. Necessary if compiler.version specifies a toolset that is not the IDE default",
"tools.microsoft.msbuild:max_cpu_count": "Argument for the /m when running msvc to build parallel projects",
"tools.microsoft.msbuild:installation_path": "VS install path, to avoid auto-detect via vswhere, like C:/Program Files (x86)/Microsoft Visual Studio/2019/Community. Use empty string to disable",
Expand Down
18 changes: 17 additions & 1 deletion conans/test/unittests/tools/cmake/test_cmaketoolchain.py
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ def conanfile_msvc():
c.settings.build_type = "Release"
c.settings.arch = "x86"
c.settings.compiler = "msvc"
c.settings.compiler.version = "193"
c.settings.compiler.version = "194"
c.settings.compiler.cppstd = "20"
c.settings.os = "Windows"
c.settings_build = c.settings
Expand All @@ -221,11 +221,27 @@ def test_toolset(conanfile_msvc):


def test_toolset_update_version(conanfile_msvc):
conanfile_msvc.settings.compiler.version = "193"
conanfile_msvc.settings.compiler.update = "8"
toolchain = CMakeToolchain(conanfile_msvc)
assert 'set(CMAKE_GENERATOR_TOOLSET "v143,version=14.38" CACHE STRING "" FORCE)' in toolchain.content


def test_toolset_update_version_conf(conanfile_msvc):
conanfile_msvc.settings.compiler.version = "193"
conanfile_msvc.conf.define("tools.microsoft:msvc_update", "7")
toolchain = CMakeToolchain(conanfile_msvc)
assert 'set(CMAKE_GENERATOR_TOOLSET "v143,version=14.37" CACHE STRING "" FORCE)' in toolchain.content


def test_toolset_update_version_forced_conf(conanfile_msvc):
conanfile_msvc.settings.compiler.version = "193"
conanfile_msvc.settings.compiler.update = "8"
conanfile_msvc.conf.define("tools.microsoft:msvc_update", "7")
toolchain = CMakeToolchain(conanfile_msvc)
assert 'set(CMAKE_GENERATOR_TOOLSET "v143,version=14.37" CACHE STRING "" FORCE)' in toolchain.content


def test_toolset_update_version_overflow(conanfile_msvc):
# https://github.com/conan-io/conan/issues/15583
conanfile_msvc.settings.compiler.version = "194"
Expand Down

0 comments on commit 54c1c08

Please sign in to comment.