From b7056e9f1f34f18b6648b1f1d9c4e9d31f04e91c Mon Sep 17 00:00:00 2001 From: Billy O'Neal Date: Sun, 1 Nov 2020 17:12:49 -0800 Subject: [PATCH] [vcpkg] Fix incorrect determination of PowerShell not found (#14317) * Fix incorrect determination of PowerShell not found because Bill doesn't know enough CMake :( Resolves #14283 --- scripts/buildsystems/vcpkg.cmake | 37 ++++++++++--------- .../cmake/vcpkg_copy_tool_dependencies.cmake | 16 ++++---- 2 files changed, 28 insertions(+), 25 deletions(-) diff --git a/scripts/buildsystems/vcpkg.cmake b/scripts/buildsystems/vcpkg.cmake index dab5b73a61..2a89422977 100644 --- a/scripts/buildsystems/vcpkg.cmake +++ b/scripts/buildsystems/vcpkg.cmake @@ -106,11 +106,11 @@ endif() if(VCPKG_TARGET_TRIPLET) # This is required since a user might do: 'set(VCPKG_TARGET_TRIPLET somevalue)' [no CACHE] before the first project() call # Latter within the toolchain file we do: 'set(VCPKG_TARGET_TRIPLET somevalue CACHE STRING "")' which - # will otherwise override the user setting of VCPKG_TARGET_TRIPLET in the current scope of the toolchain since the CACHE value - # did not exist previously. Since the value is newly created CMake will use the CACHE value within this scope since it is the more + # will otherwise override the user setting of VCPKG_TARGET_TRIPLET in the current scope of the toolchain since the CACHE value + # did not exist previously. Since the value is newly created CMake will use the CACHE value within this scope since it is the more # recently created value in directory scope. This 'strange' behaviour only happens on the very first configure call since subsequent # configure call will see the user value as the more recent value. The same logic must be applied to all cache values within this file! - # The FORCE keyword is required to ALWAYS lift the user provided/previously set value into a CACHE value. + # The FORCE keyword is required to ALWAYS lift the user provided/previously set value into a CACHE value. set(VCPKG_TARGET_TRIPLET ${VCPKG_TARGET_TRIPLET} CACHE STRING "Vcpkg target triplet (ex. x86-windows)" FORCE) elseif(CMAKE_GENERATOR_PLATFORM MATCHES "^[Ww][Ii][Nn]32$") set(_VCPKG_TARGET_TRIPLET_ARCH x86) @@ -306,9 +306,9 @@ set(CMAKE_SYSTEM_IGNORE_PATH list(APPEND CMAKE_PROGRAM_PATH ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/tools) file(GLOB _VCPKG_TOOLS_DIRS ${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/tools/*) -foreach(_VCPKG_TOOLS_DIR ${_VCPKG_TOOLS_DIRS}) - if(IS_DIRECTORY ${_VCPKG_TOOLS_DIR}) - list(APPEND CMAKE_PROGRAM_PATH ${_VCPKG_TOOLS_DIR}) +foreach(_VCPKG_TOOLS_DIR IN LISTS _VCPKG_TOOLS_DIRS) + if(IS_DIRECTORY "${_VCPKG_TOOLS_DIR}") + list(APPEND CMAKE_PROGRAM_PATH "${_VCPKG_TOOLS_DIR}") endif() endforeach() @@ -361,7 +361,7 @@ if(VCPKG_MANIFEST_MODE AND VCPKG_MANIFEST_INSTALL AND NOT _CMAKE_IN_TRY_COMPILE) endforeach() endif() - foreach(feature ${VCPKG_MANIFEST_FEATURES}) + foreach(feature IN LISTS VCPKG_MANIFEST_FEATURES) list(APPEND _VCPKG_ADDITIONAL_MANIFEST_PARAMS "--x-feature=${feature}") endforeach() @@ -399,12 +399,17 @@ function(_vcpkg_set_powershell_path) # Attempt to use pwsh if it is present; otherwise use powershell if (NOT DEFINED _VCPKG_POWERSHELL_PATH) find_program(_VCPKG_PWSH_PATH pwsh) - if (_VCPKG_PWSH_PATH-NOTFOUND) + if (_VCPKG_PWSH_PATH) + set(_VCPKG_POWERSHELL_PATH "${_VCPKG_PWSH_PATH}" CACHE INTERNAL "The path to the PowerShell implementation to use.") + else() message(DEBUG "vcpkg: Could not find PowerShell Core; falling back to PowerShell") find_program(_VCPKG_BUILTIN_POWERSHELL_PATH powershell REQUIRED) - set(_VCPKG_POWERSHELL_PATH "${_VCPKG_BUILTIN_POWERSHELL_PATH}" CACHE INTERNAL "The path to the PowerShell implementation to use.") - else() - set(_VCPKG_POWERSHELL_PATH "${_VCPKG_PWSH_PATH}" CACHE INTERNAL "The path to the PowerShell implementation to use.") + if (_VCPKG_BUILTIN_POWERSHELL_PATH) + set(_VCPKG_POWERSHELL_PATH "${_VCPKG_BUILTIN_POWERSHELL_PATH}" CACHE INTERNAL "The path to the PowerShell implementation to use.") + else() + message(WARNING "vcpkg: Could not find PowerShell; using static string 'powershell.exe'") + set(_VCPKG_POWERSHELL_PATH "powershell.exe" CACHE INTERNAL "The path to the PowerShell implementation to use.") + endif() endif() endif() # _VCPKG_POWERSHELL_PATH endfunction() @@ -471,13 +476,11 @@ endfunction() # DESTINATION - the runtime directory for those targets (usually `bin`) function(x_vcpkg_install_local_dependencies) if(_VCPKG_TARGET_TRIPLET_PLAT MATCHES "windows|uwp") - # Parse command line - cmake_parse_arguments(__VCPKG_APPINSTALL "" "DESTINATION" "TARGETS" ${ARGN}) - - foreach(TARGET ${__VCPKG_APPINSTALL_TARGETS}) + cmake_parse_arguments(PARSE_ARGV __VCPKG_APPINSTALL "" "DESTINATION" "TARGETS") + _vcpkg_set_powershell_path() + foreach(TARGET IN LISTS __VCPKG_APPINSTALL_TARGETS) install(CODE "message(\"-- Installing app dependencies for ${TARGET}...\") - execute_process(COMMAND - powershell -noprofile -executionpolicy Bypass -file \"${_VCPKG_TOOLCHAIN_DIR}/msbuild/applocal.ps1\" + execute_process(COMMAND \"${_VCPKG_POWERSHELL_PATH}\" -noprofile -executionpolicy Bypass -file \"${_VCPKG_TOOLCHAIN_DIR}/msbuild/applocal.ps1\" -targetBinary \"\${CMAKE_INSTALL_PREFIX}/${__VCPKG_APPINSTALL_DESTINATION}/$\" -installedDir \"${_VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}$<$:/debug>/bin\" -OutVariable out)") diff --git a/scripts/cmake/vcpkg_copy_tool_dependencies.cmake b/scripts/cmake/vcpkg_copy_tool_dependencies.cmake index 681c80461f..74815eec53 100644 --- a/scripts/cmake/vcpkg_copy_tool_dependencies.cmake +++ b/scripts/cmake/vcpkg_copy_tool_dependencies.cmake @@ -18,22 +18,22 @@ ## * [fltk](https://github.com/Microsoft/vcpkg/blob/master/ports/fltk/portfile.cmake) function(vcpkg_copy_tool_dependencies TOOL_DIR) find_program(PWSH_EXE pwsh) - if (PWSH_EXE-NOTFOUND) + if (NOT PWSH_EXE) message(FATAL_ERROR "Could not find PowerShell Core; please open an issue to report this.") endif() macro(search_for_dependencies PATH_TO_SEARCH) - file(GLOB TOOLS ${TOOL_DIR}/*.exe ${TOOL_DIR}/*.dll) - foreach(TOOL ${TOOLS}) + file(GLOB TOOLS "${TOOL_DIR}/*.exe" "${TOOL_DIR}/*.dll") + foreach(TOOL IN LISTS TOOLS) vcpkg_execute_required_process( COMMAND "${PWSH_EXE}" -noprofile -executionpolicy Bypass -nologo -file "${SCRIPTS}/buildsystems/msbuild/applocal.ps1" - -targetBinary ${TOOL} - -installedDir ${PATH_TO_SEARCH} - WORKING_DIRECTORY ${VCPKG_ROOT_DIR} + -targetBinary "${TOOL}" + -installedDir "${PATH_TO_SEARCH}" + WORKING_DIRECTORY "${VCPKG_ROOT_DIR}" LOGNAME copy-tool-dependencies ) endforeach() endmacro() - search_for_dependencies(${CURRENT_PACKAGES_DIR}/bin) - search_for_dependencies(${CURRENT_INSTALLED_DIR}/bin) + search_for_dependencies("${CURRENT_PACKAGES_DIR}/bin") + search_for_dependencies("${CURRENT_INSTALLED_DIR}/bin") endfunction()