xmake-io / xmake

🔥 A cross-platform build utility based on Lua
https://xmake.io
Apache License 2.0
9.87k stars 776 forks source link

在vs2022环境下面使用package.tools.cmake的生成的命令无法正确编译 #5230

Closed augustheart closed 3 months ago

augustheart commented 3 months ago

Xmake Version

2.9.2

Operating System Version and Architecture

Windows 11 家庭版 23H32

Describe Bug

在vs2022环境下面使用package.tools.cmake生成的命令无法正确编译

Expected Behavior

通过xmake调用cmake编译,具体来说是wxwidgets。

import("package.tools.cmake").install(package, cfg)

在vs2022下面出现奇怪的错误。

checking for ping ... ok
pinging the host(github.com) ... 99 ms
C:\xmake\winenv\bin\7z x -y wxWidgets-3.2.5.7z -osource.tmp

7-Zip 19.00 (x64) : Copyright (c) 1999-2018 Igor Pavlov : 2019-02-21

Scanning the drive for archives:
1 file, 22587311 bytes (22 MiB)

Extracting archive: wxWidgets-3.2.5.7z
--
Path = wxWidgets-3.2.5.7z
Type = 7z
Physical Size = 22587311
Headers Size = 89137
Method = Delta LZMA2:24
Solid = +
Blocks = 4

Everything is Ok

Folders: 526
Files: 8429
Size:       184657016
Compressed: 22587311
checking for cmake ... ok
checking for link.exe ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\link.exe
checking for the static library archiver (ar) ... link.exe
checking for link.exe ... C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.40.33807\bin\HostX64\x64\link.exe
checking for the shared library linker (sh) ... link.exe
cmake -DwxBUILD_MONOLITHIC=ON -DwxBUILD_SHARED=OFF -DCMAKE_INSTALL_PREFIX=C:\Users\gbgba\AppData\Local\.xmake\packages\w\wx\3.2.5\023350d85b1e4ae49c152d17372a023d -DCMAKE_INSTALL_LIBDIR:PATH=lib -G "Visual Studio 17 2022" -A x64 -DCMAKE_GENERATOR_TOOLSET=v144 -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=pdb -DCMAKE_POSITION_INDEPENDENT_CODE=ON "-DCMAKE_STATIC_LINKER_FLAGS_RELEASE=  -nodefaultlib:msvcrt.lib" "-DCMAKE_C_FLAGS_RELEASE=  -MT" "-DCMAKE_CXX_FLAGS_RELEASE=  -MT" "-DCMAKE_SHARED_LINKER_FLAGS_RELEASE=  -nodefaultlib:msvcrt.lib" "-DCMAKE_EXE_LINKER_FLAGS_RELEASE=  -nodefaultlib:msvcrt.lib" C:\Users\gbgba\AppData\Local\.xmake\cache\packages\2406\w\wx\3.2.5\source
CMake Deprecation Warning at CMakeLists.txt:10 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
CMake Error at CMakeLists.txt:98 (project):
  Failed to run MSBuild command:

    C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe

  to get the value of VCTargetsPath:

    閫傜敤浜?.NET Framework MSBuild 鐗堟湰 17.10.4+10fbfbf2e
    鐢熸垚鍚姩鏃堕棿涓?2024/6/19 7:03:22銆?

    鑺傜偣 1 涓婄殑椤圭洰鈥淐:\Users\gbgba\AppData\Local\.xmake\cache\packages\2406\w\wx\3.2.5\source\build_023350d8\CMakeFiles\3.29.3\VCTargetsPath.vcxproj鈥?榛樿鐩爣)銆?
    C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(456,5): error MSB8020: 鏃犳硶鎵惧埌 v144 鐨勭敓鎴愬伐鍏?骞冲彴宸ュ叿闆?=鈥渧144鈥?銆傝嫢瑕佷娇鐢?v144 鐢熸垚宸ュ叿杩涜鐢熸垚锛岃瀹夎 v144 鐢熸垚宸ュ叿銆傛垨鑰咃紝鍙互鍗囩骇鍒板綋鍓?Visual Studio 宸ュ叿锛屾柟寮忔槸閫氳繃閫夋嫨鈥滈」鐩€濊彍鍗曟垨鍙抽敭鍗曞嚮璇ヨВ鍐虫柟妗堬紝鐒跺悗閫夋嫨鈥滈噸瀹氳В鍐虫柟妗堢洰鏍団€濄€?[C:\Users\gbgba\AppData\Local\.xmake\cache\packages\2406\w\wx\3.2.5\source\build_023350d8\CMakeFiles\3.29.3\VCTargetsPath.vcxproj]
    宸插畬鎴愮敓鎴愰」鐩€淐:\Users\gbgba\AppData\Local\.xmake\cache\packages\2406\w\wx\3.2.5\source\build_023350d8\CMakeFiles\3.29.3\VCTargetsPath.vcxproj鈥?榛樿鐩爣)鐨勬搷浣?- 澶辫触銆?

    鐢熸垚澶辫触銆?

    鈥淐:\Users\gbgba\AppData\Local\.xmake\cache\packages\2406\w\wx\3.2.5\source\build_023350d8\CMakeFiles\3.29.3\VCTargetsPath.vcxproj鈥?榛樿鐩爣) (1) ->
    (PrepareForBuild 鐩爣) ->
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(456,5): error MSB8020: 鏃犳硶鎵惧埌 v144 鐨勭敓鎴愬伐鍏?骞冲彴宸ュ叿闆?=鈥渧144鈥?銆傝嫢瑕佷娇鐢?v144 鐢熸垚宸ュ叿杩涜鐢熸垚锛岃瀹夎 v144 鐢熸垚宸ュ叿銆傛垨鑰咃紝鍙互鍗囩骇鍒板綋鍓?Visual Studio 宸ュ叿锛屾柟寮忔槸閫氳繃閫夋嫨鈥滈」鐩€濊彍鍗曟垨鍙抽敭鍗曞嚮璇ヨВ鍐虫柟妗堬紝鐒跺悗閫夋嫨鈥滈噸瀹氳В鍐虫柟妗堢洰鏍団€濄€?[C:\Users\gbgba\AppData\Local\.xmake\cache\packages\2406\w\wx\3.2.5\source\build_023350d8\CMakeFiles\3.29.3\VCTargetsPath.vcxproj]

        0 涓鍛?
        1 涓敊璇?

    宸茬敤鏃堕棿 00:00:00.20

  Exit code: 1

