From de1f4dffbac432f5142e63efa3cbe6a5a8b82f67 Mon Sep 17 00:00:00 2001 From: Rafael Kitover Date: Fri, 1 Dec 2023 09:54:51 +0000 Subject: [PATCH] build: prefer user vcpkg root over VS system-wide If the vcpkg clone exists in our preferred location, and VCPKG_ROOT has not been passed to the build system, use it over the Visual Studio default one, which is much more problematic. Signed-off-by: Rafael Kitover --- cmake/Set-Toolchain-vcpkg.cmake | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/cmake/Set-Toolchain-vcpkg.cmake b/cmake/Set-Toolchain-vcpkg.cmake index 8b4cf978..791593da 100644 --- a/cmake/Set-Toolchain-vcpkg.cmake +++ b/cmake/Set-Toolchain-vcpkg.cmake @@ -326,11 +326,16 @@ endfunction() function(vcpkg_set_toolchain) 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) set(VCPKG_ROOT /vcpkg) elseif(EXISTS c:/vcpkg) set(VCPKG_ROOT c:/vcpkg) + # Prefer the preferred root to the VS default which is more difficult to deal with, if it exists. + elseif(EXISTS "${preferred_root}") + set(VCPKG_ROOT "${preferred_root}") else() find_program(vcpkg_exe_path NAME vcpkg.exe HINTS ENV PATH) @@ -344,17 +349,17 @@ function(vcpkg_set_toolchain) endif() if(NOT DEFINED VCPKG_ROOT) - get_filename_component(VCPKG_ROOT ${CMAKE_SOURCE_DIR}/../vcpkg ABSOLUTE) + set(VCPKG_ROOT "${preferred_root}") endif() - set(ENV{VCPKG_ROOT} ${VCPKG_ROOT}) + set(ENV{VCPKG_ROOT} "${VCPKG_ROOT}") else() - set(VCPKG_ROOT $ENV{VCPKG_ROOT}) + set(VCPKG_ROOT "$ENV{VCPKG_ROOT}") endif() set(VCPKG_ROOT "${VCPKG_ROOT}" CACHE FILEPATH "vcpkg installation root path" FORCE) - if(NOT EXISTS ${VCPKG_ROOT}) + if(NOT EXISTS "${VCPKG_ROOT}") get_filename_component(root_parent ${VCPKG_ROOT}/.. ABSOLUTE) execute_process(