build: use find_program() to find powershell

Use cmake find_program() to find powershell.exe on Windows because
invoking `powershell` or `powershell.exe` without a path sometimes fails
for some reason. Use the standard location on Windows 11 as a hint.

Make the `pwsh` executable REQUIRED when installing vcpkg packages
on non-Windows.

Use find_program() to find the zip executable before downloading it on
Windows vcpkg builds.

Signed-off-by: Rafael Kitover <rkitover@gmail.com>
This commit is contained in:
Rafael Kitover 2024-02-28 13:44:22 +00:00
parent e5aa685f70
commit 215e3c5ae9
No known key found for this signature in database
GPG Key ID: 08AB596679D86240
2 changed files with 20 additions and 7 deletions

View File

@ -278,9 +278,9 @@ function(get_binary_packages vcpkg_exe)
endif() endif()
if(WIN32) if(WIN32)
set(powershell powershell) find_program(powershell powershell.exe HINTS "/Windows/System32/WindowsPowerShell/v1.0" REQUIRED)
else() else()
set(powershell pwsh) find_program(powershell pwsh REQUIRED)
endif() endif()
unset(to_install) unset(to_install)

View File

@ -94,6 +94,17 @@ if (WIN32)
add_definitions(-D_UNICODE -DUNICODE -DwxUSE_GUI=1 -D__WXMSW__ -DWINVER=0x0A00 -DNTDDI_VERSION=0x0A000007) add_definitions(-D_UNICODE -DUNICODE -DwxUSE_GUI=1 -D__WXMSW__ -DWINVER=0x0A00 -DNTDDI_VERSION=0x0A000007)
endif() endif()
if(CMAKE_HOST_WIN32)
find_program(POWERSHELL powershell.exe HINTS "/Windows/System32/WindowsPowerShell/v1.0" REQUIRED)
else()
find_program(POWERSHELL pwsh)
endif()
find_program(ZIP_PROGRAM zip)
if(ZIP_PROGRAM)
set(ZIP_PROGRAM "${ZIP_PROGRAM}" CACHE STRING "zip compressor executable" FORCE)
endif()
# on VS with vcpkg we can't use FindwxWidgets, we have to set everything up # on VS with vcpkg we can't use FindwxWidgets, we have to set everything up
# manually because the package is broken # manually because the package is broken
if(WIN32 AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg") if(WIN32 AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
@ -180,12 +191,12 @@ if(WIN32 AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg")
set(ENV{PATH} "${dbg_prefix}/bin;${common_prefix}/bin;$ENV{PATH}") set(ENV{PATH} "${dbg_prefix}/bin;${common_prefix}/bin;$ENV{PATH}")
if(NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/zip.exe) if(NOT ZIP_PROGRAM AND NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/zip.exe)
# get zip binary for wxrc # get zip binary for wxrc
file(DOWNLOAD "https://www.willus.com/archive/zip64/infozip_binaries_win32.zip" ${CMAKE_CURRENT_BINARY_DIR}/infozip_binaries_win32.zip) file(DOWNLOAD "https://www.willus.com/archive/zip64/infozip_binaries_win32.zip" ${CMAKE_CURRENT_BINARY_DIR}/infozip_binaries_win32.zip)
# unzip it # unzip it
execute_process( execute_process(
COMMAND powershell.exe -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('${CMAKE_CURRENT_BINARY_DIR}/infozip_binaries_win32.zip', '${CMAKE_CURRENT_BINARY_DIR}'); }" COMMAND "${POWERSHELL}" -NoLogo -NoProfile -ExecutionPolicy Bypass -Command "& { Add-Type -A 'System.IO.Compression.FileSystem'; [IO.Compression.ZipFile]::ExtractToDirectory('${CMAKE_CURRENT_BINARY_DIR}/infozip_binaries_win32.zip', '${CMAKE_CURRENT_BINARY_DIR}'); }"
) )
set(ZIP_PROGRAM ${CMAKE_CURRENT_BINARY_DIR}/zip.exe CACHE STRING "zip compressor executable" FORCE) set(ZIP_PROGRAM ${CMAKE_CURRENT_BINARY_DIR}/zip.exe CACHE STRING "zip compressor executable" FORCE)
@ -592,10 +603,12 @@ include_directories(widgets)
include_directories(${CMAKE_CURRENT_BINARY_DIR}) include_directories(${CMAKE_CURRENT_BINARY_DIR})
include_directories(${CMAKE_CURRENT_SOURCE_DIR}) include_directories(${CMAKE_CURRENT_SOURCE_DIR})
find_program(ZIP_PROGRAM zip DOC "zip compressor executable")
if(NOT ZIP_PROGRAM) if(NOT ZIP_PROGRAM)
find_program(ZIP_PROGRAM zip DOC "zip compressor executable")
if(NOT ZIP_PROGRAM)
message(FATAL_ERROR "The zip compressor program is required for building.") message(FATAL_ERROR "The zip compressor program is required for building.")
endif()
endif() endif()
set( set(