microsoft / vcpkg

C++ Library Manager for Windows, Linux, and MacOS
MIT License
23.08k stars 6.36k forks source link

VCPKG_CMAKE_SYSTEM_VERSION not work. #41723

Open thegoodtgg opened 2 days ago

thegoodtgg commented 2 days ago

Describe the bug VCPKG_CMAKE_SYSTEM_VERSION not work.

Environment

To Reproduce Steps to reproduce the behavior: Use following triplet, install boost-headers 1.85.0

set(VCPKG_TARGET_ARCHITECTURE x64)
set(VCPKG_CRT_LINKAGE static)
set(VCPKG_LIBRARY_LINKAGE static)
set(VCPKG_LOAD_VCVARS_ENV ON)
set(VCPKG_VISUAL_STUDIO_PATH "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community")
set(VCPKG_ENV_PASSTHROUGH WindowsSDKVersion)
set(VCPKG_CMAKE_SYSTEM_VERSION "10.0.22000.0")
set(WindowsSDKVersion "10.0.22000.0")
# WindowsSDKVersion and VCPKG_VMAKE_SYSTEM_VERSION not work
set(VCPKG_PLATFORM_TOOLSET "v142")
set(VCPKG_PLATFORM_TOOLSET_VERSION "14.29.30133")
  1. See error Repro code when

Expected behavior A clear and concise description of what you expected to happen.

Failure logs