-- Configuring incomplete, errors occurred!
error: execv(cmake -DwxBUILD_MONOLITHIC=ON -DwxBUILD_SHARED=OFF -DCMAKE_INSTALL_PREFIX=C:\Users\gbgba\AppData\Local\.xmake\packages\w\wx\3.2.5\023350d85b1e4ae49c152d17372a023d -DCMAKE_INSTALL_LIBDIR:PATH=lib -G "Visual Studio 17 2022" -A x64 -DCMAKE_GENERATOR_TOOLSET=v144 -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded -DCMAKE_COMPILE_PDB_OUTPUT_DIRECTORY=pdb -DCMAKE_POSITION_INDEPENDENT_CODE=ON "-DCMAKE_STATIC_LINKER_FLAGS_RELEASE=  -nodefaultlib:msvcrt.lib" "-DCMAKE_C_FLAGS_RELEASE=  -MT" "-DCMAKE_CXX_FLAGS_RELEASE=  -MT" "-DCMAKE_SHARED_LINKER_FLAGS_RELEASE=  -nodefaultlib:msvcrt.lib" "-DCMAKE_EXE_LINKER_FLAGS_RELEASE=  -nodefaultlib:msvcrt.lib" C:\Users\gbgba\AppData\Local\.xmake\cache\packages\2406\w\wx\3.2.5\source) failed(1)
  => install wx 3.2.5 .. failed
error: install failed!

考虑到,我已经在同样的环境下面使用cmake事先编译过了。大概问题出在不同的cmake参数上? 我自己直接调用cmake的参数为:

