Skip to content

Commit

Permalink
[vcpkg] Fix termination of vcpkg root search (microsoft#22694)
Browse files Browse the repository at this point in the history
* Fix termination of vpckg root search

* Apply CR suggestion

Co-authored-by: Vadim Peretokin <[email protected]>

Co-authored-by: Vadim Peretokin <[email protected]>
  • Loading branch information
dg0yt and vadi2 authored Jan 31, 2022
1 parent 5f9c75f commit 912bfa9
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions scripts/buildsystems/vcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -357,18 +357,23 @@ endif()
set(VCPKG_TARGET_TRIPLET "${Z_VCPKG_TARGET_TRIPLET_ARCH}-${Z_VCPKG_TARGET_TRIPLET_PLAT}" CACHE STRING "Vcpkg target triplet (ex. x86-windows)")
set(Z_VCPKG_TOOLCHAIN_DIR "${CMAKE_CURRENT_LIST_DIR}")

if(NOT DEFINED Z_VCPKG_ROOT_DIR)
# Detect .vcpkg-root to figure VCPKG_ROOT_DIR
set(Z_VCPKG_ROOT_DIR_CANDIDATE "${CMAKE_CURRENT_LIST_DIR}")
while(IS_DIRECTORY "${Z_VCPKG_ROOT_DIR_CANDIDATE}" AND NOT EXISTS "${Z_VCPKG_ROOT_DIR_CANDIDATE}/.vcpkg-root")
# Detect .vcpkg-root to figure VCPKG_ROOT_DIR
set(Z_VCPKG_ROOT_DIR_CANDIDATE "${CMAKE_CURRENT_LIST_DIR}")
while(NOT DEFINED Z_VCPKG_ROOT_DIR)
if(EXISTS "${Z_VCPKG_ROOT_DIR_CANDIDATE}/.vcpkg-root")
set(Z_VCPKG_ROOT_DIR "${Z_VCPKG_ROOT_DIR_CANDIDATE}" CACHE INTERNAL "Vcpkg root directory")
elseif(IS_DIRECTORY "${Z_VCPKG_ROOT_DIR_CANDIDATE}")
get_filename_component(Z_VCPKG_ROOT_DIR_TEMP "${Z_VCPKG_ROOT_DIR_CANDIDATE}" DIRECTORY)
if(Z_VCPKG_ROOT_DIR_TEMP STREQUAL Z_VCPKG_ROOT_DIR_CANDIDATE) # If unchanged, we have reached the root of the drive
else()
SET(Z_VCPKG_ROOT_DIR_CANDIDATE "${Z_VCPKG_ROOT_DIR_TEMP}")
if(Z_VCPKG_ROOT_DIR_TEMP STREQUAL Z_VCPKG_ROOT_DIR_CANDIDATE)
break() # If unchanged, we have reached the root of the drive without finding vcpkg.
endif()
endwhile()
set(Z_VCPKG_ROOT_DIR "${Z_VCPKG_ROOT_DIR_CANDIDATE}" CACHE INTERNAL "Vcpkg root directory")
endif()
SET(Z_VCPKG_ROOT_DIR_CANDIDATE "${Z_VCPKG_ROOT_DIR_TEMP}")
unset(Z_VCPKG_ROOT_DIR_TEMP)
else()
break()
endif()
endwhile()
unset(Z_VCPKG_ROOT_DIR_CANDIDATE)

if(NOT Z_VCPKG_ROOT_DIR)
z_vcpkg_add_fatal_error("Could not find .vcpkg-root")
Expand Down

0 comments on commit 912bfa9

Please sign in to comment.