[vcpkg.cmake] Setup CMAKE_PROGRAM_PATH for the host if possible (#23322)

* Use host tools by default.

* use GLOB_RECURSE and filter the result

* be positiv ;)

* give me debug output

* Revert "give me debug output"

This reverts commit 17737bceda8ed0dbe1a60c2fd831a55e53707dcd.

* remove unnecessary if(IS_DIRECTORY)

Co-authored-by: Alexander Neumann <you@example.com>
This commit is contained in:
Alexander Neumann 2022-03-04 23:16:47 +01:00 committed by GitHub
parent b44c4dd0e2
commit bd602277bf
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -517,13 +517,26 @@ if(VCPKG_MANIFEST_MODE AND VCPKG_MANIFEST_INSTALL AND NOT Z_VCPKG_CMAKE_IN_TRY_C
endif()
endif()
list(APPEND CMAKE_PROGRAM_PATH "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/tools")
file(GLOB Z_VCPKG_TOOLS_DIRS "${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/tools/*")
foreach(Z_VCPKG_TOOLS_DIR IN LISTS Z_VCPKG_TOOLS_DIRS)
if(IS_DIRECTORY "${Z_VCPKG_TOOLS_DIR}")
list(APPEND CMAKE_PROGRAM_PATH "${Z_VCPKG_TOOLS_DIR}")
option(VCPKG_SETUP_CMAKE_PROGRAM_PATH "Enable the setup of CMAKE_PROGRAM_PATH to vcpkg paths" ON)
cmake_dependent_option(VCPKG_USE_HOST_TOOLS "Setup CMAKE_PROGRAM_PATH to use host tools" ON "NOT VCPKG_HOST_TRIPLET STREQUAL \"\"" OFF)
if(VCPKG_SETUP_CMAKE_PROGRAM_PATH)
set(tools_base_path "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/tools")
if(VCPKG_USE_HOST_TOOLS)
set(tools_base_path "${VCPKG_INSTALLED_DIR}/${VCPKG_HOST_TRIPLET}/tools")
endif()
endforeach()
list(APPEND CMAKE_PROGRAM_PATH "${tools_base_path}")
file(GLOB_RECURSE Z_VCPKG_TOOLS_DIRS "${tools_base_path}/*")
file(GLOB_RECURSE Z_VCPKG_TOOLS_FILES LIST_DIRECTORIES false "${tools_base_path}/*")
list(REMOVE_ITEM Z_VCPKG_TOOLS_DIRS ${Z_VCPKG_TOOLS_FILES})
list(FILTER Z_VCPKG_TOOLS_DIRS EXCLUDE REGEX "/debug/")
foreach(Z_VCPKG_TOOLS_DIR IN LISTS Z_VCPKG_TOOLS_DIRS)
list(APPEND CMAKE_PROGRAM_PATH "${Z_VCPKG_TOOLS_DIR}")
endforeach()
unset(Z_VCPKG_TOOLS_DIRS)
unset(Z_VCPKG_TOOLS_DIR)
unset(tools_base_path)
endif()
cmake_policy(POP)