cmake -B build_vc -DwxBUILD_MONOLITHIC=ON -DwBUILD_SHARED=OFF 

这个命令行通过vs的命令行环境是能够直接执行的。 但是xmake生成的命令行多了很多东西,直接复制xmake生成的命令行一样不能正常构建。确切说就在于

-DCMAKE_GENERATOR_TOOLSET=v144

这句。然后,现在最新的vs也只是143,这个v144哪来的? 使用v143是能够成功编译的

C:\Users\gbgba\AppData\Local\.xmake\cache\packages\2406\w\wx\3.2.5\wxWidgets-3.2.5>cmake -B build_vc -DwxBUILD_MONOLITHIC=ON -DwxBUILD_SHARED=OFF -DCMAKE_INSTALL_PREFIX=C:\Users\gbgba\AppData\Local\.xmake\packages\w\wx\3.2.5\023350d85b1e4ae49c152d17372a023d -DCMAKE_INSTALL_LIBDIR:PATH=lib -G "Visual Studio 17 2022" -A x64 -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded --fresh -DCMAKE_GENERATOR_TOOLSET=v143
CMake Deprecation Warning at CMakeLists.txt:10 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
-- The C compiler identification is MSVC 19.40.33811.0
-- The CXX compiler identification is MSVC 19.40.33811.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.40.33807/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
^C

另外,xmake编译过程中出现了乱码,但是同样vs的命令行下,直接调用cmake是正确的显示。

C:\Users\gbgba\AppData\Local\.xmake\cache\packages\2406\w\wx\3.2.5\wxWidgets-3.2.5>cmake -B build_vc -DwxBUILD_MONOLITHIC=ON -DwxBUILD_SHARED=OFF -DCMAKE_INSTALL_PREFIX=C:\Users\gbgba\AppData\Local\.xmake\packages\w\wx\3.2.5\023350d85b1e4ae49c152d17372a023d -DCMAKE_INSTALL_LIBDIR:PATH=lib -G "Visual Studio 17 2022" -A x64 -DCMAKE_MSVC_RUNTIME_LIBRARY=MultiThreaded --fresh -DCMAKE_GENERATOR_TOOLSET=v144
CMake Deprecation Warning at CMakeLists.txt:10 (cmake_minimum_required):
  Compatibility with CMake < 3.5 will be removed from a future version of
  CMake.

  Update the VERSION argument <min> value or use a ...<max> suffix to tell
  CMake that the project does not need compatibility with older versions.

-- Selecting Windows SDK version 10.0.22621.0 to target Windows 10.0.22631.
CMake Error at CMakeLists.txt:98 (project):
  Failed to run MSBuild command:

    C:/Program Files/Microsoft Visual Studio/2022/Community/MSBuild/Current/Bin/amd64/MSBuild.exe

  to get the value of VCTargetsPath:

    适用于 .NET Framework MSBuild 版本 17.10.4+10fbfbf2e
    生成启动时间为 2024/6/19 7:15:11。

    节点 1 上的项目“C:\Users\gbgba\AppData\Local\.xmake\cache\packages\2406\w\wx\3.2.5\wxWidgets-3.2.5\build_vc\CMakeFiles\3.29.3\VCTargetsPath.vcxproj”(默认目标)。
    C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(456,5): error MSB8020: 无法找到 v144 的生成工具(平台工具集 =“v144”)。若要使用 v144 生成工具进行生成,请安装 v144 生成工具。或者,可以升级到当前 Visual Studio 工具,方式是通过选择“项目”菜单或右键单击该解决方案,然后选择“重定解决方案目标”。 [C:\Users\gbgba\AppData\Local\.xmake\cache\packages\2406\w\wx\3.2.5\wxWidgets-3.2.5\build_vc\CMakeFiles\3.29.3\VCTargetsPath.vcxproj]
    已完成生成项目“C:\Users\gbgba\AppData\Local\.xmake\cache\packages\2406\w\wx\3.2.5\wxWidgets-3.2.5\build_vc\CMakeFiles\3.29.3\VCTargetsPath.vcxproj”(默认目标)的操作 - 失败。

    生成失败。

    “C:\Users\gbgba\AppData\Local\.xmake\cache\packages\2406\w\wx\3.2.5\wxWidgets-3.2.5\build_vc\CMakeFiles\3.29.3\VCTargetsPath.vcxproj”(默认目标) (1) ->
    (PrepareForBuild 目标) ->
      C:\Program Files\Microsoft Visual Studio\2022\Community\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(456,5): error MSB8020: 无法找到 v144 的生成工具(平台工具集 =“v144”)。若要使用 v144 生成工具进行生成,请安装 v144 生成工具。或者,可以升级到当前 Visual Studio 工具,方式是通过选择“项目”菜单或右键单击该解决方案,然后选择“重定解决方案目标”。 [C:\Users\gbgba\AppData\Local\.xmake\cache\packages\2406\w\wx\3.2.5\wxWidgets-3.2.5\build_vc\CMakeFiles\3.29.3\VCTargetsPath.vcxproj]

        0 个警告
        1 个错误

    已用时间 00:00:00.17

  Exit code: 1

