From 1d051d0e6e13717c7c97816ff0906bd82a82340b Mon Sep 17 00:00:00 2001 From: Fabrice de Gans Date: Fri, 15 Mar 2024 11:32:24 -0700 Subject: [PATCH] [Build] Make powershell optional on non-Windows (#1248) Fixes: #1247 --- CMakeLists.txt | 2 +- cmake/MakeReleaseCommitAndTag.cmake | 4 +++- cmake/Set-Toolchain-vcpkg.cmake | 3 +++ cmake/UpdateAppcast.cmake | 4 +++- src/wx/CMakeLists.txt | 3 +++ 5 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 10d8e1ed..57db8b08 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -28,7 +28,7 @@ if(WIN32) HINTS "/Windows/System32/WindowsPowerShell/v1.0" REQUIRED) else() - find_program(POWERSHELL pwsh REQUIRED) + find_program(POWERSHELL pwsh) endif() include(Set-Toolchain-vcpkg) diff --git a/cmake/MakeReleaseCommitAndTag.cmake b/cmake/MakeReleaseCommitAndTag.cmake index 5f619fe6..3a8ee183 100644 --- a/cmake/MakeReleaseCommitAndTag.cmake +++ b/cmake/MakeReleaseCommitAndTag.cmake @@ -184,8 +184,10 @@ Ignore the following cmake error. endwhile() # Convert to UNIX line endings on Windows, just copy the file otherwise. - if(CMAKE_HOST_SYSTEM MATCHES Windows OR ((NOT DEFINED CMAKE_HOST_SYSTEM) AND WIN32)) + if(NOT DEFINED POWERSHELL) + message(FATAL_ERROR "Powershell is required to convert line endings on Windows.") + endif() execute_process( COMMAND ${POWERSHELL} -NoLogo -NoProfile -ExecutionPolicy Bypass -Command [=[ $text = [IO.File]::ReadAllText("CHANGELOG.md.work") -replace "`r`n", "`n" diff --git a/cmake/Set-Toolchain-vcpkg.cmake b/cmake/Set-Toolchain-vcpkg.cmake index 8bb668a2..befbe0b3 100644 --- a/cmake/Set-Toolchain-vcpkg.cmake +++ b/cmake/Set-Toolchain-vcpkg.cmake @@ -320,6 +320,9 @@ function(vcpkg_remove_optional_deps vcpkg_exe) endfunction() function(vcpkg_set_toolchain) + if(NOT DEFINED POWERSHELL) + message(FATAL_ERROR "Powershell is required to use vcpkg binaries.") + endif() if(NOT DEFINED ENV{VCPKG_ROOT}) get_filename_component(preferred_root ${CMAKE_SOURCE_DIR}/../vcpkg ABSOLUTE) diff --git a/cmake/UpdateAppcast.cmake b/cmake/UpdateAppcast.cmake index 3d224ec9..6fdf4f14 100644 --- a/cmake/UpdateAppcast.cmake +++ b/cmake/UpdateAppcast.cmake @@ -75,8 +75,10 @@ Ignore the following cmake error. endwhile() # Convert to UNIX line endings on Windows, just copy the file otherwise. - if(CMAKE_HOST_SYSTEM MATCHES Windows OR ((NOT DEFINED CMAKE_HOST_SYSTEM) AND WIN32)) + if(NOT DEFINED POWERSHELL) + message(FATAL_ERROR "Powershell is required to convert line endings on Windows.") + endif() execute_process( COMMAND ${POWERSHELL} -NoLogo -NoProfile -ExecutionPolicy Bypass -Command [=[ $text = [IO.File]::ReadAllText("appcast.xml.work") -replace "`r`n", "`n" diff --git a/src/wx/CMakeLists.txt b/src/wx/CMakeLists.txt index dddaf363..ff05a060 100644 --- a/src/wx/CMakeLists.txt +++ b/src/wx/CMakeLists.txt @@ -158,6 +158,9 @@ if(WIN32 AND CMAKE_TOOLCHAIN_FILE MATCHES "vcpkg") set(ENV{PATH} "${dbg_prefix}/bin;${common_prefix}/bin;$ENV{PATH}") if(NOT ZIP_PROGRAM AND NOT EXISTS ${CMAKE_CURRENT_BINARY_DIR}/zip.exe) + if(NOT DEFINED POWERSHELL) + message(FATAL_ERROR "Powershell is required for extraction.") + endif() # 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) # unzip it