Repository: conan-io/conan-center-index

Issue:
[package] lcms/2.12: can't build win32 lib with VS2019 on win10
### Package and Environment Details (include every applicable attribute)
  * Package Name/Version: **lcms/2.12**
  * Operating System+version: **windows 10**
  * Compiler+version: **VS2019**
  * Docker image: NA
  * Conan version: **conan 1.41.0**
  * Python version: **Python 3.6.13 :: Anaconda custom (64-bit)**


### Conan profile (output of `conan profile show default` or `conan profile show <profile>` if custom profile is in use)
```
Configuration for profile default:

[settings]
os=Windows
os_build=Windows
arch=x86_64
arch_build=x86_64
compiler=Visual Studio
compiler.version=16
build_type=Release
[options]
[conf]
[build_requires]
[env]
```


### Steps to reproduce (Include if Applicable)
Running the command below fails to build lcms/2.12 due to my machine's lack of windows SDK 8.1.  My `conanfile.txt` is in the `build/` subfolder of the current dir.

```
>conan install build -s arch=x86 -s build_type=Release -s compiler="Visual Studio" -s compiler.runtime=MT -s compiler.version=16 --install-folder build/win/conan/win32/Release --build
```

### Logs (Include/Attach if Applicable)
<details><summary>Click to expand log</summary>

```
Configuration:
[settings]
arch=x86
arch_build=x86_64
build_type=Release
compiler=Visual Studio
compiler.runtime=MT
compiler.version=16
os=Windows
os_build=Windows
[options]
[build_requires]
[env]

lcms/2.12: Forced build from source
conanfile.txt: Installing package
Requirements
    lcms/2.12 from 'conancenter' - Cache
Packages
    lcms/2.12:d4bb31912cc39810f01c804d7ba2f80b8bd35a3a - Build

Cross-build from 'Windows:x86_64' to 'Windows:x86'
Installing (downloading, building) binaries...
lcms/2.12: Configuring sources in C:\Users\atevet\.conan\data\lcms\2.12\_\_\source
Downloading 2.12.tar.gz completed [7231.36k]

lcms/2.12: Copying sources to build folder
lcms/2.12: Building your package in C:\Users\atevet\.conan\data\lcms\2.12\_\_\build\d4bb31912cc39810f01c804d7ba2f80b8bd35a3a
lcms/2.12: Generator txt created conanbuildinfo.txt
lcms/2.12: Aggregating env generators
lcms/2.12: Calling build()
**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.10.3
** Copyright (c) 2021 Microsoft Corporation
**********************************************************************
[vcvarsall.bat] Environment initialized for: 'x86'

Microsoft Visual Studio 2019 Version 16.10.3.
Copyright (C) Microsoft Corp. All rights reserved.
Upgrading project 'testbed'...
        Configuration 'Debug|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Debug|x64': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|x64': changing Platform Toolset to 'v142' (was 'v140').
Upgrading project 'tifficc'...
        Configuration 'Debug|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Debug|x64': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|x64': changing Platform Toolset to 'v142' (was 'v140').
Upgrading project 'lcms2_DLL'...
        Configuration 'Debug|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Debug|x64': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|x64': changing Platform Toolset to 'v142' (was 'v140').
Upgrading project 'linkicc'...
        Configuration 'Debug|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Debug|x64': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|x64': changing Platform Toolset to 'v142' (was 'v140').
Upgrading project 'transicc'...
        Configuration 'Debug|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Debug|x64': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|x64': changing Platform Toolset to 'v142' (was 'v140').
Upgrading project 'jpegicc'...
        Configuration 'Debug|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Debug|x64': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|x64': changing Platform Toolset to 'v142' (was 'v140').
Upgrading project 'tiffdiff'...
        Configuration 'Debug|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Debug|x64': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|x64': changing Platform Toolset to 'v142' (was 'v140').
Upgrading project 'lcms2_static'...
        Configuration 'Debug|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Debug|x64': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|x64': changing Platform Toolset to 'v142' (was 'v140').
Upgrading project 'psicc'...
        Configuration 'Debug|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Debug|x64': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|Win32': changing Platform Toolset to 'v142' (was 'v140').
        Configuration 'Release|x64': changing Platform Toolset to 'v142' (was 'v140').

Migration completed successfully, but some warnings were detected during migration.
For more information, see the migration report:
C:\Users\atevet\.conan\data\lcms\2.12\_\_\build\d4bb31912cc39810f01c804d7ba2f80b8bd35a3a\source_subfolder\Projects\VC2015\UpgradeLog.htm
Microsoft (R) Build Engine version 16.10.2+857e5a733 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Microsoft\VC\v160\Microsoft.Cpp.WindowsSDK.targets(46,5): error MSB8036: The Windows SDK version 8.1 was not found
. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". [C:\Users\atevet
\.conan\data\lcms\2.12\_\_\build\d4bb31912cc39810f01c804d7ba2f80b8bd35a3a\source_subfolder\Projects\VC2015\lcms2_static\lcms2_static.vcxproj]
lcms/2.12: 
lcms/2.12: ERROR: Package 'd4bb31912cc39810f01c804d7ba2f80b8bd35a3a' build failed
lcms/2.12: WARN: Build folder C:\Users\atevet\.conan\data\lcms\2.12\_\_\build\d4bb31912cc39810f01c804d7ba2f80b8bd35a3a
ERROR: lcms/2.12: Error in build() method, line 109
        self._build_visual_studio()
while calling '_build_visual_studio', line 82
        msbuild.build("lcms2.sln", targets=[target], platforms={"x86": "Win32"}, upgrade_project=upgrade_project, properties=properties)
        ConanException: Error 1 while executing set "VSCMD_START_DIR=%CD%" && call "C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC/Auxiliary/Build/vcvarsall.bat" x86 && devenv "lcms2.sln" /upgrade && msbuild "lcms2.sln" /p:Configuration="Release" /p:UseEnv=true /p:Platform="Win32" /m:4 /target:lcms2_static /p:PlatformToolset="v142" /verbosity:minimal /p:ForceImportBeforeCppTargets="C:\Users\atevet\.conan\data\lcms\2.12\_\_\build\d4bb31912cc39810f01c804d7ba2f80b8bd35a3a\source_subfolder\Projects\VC2015\conan_build.props" /p:WholeProgramOptimization="false"
```
</details>