[1/1] "F:/vcpkg/downloads/tools/cmake-3.30.1-windows/cmake-3.30.1-windows-i386/bin/cmake.exe" -E chdir ".." "F:/vcpkg/downloads/tools/cmake-3.30.1-windows/cmake-3.30.1-windows-i386/bin/cmake.exe" "C:/vcpkg/buildtrees/boost-headers/src/ost-1.85.0-f4cb877742.clean" "-G" "Ninja" "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=C:/vcpkg/packages/boost-headers_x64-windows-static-su" "-DFETCHCONTENT_FULLY_DISCONNECTED=ON" "-DBOOST_INCLUDE_LIBRARIES=headers" "-DBOOST_RUNTIME_LINK=static" "-DBOOST_INSTALL_INCLUDE_SUBDIR=" "-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=" "-DCMAKE_MAKE_PROGRAM=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe" "-DBUILD_SHARED_LIBS=OFF" "-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=D:/gitlab/runner/builds/WsKsEyi3/0/d5lightening/lighteningclient/external/dcc/sketchup/scripts/vcpkg/triplets/x64-windows-static-su-toolchain.cmake" "-DVCPKG_TARGET_TRIPLET=x64-windows-static-su" "-DVCPKG_SET_CHARSET_FLAG=ON" "-DVCPKG_PLATFORM_TOOLSET=v142" "-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON" "-DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON" "-DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON" "-DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=TRUE" "-DCMAKE_VERBOSE_MAKEFILE=ON" "-DVCPKG_APPLOCAL_DEPS=OFF" "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" "-DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON" "-DVCPKG_CXX_FLAGS=" "-DVCPKG_CXX_FLAGS_RELEASE=" "-DVCPKG_CXX_FLAGS_DEBUG=" "-DVCPKG_C_FLAGS=" "-DVCPKG_C_FLAGS_RELEASE=" "-DVCPKG_C_FLAGS_DEBUG=" "-DVCPKG_CRT_LINKAGE=static" "-DVCPKG_LINKER_FLAGS=" "-DVCPKG_LINKER_FLAGS_RELEASE=" "-DVCPKG_LINKER_FLAGS_DEBUG=" "-DVCPKG_TARGET_ARCHITECTURE=x64" "-DCMAKE_INSTALL_LIBDIR:STRING=lib" "-DCMAKE_INSTALL_BINDIR:STRING=bin" "-D_VCPKG_ROOT_DIR=C:/vcpkg" "-D_VCPKG_INSTALLED_DIR=D:/gitlab/runner/builds/WsKsEyi3/0/d5lightening/lighteningclient/.circleci/build/su" "-DVCPKG_MANIFEST_INSTALL=OFF"
FAILED: ../CMakeCache.txt 
"F:/vcpkg/downloads/tools/cmake-3.30.1-windows/cmake-3.30.1-windows-i386/bin/cmake.exe" -E chdir ".." "F:/vcpkg/downloads/tools/cmake-3.30.1-windows/cmake-3.30.1-windows-i386/bin/cmake.exe" "C:/vcpkg/buildtrees/boost-headers/src/ost-1.85.0-f4cb877742.clean" "-G" "Ninja" "-DCMAKE_BUILD_TYPE=Release" "-DCMAKE_INSTALL_PREFIX=C:/vcpkg/packages/boost-headers_x64-windows-static-su" "-DFETCHCONTENT_FULLY_DISCONNECTED=ON" "-DBOOST_INCLUDE_LIBRARIES=headers" "-DBOOST_RUNTIME_LINK=static" "-DBOOST_INSTALL_INCLUDE_SUBDIR=" "-DCMAKE_MSVC_DEBUG_INFORMATION_FORMAT=" "-DCMAKE_MAKE_PROGRAM=C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe" "-DBUILD_SHARED_LIBS=OFF" "-DVCPKG_CHAINLOAD_TOOLCHAIN_FILE=D:/gitlab/runner/builds/WsKsEyi3/0/d5lightening/lighteningclient/external/dcc/sketchup/scripts/vcpkg/triplets/x64-windows-static-su-toolchain.cmake" "-DVCPKG_TARGET_TRIPLET=x64-windows-static-su" "-DVCPKG_SET_CHARSET_FLAG=ON" "-DVCPKG_PLATFORM_TOOLSET=v142" "-DCMAKE_EXPORT_NO_PACKAGE_REGISTRY=ON" "-DCMAKE_FIND_PACKAGE_NO_PACKAGE_REGISTRY=ON" "-DCMAKE_FIND_PACKAGE_NO_SYSTEM_PACKAGE_REGISTRY=ON" "-DCMAKE_INSTALL_SYSTEM_RUNTIME_LIBS_SKIP=TRUE" "-DCMAKE_VERBOSE_MAKEFILE=ON" "-DVCPKG_APPLOCAL_DEPS=OFF" "-DCMAKE_TOOLCHAIN_FILE=C:/vcpkg/scripts/buildsystems/vcpkg.cmake" "-DCMAKE_ERROR_ON_ABSOLUTE_INSTALL_DESTINATION=ON" "-DVCPKG_CXX_FLAGS=" "-DVCPKG_CXX_FLAGS_RELEASE=" "-DVCPKG_CXX_FLAGS_DEBUG=" "-DVCPKG_C_FLAGS=" "-DVCPKG_C_FLAGS_RELEASE=" "-DVCPKG_C_FLAGS_DEBUG=" "-DVCPKG_CRT_LINKAGE=static" "-DVCPKG_LINKER_FLAGS=" "-DVCPKG_LINKER_FLAGS_RELEASE=" "-DVCPKG_LINKER_FLAGS_DEBUG=" "-DVCPKG_TARGET_ARCHITECTURE=x64" "-DCMAKE_INSTALL_LIBDIR:STRING=lib" "-DCMAKE_INSTALL_BINDIR:STRING=bin" "-D_VCPKG_ROOT_DIR=C:/vcpkg" "-D_VCPKG_INSTALLED_DIR=D:/gitlab/runner/builds/WsKsEyi3/0/d5lightening/lighteningclient/.circleci/build/su" "-DVCPKG_MANIFEST_INSTALL=OFF"
-- The CXX compiler identification is MSVC 19.29.30156.0
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - failed
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe - broken
CMake Error at F:/vcpkg/downloads/tools/cmake-3.30.1-windows/cmake-3.30.1-windows-i386/share/cmake-3.30/Modules/CMakeTestCXXCompiler.cmake:73 (message):
  The C++ compiler

    "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.29.30133/bin/Hostx64/x64/cl.exe"

  is not able to compile a simple test program.

  It fails with the following output:

    Change Dir: 'C:/vcpkg/buildtrees/boost-headers/x64-windows-static-su-rel/CMakeFiles/CMakeScratch/TryCompile-g6hkr6'

    Run Build Command(s): "C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/IDE/CommonExtensions/Microsoft/CMake/Ninja/ninja.exe" -v cmTC_cb45f
    [1/2] C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\cl.exe  /nologo /TP   /nologo /DWIN32 /D_WINDOWS /utf-8 /GR /EHsc /MP   /D_DEBUG /MTd /Z7 /Ob0 /Od /RTC1  -MTd /showIncludes /FoCMakeFiles\cmTC_cb45f.dir\testCXXCompiler.cxx.obj /FdCMakeFiles\cmTC_cb45f.dir\ /FS -c C:\vcpkg\buildtrees\boost-headers\x64-windows-static-su-rel\CMakeFiles\CMakeScratch\TryCompile-g6hkr6\testCXXCompiler.cxx
    [2/2] C:\WINDOWS\system32\cmd.exe /C "cd . && F:\vcpkg\downloads\tools\cmake-3.30.1-windows\cmake-3.30.1-windows-i386\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_cb45f.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_cb45f.dir\testCXXCompiler.cxx.obj  /out:cmTC_cb45f.exe /implib:cmTC_cb45f.lib /pdb:cmTC_cb45f.pdb /version:0.0 /machine:x64  /nologo    /debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
    FAILED: cmTC_cb45f.exe 
    C:\WINDOWS\system32\cmd.exe /C "cd . && F:\vcpkg\downloads\tools\cmake-3.30.1-windows\cmake-3.30.1-windows-i386\bin\cmake.exe -E vs_link_exe --intdir=CMakeFiles\cmTC_cb45f.dir --rc=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\rc.exe --mt=C:\PROGRA~2\WI3CF2~1\10\bin\100261~1.0\x64\mt.exe --manifests  -- C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_cb45f.dir\testCXXCompiler.cxx.obj  /out:cmTC_cb45f.exe /implib:cmTC_cb45f.lib /pdb:cmTC_cb45f.pdb /version:0.0 /machine:x64  /nologo    /debug /INCREMENTAL /subsystem:console  kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib && cd ."
    LINK Pass 1: command "C:\PROGRA~2\MICROS~2\2019\COMMUN~1\VC\Tools\MSVC\1429~1.301\bin\Hostx64\x64\link.exe /nologo CMakeFiles\cmTC_cb45f.dir\testCXXCompiler.cxx.obj /out:cmTC_cb45f.exe /implib:cmTC_cb45f.lib /pdb:cmTC_cb45f.pdb /version:0.0 /machine:x64 /nologo /debug /INCREMENTAL /subsystem:console kernel32.lib user32.lib gdi32.lib winspool.lib shell32.lib ole32.lib oleaut32.lib uuid.lib comdlg32.lib advapi32.lib /MANIFEST /MANIFESTFILE:CMakeFiles\cmTC_cb45f.dir/intermediate.manifest CMakeFiles\cmTC_cb45f.dir/manifest.res" failed (exit code 1120) with the following output:
    libucrtd.lib(checkcfg.obj) : error LNK2001: 无法解析的外部符号 _guard_check_icall_$fo$
    cmTC_cb45f.exe : fatal error LNK1120: 1 个无法解析的外部命令
    ninja: build stopped: subcommand failed.

  CMake will not be able to correctly generate this project.