-- Configuring incomplete, errors occurred!

Project Configuration

-

Additional Information and Error Logs

-

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


Title: The command generated using package.tools.cmake under the vs2022 environment cannot be compiled correctly.

star-hengxing commented 3 months ago

https://github.com/xmake-io/xmake/issues/4772

augustheart commented 3 months ago

由于是早上上班之前匆忙写的issue,没有发现已经有老外开了。 我个人的理解是,-DCMAKE_GENERATOR_TOOLSET=v144这个东西不需要传,-G已经足够了

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


Since I wrote the issue in a hurry before going to work in the morning, I didn’t find that a foreigner had already opened it. My personal understanding is that -DCMAKE_GENERATOR_TOOLSET=v144 does not need to be passed, -G is enough

waruqi commented 3 months ago

由于是早上上班之前匆忙写的issue,没有发现已经有老外开了。 我个人的理解是,-DCMAKE_GENERATOR_TOOLSET=v144这个东西不需要传,-G已经足够了

需要同步 xmake 的配置,外面有可能会 xmake f --vs_toolset=xx 去改写 toolset 的。。另外,即使默认,cmake 探测 v144 也是有问题的,这是 msvc 的坑,尽管 cmake 新版本内部也对 v144 也做了兼容,但是之前我看他们也仅仅处理了 14.40 。。但是最新的 msvc preview 已经到 14.41 了。。

也就是说,如果用户没用最新 cmake 版本,或者 cmake 没有及时更新适配。。即使 xmake 不传 toolset ,cmake 里面照样得跪,传了,反而不仅能同步 xmake 所有配置,还是保证即使 cmake 是低版本,也照样没这问题。。只要你保证 xmake 版本最新。

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


Since I wrote the issue in a hurry before going to work in the morning, I didn’t find that a foreigner had already opened it. My personal understanding is that -DCMAKE_GENERATOR_TOOLSET=v144 does not need to be passed, -G is enough

It is necessary to synchronize the configuration of xmake. It is possible to use xmake f --vs_toolset=xx to rewrite the toolset from outside. . In addition, even by default, there is a problem with cmake detecting v144. This is a pitfall of msvc. Although the new version of cmake is also internally compatible with v144, I saw that they only dealt with 14.40 before. . But the latest msvc preview is already 14.41. .

In other words, if the user is not using the latest cmake version, or cmake is not updated and adapted in time. . Even if xmake does not pass the toolset, cmake still has to kneel down and pass it. On the contrary, it can not only synchronize all xmake configurations, but also ensure that cmake is a lower version, and there will still be no such problem. . As long as you keep the xmake version up to date.

augustheart commented 3 months ago

了解,我知道你的顾忌之处了。我自己先捣鼓一会吧

Issues-translate-bot commented 3 months ago

Bot detected the issue body's language is not English, translate it automatically.


Got it, I understand your concerns. I'll tinker with it myself for a while.