【问题标题】:set vcpkg x-buildtrees-root option in manifest or in cmakepresets.json在清单或 cmakepresets.json 中设置 vcpkg x-buildtrees-root 选项
【发布时间】:2022-12-03 20:09:36
【问题描述】:

我有一个 CMake 项目,使用 vcpkg.json 来使用 vcpkg,使用 CMakePresets.json 来设置 CMake 选项。

这是vcpkg.json

{
  "name": "myproj",
  "version": "1.0.0",
  "dependencies": [
    "boost",
    "qt"
  ]
}

这是CMakePresets.json

{
  "version": 3,
  "cmakeMinimumRequired": {
    "major": 3,
    "minor": 22,
    "patch": 1
  },
  "configurePresets": [
    {
      "name": "default",
      "displayName": "Default Config",
      "description": "Default config generator with ninja",
      "generator": "Ninja",
      "binaryDir": "${sourceDir}/build/${presetName}",
      "hidden": true,
      "cacheVariables": {
        "CMAKE_TOOLCHAIN_FILE": "e:/lib/vcpkg/scripts/buildsystems/vcpkg.cmake",
        "VCPKG_DEFAULT_TRIPLET": "x64-windows",
        "CMAKE_EXPORT_COMPILE_COMMANDS": "TRUE"
      },
      "environment": {
      }
    },
    {
      "inherits": "default",
      "name": "debug",
      "displayName": "Debug",
      "description": "Debug build.",
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Debug"
      }
    },
    {
      "inherits": "default",
      "name": "release",
      "displayName": "Release",
      "description": "Release build.",
      "cacheVariables": {
        "CMAKE_BUILD_TYPE": "Release"
      }
    }
  ],
  "buildPresets": [
    {
      "name": "Debug",
      "configurePreset": "debug"
    },
    {
      "name": "Release",
      "configurePreset": "release"
    }
  ],
  "testPresets": [
    {
      "name": "debugtest",
      "configurePreset": "debug",
      "output": {"outputOnFailure": true},
      "execution": {"noTestsAction": "error", "stopOnFailure": true}
    }
  ]
}

当我使用 Visual Studio 2022 打开项目文件夹时,它开始构建 vcpkg 库,一切顺利,直到它构建 qtwebengine,它返回一个错误:

1> [CMake] Installing 376/432 qtwebengine:x64-windows...
1> [CMake] Building qtwebengine[core,default-features,geolocation,spellchecker,webchannel]:x64-windows...
1> [CMake] -- Using cached pypa-get-pip-38e54e5de07c66e875c11a1ebbdb938854625dd8.tar.gz.
1> [CMake] -- Cleaning sources at E:/lib/vcpkg/buildtrees/qtwebengine/src/8854625dd8-861bd167bd.clean. Use --editable to skip cleaning for the packages you specify.
1> [CMake] -- Extracting source E:/lib/vcpkg/downloads/pypa-get-pip-38e54e5de07c66e875c11a1ebbdb938854625dd8.tar.gz
1> [CMake] -- Using source at E:/lib/vcpkg/buildtrees/qtwebengine/src/8854625dd8-861bd167bd.clean
1> [CMake] -- Setting up python virtual environmnent...
1> [CMake] -- Installing python packages: html5lib
1> [CMake] -- Setting up python virtual environmnent...finished.
1> [CMake] CMake Warning at ports/qtwebengine/portfile.cmake:85 (message):
1> [CMake]   Buildtree path 'E:/lib/vcpkg/buildtrees/qtwebengine' is too long.
1> [CMake] 
1> [CMake]   Consider passing --x-buildtrees-root=<shortpath> to vcpkg!
1> [CMake] 
1> [CMake]   Trying to use 'E:/lib/vcpkg/buildtrees/qtwebengine/../tmp'
1> [CMake] Call Stack (most recent call first):
1> [CMake]   scripts/ports.cmake:147 (include)
1> [CMake] 
1> [CMake] 
1> [CMake] CMake Error at ports/qtwebengine/portfile.cmake:90 (message):
1> [CMake]   Buildtree path is too long.  Build will fail! Pass
1> [CMake]   --x-buildtrees-root=<shortpath> to vcpkg!
1> [CMake] Call Stack (most recent call first):
1> [CMake]   scripts/ports.cmake:147 (include)
1> [CMake] error: building qtwebengine:x64-windows failed with: BUILD_FAILED
1> [CMake] error: Please ensure you're using the latest port files with `git pull` and `vcpkg update`.

基本上我需要在使用 vcpkg 构建库时设置 --x-buildtrees-root=&lt;shortpath&gt; 选项。我可以手动完成,但如何设置此选项以便在使用 Visual Studio 构建依赖项时自动调用?如何更新我的配置文件?

【问题讨论】:

    标签: c++ qt cmake vcpkg qtwebengine


    【解决方案1】:

    变量VCPKG_INSTALL_OPTIONS 用于将更多选项传递给vcpkg install。所以只需将其设置在您的预设中即可。

    【讨论】:

      最近更新 更多