diff --git a/CMakePresets.json b/CMakePresets.json index 9cf870484f3..46891977589 100644 --- a/CMakePresets.json +++ b/CMakePresets.json @@ -24,9 +24,6 @@ "displayName": "Windows x64 MSVC", "description": "Target Windows (64-bit) with the Visual Studio development environment.", "generator": "Visual Studio 17 2022", - "environment": { - "VCPKG_ROOT": "C:/vcpkg" - }, "cacheVariables": { "DYNAMIC_LINKING": "False", "CURSES": "True", "LOCALIZE": "True", "TILES": "False", "SOUND": "False", "TESTS": "True", @@ -55,9 +52,6 @@ "description": "Target Windows (64-bit) with the Visual Studio development environment.", "generator": "Visual Studio 17 2022", "inherits": "windows-tiles-sounds-x64", - "environment": { - "VCPKG_ROOT": "C:/vcpkg" - }, "cacheVariables": { "CMAKE_PROJECT_INCLUDE_BEFORE": "${sourceDir}/build-scripts/${presetName}.cmake", "CMAKE_TOOLCHAIN_FILE": "${sourceDir}/build-scripts/MSVC.cmake", diff --git a/build-scripts/MSVC.cmake b/build-scripts/MSVC.cmake index 311e78645ac..782675af18b 100644 --- a/build-scripts/MSVC.cmake +++ b/build-scripts/MSVC.cmake @@ -85,9 +85,17 @@ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") # Where is vcpkg.json ? set(VCPKG_MANIFEST_DIR ${CMAKE_SOURCE_DIR}/msvc-full-features) -set(VCPKG_ROOT "" CACHE PATH "Path to VCPKG installation") -if (NOT $ENV{VCPKG_ROOT} STREQUAL "") - include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) -elseif(NOT $CACHE{VCPKG_ROOT} STREQUAL "") - include($CACHE{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake) +set(VCPKG_ROOT "$ENV{VCPKG_ROOT}" CACHE PATH "Path to VCPKG installation") +if(NOT VCPKG_ROOT) + set(VCPKG_ROOT "C:/vcpkg" CACHE PATH "Path to VCPKG installation" FORCE) endif() + +set(_vcpkg_toolchain "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake") +if(NOT EXISTS "${_vcpkg_toolchain}") + message(FATAL_ERROR + "Could not find vcpkg toolchain file at:\n ${_vcpkg_toolchain}\n" + "Check that VCPKG_ROOT points to a valid vcpkg checkout " + "(it should contain scripts/buildsystems/vcpkg.cmake).") +endif() + +include("${_vcpkg_toolchain}")