Call Stack (most recent call first):
  CMakeLists.txt:3 (project)

-- Configuring incomplete, errors occurred!
ninja: build stopped: subcommand failed.

Additional context I run into the problem recently. The problem is related to "WindowsSDKVersion". When using "Visual Studio 17 2022" with toolset "v142", "WindowsSDKVersion" must under "10.0.22xxx.0", or CMake would get a error while configure. Environment: Visual Studio 2022 17.11.5 and WindowSDKVersion "10.0.26100.0" Found a issue from poco repo: unresolved external symbol _guard_checkicall$fo$ And another related issue from STL: VCRuntime incompatibility with older version in mutex code, which cause me can't using v143 toolset and WindowSDKVersion "10.0.26100.0" config-x64-windows-static-su-out.log config-x64-windows-static-su-rel-CMakeCache.txt.log config-x64-windows-static-su-rel-CMakeConfigureLog.yaml.log

And when I run command "vcpkg env", I get following output:

Microsoft Windows [Version 10.0.22631.4317]
(c) Microsoft Corporation. All rights reserved.

I read the doc about vcpkg env. Is there any method to override WindowsSDKVersion. I try to use VCPKG_CHAINLOAD_TOOLCHAIN_FILE with a different toolchain file, however don't know how to make it work. @jimwang118

thegoodtgg commented 2 days ago

After some digging, I found "vcpkg.exe" run "vcvarsall.bat" no "Windows SDK Version " specified.

thegoodtgg commented 2 days ago

Found a existed issue from vcpkg-tool: vcpkg-tool Window SDK Version Triplet Variable. I found it 0001-fix-repest-to-VCPKG_CMAKE_SYSTEM_VERSION.patch easy when using the value of VCPKG_CMAKE_SYSTEM_VERSION as the target passed to "vcvarsall.bat" instead of empty value.

From fe3de4081e046b70ee4e5ff6c5e99533bf7b99e6 Mon Sep 17 00:00:00 2001
From: tgg <thegoodtgg@outlook.com>
Date: Wed, 23 Oct 2024 15:28:43 +0800
Subject: [PATCH] fix: repest to VCPKG_CMAKE_SYSTEM_VERSION.

---
 src/vcpkg/commands.build.cpp | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/src/vcpkg/commands.build.cpp b/src/vcpkg/commands.build.cpp
index d1a8a8d4..6c694782 100644
--- a/src/vcpkg/commands.build.cpp
+++ b/src/vcpkg/commands.build.cpp
@@ -311,10 +311,10 @@ namespace vcpkg
     }

 #if defined(_WIN32)
-    static ZStringView to_vcvarsall_target(StringView cmake_system_name)
+    static ZStringView to_vcvarsall_target(StringView cmake_system_name, StringView cmake_system_version)
     {
-        if (cmake_system_name.empty()) return "";
-        if (cmake_system_name == "Windows") return "";
+        if (cmake_system_name.empty()) return { cmake_system_version.data(), cmake_system_version.size() };
+        if (cmake_system_name == "Windows") return { cmake_system_version.data(), cmake_system_version.size()};
         if (cmake_system_name == "WindowsStore") return "store";

         Checks::msg_exit_with_error(VCPKG_LINE_INFO, msgUnsupportedSystemName, msg::system_name = cmake_system_name);
@@ -597,7 +597,7 @@ namespace vcpkg
         }

         const auto arch = to_vcvarsall_toolchain(pre_build_info.target_architecture, toolset, pre_build_info.triplet);
-        const auto target = to_vcvarsall_target(pre_build_info.cmake_system_name);
+        const auto target = to_vcvarsall_target(pre_build_info.cmake_system_name, pre_build_info.cmake_system_version);

         return vcpkg::Command{"cmd"}.string_arg("/d").string_arg("/c").raw_arg(
             fmt::format(R"("{}" {} {} {} {} 2>&1 <NUL)",
-- 
2.41.0.windows.1