Skip to content

Commit

Permalink
[vcpkg.cmake] Setup CMAKE_PROGRAM_PATH for the host if possible (#23322)
Browse files Browse the repository at this point in the history
* 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 17737bc.

* remove unnecessary if(IS_DIRECTORY)

Co-authored-by: Alexander Neumann <[email protected]>
  • Loading branch information
Neumann-A and Alexander Neumann authored Mar 4, 2022
1 parent b44c4dd commit bd60227
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions scripts/buildsystems/vcpkg.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

3 comments on commit bd60227

@sosias
Copy link

@sosias sosias commented on bd60227 Mar 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this change I got build error on linux, with cmake 3.13.4

[cmake]  CMake Error at vcpkg/scripts/buildsystems/vcpkg.cmake:531 (list):
[cmake]      list sub-command REMOVE_ITEM requires two or more arguments.

thanks for your work and the awesome project!! 💙

@dg0yt
Copy link
Contributor

@dg0yt dg0yt commented on bd60227 Mar 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After this change I got build error on linux, with cmake 3.13.4

[cmake]  CMake Error at vcpkg/scripts/buildsystems/vcpkg.cmake:531 (list):
[cmake]      list sub-command REMOVE_ITEM requires two or more arguments.

This is a bug in CMake <= 3.19. My proposed fix is using a dummy list item CMake_3.19_quirk, i.e.

list(REMOVE_ITEM Z_VCPKG_TOOLS_DIRS ${Z_VCPKG_TOOLS_FILES} CMake_3.19_quirk)

@dg0yt
Copy link
Contributor

@dg0yt dg0yt commented on bd60227 Mar 7, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

PR: #23410

Please sign in to comment.