Skip to content

Commit c7dbaf7

Browse files
authored
[cmake] honor $VCPKG_ROOT from env (#83003)
1 parent 42ece09 commit c7dbaf7

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

CMakePresets.json

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,6 @@
2424
"displayName": "Windows x64 MSVC",
2525
"description": "Target Windows (64-bit) with the Visual Studio development environment.",
2626
"generator": "Visual Studio 17 2022",
27-
"environment": {
28-
"VCPKG_ROOT": "C:/vcpkg"
29-
},
3027
"cacheVariables": {
3128
"DYNAMIC_LINKING": "False",
3229
"CURSES": "True", "LOCALIZE": "True", "TILES": "False", "SOUND": "False", "TESTS": "True",
@@ -55,9 +52,6 @@
5552
"description": "Target Windows (64-bit) with the Visual Studio development environment.",
5653
"generator": "Visual Studio 17 2022",
5754
"inherits": "windows-tiles-sounds-x64",
58-
"environment": {
59-
"VCPKG_ROOT": "C:/vcpkg"
60-
},
6155
"cacheVariables": {
6256
"CMAKE_PROJECT_INCLUDE_BEFORE": "${sourceDir}/build-scripts/${presetName}.cmake",
6357
"CMAKE_TOOLCHAIN_FILE": "${sourceDir}/build-scripts/MSVC.cmake",

build-scripts/MSVC.cmake

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,17 @@ set(CMAKE_MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")
8585
# Where is vcpkg.json ?
8686
set(VCPKG_MANIFEST_DIR ${CMAKE_SOURCE_DIR}/msvc-full-features)
8787

88-
set(VCPKG_ROOT "" CACHE PATH "Path to VCPKG installation")
89-
if (NOT $ENV{VCPKG_ROOT} STREQUAL "")
90-
include($ENV{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
91-
elseif(NOT $CACHE{VCPKG_ROOT} STREQUAL "")
92-
include($CACHE{VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake)
88+
set(VCPKG_ROOT "$ENV{VCPKG_ROOT}" CACHE PATH "Path to VCPKG installation")
89+
if(NOT VCPKG_ROOT)
90+
set(VCPKG_ROOT "C:/vcpkg" CACHE PATH "Path to VCPKG installation" FORCE)
9391
endif()
92+
93+
set(_vcpkg_toolchain "${VCPKG_ROOT}/scripts/buildsystems/vcpkg.cmake")
94+
if(NOT EXISTS "${_vcpkg_toolchain}")
95+
message(FATAL_ERROR
96+
"Could not find vcpkg toolchain file at:\n ${_vcpkg_toolchain}\n"
97+
"Check that VCPKG_ROOT points to a valid vcpkg checkout "
98+
"(it should contain scripts/buildsystems/vcpkg.cmake).")
99+
endif()
100+
101+
include("${_vcpkg_toolchain}")

0 commit comments

Comments
 (0)