summaryrefslogtreecommitdiffstats
path: root/cmake/modules/FindPowerShell.cmake
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:34:10 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-10 20:34:10 +0000
commite4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc (patch)
tree68cb5ef9081156392f1dd62a00c6ccc1451b93df /cmake/modules/FindPowerShell.cmake
parentInitial commit. (diff)
downloadwireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.tar.xz
wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.zip
Adding upstream version 4.2.2.upstream/4.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'cmake/modules/FindPowerShell.cmake')
-rw-r--r--cmake/modules/FindPowerShell.cmake32
1 files changed, 32 insertions, 0 deletions
diff --git a/cmake/modules/FindPowerShell.cmake b/cmake/modules/FindPowerShell.cmake
new file mode 100644
index 0000000..307d7e7
--- /dev/null
+++ b/cmake/modules/FindPowerShell.cmake
@@ -0,0 +1,32 @@
+#
+# Find PowerShell
+# This module looks for PowerShell and sets the following:
+# POWERSHELL_EXECUTABLE - Path to PowerShell.
+# POWERSHELL_COMMAND - Command suitable for running .ps1 scripts
+#
+# To do:
+# - Add a version check
+#
+
+find_program(POWERSHELL_EXECUTABLE
+ NAMES
+ powershell
+ pwsh
+ DOC "PowerShell command"
+)
+
+INCLUDE(FindPackageHandleStandardArgs)
+find_package_handle_standard_args(PowerShell DEFAULT_MSG POWERSHELL_EXECUTABLE)
+
+set(_powershell_command "POWERSHELL_COMMAND-NOTFOUND")
+if(POWERSHELL_FOUND)
+ # Calling a script using "-File" doesn't properly return exit codes.
+ # Use dot sourcing instead
+ # https://connect.microsoft.com/PowerShell/feedback/details/777375/powershell-exe-does-not-set-an-exit-code-when-file-is-used
+ set(_powershell_command "${POWERSHELL_EXECUTABLE}" -NoProfile -NonInteractive -executionpolicy bypass .)
+endif()
+set(POWERSHELL_COMMAND ${_powershell_command}
+ CACHE STRING "Command suitable for running PowerShell scripts."
+)
+
+mark_as_advanced(POWERSHELL_EXECUTABLE POWERSHELL_COMMAND)