build: avoid using VS vcpkg with elevation

Always use a parallel vcpkg directory instead of the Visual Studio
default vcpkg, because installing there requires elevation and doesn't
always work.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2025-06-22 17:26:15 +00:00
parent 48fc076cc2
commit 61be54d3d9
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
1 changed files with 8 additions and 1 deletions

View File

@ -355,11 +355,12 @@ function(vcpkg_remove_optional_deps vcpkg_exe)
endfunction()
function(vcpkg_set_toolchain)
get_filename_component(preferred_root ${CMAKE_SOURCE_DIR}/../vcpkg ABSOLUTE)
if(NOT DEFINED POWERSHELL)
message(FATAL_ERROR "Powershell is required to use vcpkg binaries.")
endif()
if(NOT DEFINED ENV{VCPKG_ROOT})
get_filename_component(preferred_root ${CMAKE_SOURCE_DIR}/../vcpkg ABSOLUTE)
if(WIN32)
if(DEFINED ENV{CI} OR EXISTS /vcpkg)
@ -390,6 +391,12 @@ function(vcpkg_set_toolchain)
set(VCPKG_ROOT $ENV{VCPKG_ROOT})
endif()
# Avoid using Visual Studio default vcpkg, because that requires elevaction.
if(VCPKG_ROOT MATCHES "Visual Studio")
set(VCPKG_ROOT "${preferred_root}")
set(ENV{VCPKG_ROOT} ${VCPKG_ROOT})
endif()
set(VCPKG_ROOT ${VCPKG_ROOT} CACHE FILEPATH "vcpkg installation root path" FORCE)
if(NOT EXISTS ${VCPKG_ROOT})