From c8baa4708abf9118e26fb1d1950596e874448fad Mon Sep 17 00:00:00 2001 From: Kai Pastor Date: Mon, 7 Mar 2022 20:01:14 +0100 Subject: [PATCH] [vcpkg baseline][vcpkg toolchain] Fix toolchain usage with CMake <= 3.19 (#23410) * Fix toolchain usage with CMake <= 3.19 * Add quotes * Merge Neumann-A:fix_tools_selection into dg0yt:cmake-3.19-quirk Co-authored-by: JackBoosY --- scripts/buildsystems/vcpkg.cmake | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/scripts/buildsystems/vcpkg.cmake b/scripts/buildsystems/vcpkg.cmake index 3e8fd72605..ceac24ffd8 100644 --- a/scripts/buildsystems/vcpkg.cmake +++ b/scripts/buildsystems/vcpkg.cmake @@ -518,7 +518,12 @@ if(VCPKG_MANIFEST_MODE AND VCPKG_MANIFEST_INSTALL AND NOT Z_VCPKG_CMAKE_IN_TRY_C endif() 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) +set(VCPKG_CAN_USE_HOST_TOOLS OFF) +if(DEFINED VCPKG_HOST_TRIPLET AND NOT VCPKG_HOST_TRIPLET STREQUAL "") + set(VCPKG_CAN_USE_HOST_TOOLS ON) +endif() +cmake_dependent_option(VCPKG_USE_HOST_TOOLS "Setup CMAKE_PROGRAM_PATH to use host tools" ON "VCPKG_CAN_USE_HOST_TOOLS" OFF) +unset(VCPKG_CAN_USE_HOST_TOOLS) if(VCPKG_SETUP_CMAKE_PROGRAM_PATH) set(tools_base_path "${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/tools") @@ -526,9 +531,9 @@ if(VCPKG_SETUP_CMAKE_PROGRAM_PATH) set(tools_base_path "${VCPKG_INSTALLED_DIR}/${VCPKG_HOST_TRIPLET}/tools") endif() list(APPEND CMAKE_PROGRAM_PATH "${tools_base_path}") - file(GLOB_RECURSE Z_VCPKG_TOOLS_DIRS "${tools_base_path}/*") + file(GLOB_RECURSE Z_VCPKG_TOOLS_DIRS LIST_DIRECTORIES true "${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(REMOVE_ITEM Z_VCPKG_TOOLS_DIRS ${Z_VCPKG_TOOLS_FILES} "") # need at least one item for REMOVE_ITEM if CMake <= 3.19 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}")