vcpkg: Fix usage with Visual C++ 2022

Visual Studio 2022 comes with their own vcpkg and sets the VCPKG_ROOT as
part of the 'vcvars.bat' environment.

This change makes sure that the 'vcpkg' program specified by the vcpkg
plugin is being used.

Change-Id: I582a54ed615a2ad8f47814736d4e6dddad9f50cd
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
This commit is contained in:
Cristian Adam
2024-09-19 17:28:04 +02:00
parent 0076ef4be6
commit 81bfc2f9f7
3 changed files with 12 additions and 1 deletions

View File

@@ -2086,6 +2086,13 @@ CMakeBuildSystem *CMakeBuildConfiguration::cmakeBuildSystem() const
void CMakeBuildConfiguration::addToEnvironment(Utils::Environment &env) const void CMakeBuildConfiguration::addToEnvironment(Utils::Environment &env) const
{ {
// Use the user provided VCPKG_ROOT if existing
// Visual C++ 2022 (and newer) come with their own VCPKG_ROOT
// that is incompatible with Qt Creator
const QString vcpkgRoot = qtcEnvironmentVariable(Constants::VCPKG_ROOT);
if (!vcpkgRoot.isEmpty())
env.set(Constants::VCPKG_ROOT, vcpkgRoot);
const CMakeTool *tool = CMakeKitAspect::cmakeTool(kit()); const CMakeTool *tool = CMakeKitAspect::cmakeTool(kit());
// The hack further down is only relevant for desktop // The hack further down is only relevant for desktop
if (tool && tool->cmakeExecutable().needsDevice()) if (tool && tool->cmakeExecutable().needsDevice())

View File

@@ -27,6 +27,7 @@ const char CMAKEFORMATTER_MENU_ID[] = "CMakeFormatter.Menu";
const char CMAKE_DEBUGGING_GROUP[] = "Debugger.Group.CMake"; const char CMAKE_DEBUGGING_GROUP[] = "Debugger.Group.CMake";
const char PACKAGE_MANAGER_DIR[] = ".qtc/package-manager"; const char PACKAGE_MANAGER_DIR[] = ".qtc/package-manager";
const char VCPKG_ROOT[] = "VCPKG_ROOT";
const char CMAKE_LISTS_TXT[] = "CMakeLists.txt"; const char CMAKE_LISTS_TXT[] = "CMakeLists.txt";
const char CMAKE_CACHE_TXT[] = "CMakeCache.txt"; const char CMAKE_CACHE_TXT[] = "CMakeCache.txt";

View File

@@ -199,7 +199,10 @@ macro(qtc_auto_setup_vcpkg)
if (EXISTS "${CMAKE_SOURCE_DIR}/vcpkg.json" AND NOT QT_CREATOR_SKIP_VCPKG_SETUP) if (EXISTS "${CMAKE_SOURCE_DIR}/vcpkg.json" AND NOT QT_CREATOR_SKIP_VCPKG_SETUP)
option(QT_CREATOR_SKIP_VCPKG_SETUP "Skip Qt Creator's vcpkg package manager auto-setup" OFF) option(QT_CREATOR_SKIP_VCPKG_SETUP "Skip Qt Creator's vcpkg package manager auto-setup" OFF)
find_program(vcpkg_program vcpkg $ENV{VCPKG_ROOT} ${CMAKE_SOURCE_DIR}/vcpkg) find_program(vcpkg_program vcpkg
PATHS $ENV{VCPKG_ROOT} ${CMAKE_SOURCE_DIR}/vcpkg
NO_DEFAULT_PATH
)
if (NOT vcpkg_program) if (NOT vcpkg_program)
message(WARNING "Qt Creator: vcpkg executable not found. " message(WARNING "Qt Creator: vcpkg executable not found. "
"Package manager auto-setup will be skipped. " "Package manager auto-setup will be skipped. "