Discussion:
I was able to resolve this locally by changing the recipe to use LCMS 2.12's VS2019 project when `self.settings.compiler.version` == 16, rather than using an upgraded VS2015 project.  I'll be submitting a PR for my change shortly after my access request is approved!

Resolving patch:
diff --git a/recipes/lcms/all/conanfile.py b/recipes/lcms/all/conanfile.py
--- a/recipes/lcms/all/conanfile.py
+++ b/recipes/lcms/all/conanfile.py
@@ -59,6 +59,10 @@ def _patch_sources(self):
             # since VS2015 vsnprintf is built-in
             path = os.path.join(self._source_subfolder, "src", "lcms2_internal.h")
             tools.replace_in_file(path, "#       define vsnprintf  _vsnprintf", "")
+        if self.settings.compiler == "Visual Studio" and Version(self.settings.compiler.version) >= "16":
+            # since VS2019, don't need to specify the WindowsTargetPlatformVersion
+            path = os.path.join(self._source_subfolder, "Projects", "VC2015", "lcms2_static", "lcms2_static.vcxproj")
+            tools.replace_in_file(path, "<WindowsTargetPlatformVersion>8.1</WindowsTargetPlatformVersion>", "")
         if self.settings.os == "Android" and tools.os_info.is_windows:
             # remove escape for quotation marks, to make ndk on windows happy
             tools.replace_in_file(os.path.join(self._source_subfolder, "configure"),


Test patch: