From bd602277bf7fc3188b3d086b302c6840464db900 Mon Sep 17 00:00:00 2001 From: Alexander Neumann <30894796+Neumann-A@users.noreply.github.com> Date: Fri, 4 Mar 2022 23:16:47 +0100 Subject: [PATCH] [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 --- scripts/buildsystems/vcpkg.cmake | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/scripts/buildsystems/vcpkg.cmake b/scripts/buildsystems/vcpkg.cmake index 5a475b00f9..3e8fd72605 100644 --- a/scripts/buildsystems/vcpkg.cmake +++ b/scripts/buildsystems/vcpkg.cmake @@ -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)