]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
cmake: install shell completions for cross-builds
authorViktor Szakats <commit@vsz.me>
Wed, 23 Apr 2025 08:26:38 +0000 (10:26 +0200)
committerViktor Szakats <commit@vsz.me>
Thu, 24 Apr 2025 08:04:17 +0000 (10:04 +0200)
Also:
- omit auto-detecting `CURL_COMPLETION_FISH_DIR` via `pkg-config`
  for cross-builds and when `CMAKE_INSTALL_PREFIX` is set.
- flatten nested `if`s.

Note:
On macOS with Homebrew, `pkg-config --variable completionsdir fish`
returns the version-specific Cellar path instead of the permanent path
`/opt/homebrew/share/fish/vendor_completions.d/`. This mimics what
autotools does, but may need further fixing, possibly upstream.
https://github.com/Homebrew/homebrew-core/blob/9c13e62b009b8e814fda180e0fcc5096318daf31/Formula/f/fish.rb
https://github.com/fish-shell/fish-shell/blob/ce631fd2fb1f5b63f5f0f1b4041a30dfad823d22/cmake/Install.cmake#L15-L21

Ref: #17147
Ref: 51170b52d15256d4aaf74ed6eea9a9297f5d595c #17159
Bug: https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=1103938

Closes #17145

scripts/CMakeLists.txt

index a627184e45e5a807571a3547ad827c87a7977538..dd590c910fc7ec782d2c30298df3389f94c914f6 100644 (file)
@@ -51,33 +51,25 @@ if(CURL_COMPLETION_FISH OR
     endif()
 
     if(NOT CURL_DISABLE_INSTALL)
-      if(NOT CMAKE_CROSSCOMPILING)
-        if(CURL_COMPLETION_FISH)
-          if(NOT CURL_COMPLETION_FISH_DIR)
-            find_package(PkgConfig QUIET)
-            pkg_get_variable(CURL_COMPLETION_FISH_DIR "fish" "completionsdir")
-            if(NOT CURL_COMPLETION_FISH_DIR)
-              if(CMAKE_INSTALL_DATAROOTDIR)
-                set(CURL_COMPLETION_FISH_DIR "${CMAKE_INSTALL_DATAROOTDIR}/fish/vendor_completions.d")
-              endif()
-            endif()
-          endif()
-          if(CURL_COMPLETION_FISH_DIR)
-            install(FILES "${_completion_fish}" DESTINATION "${CURL_COMPLETION_FISH_DIR}")
-          endif()
+      if(CURL_COMPLETION_FISH)
+        if(NOT CURL_COMPLETION_FISH_DIR AND NOT CMAKE_CROSSCOMPILING AND NOT DEFINED CMAKE_INSTALL_PREFIX)
+          find_package(PkgConfig QUIET)
+          pkg_get_variable(CURL_COMPLETION_FISH_DIR "fish" "completionsdir")
         endif()
-        if(CURL_COMPLETION_ZSH)
-          if(NOT CURL_COMPLETION_ZSH_DIR)
-            if(CMAKE_INSTALL_DATAROOTDIR)
-              set(CURL_COMPLETION_ZSH_DIR "${CMAKE_INSTALL_DATAROOTDIR}/zsh/site-functions")
-            endif()
-          endif()
-          if(CURL_COMPLETION_ZSH_DIR)
-            install(FILES "${_completion_zsh}" DESTINATION "${CURL_COMPLETION_ZSH_DIR}")
-          endif()
+        if(NOT CURL_COMPLETION_FISH_DIR AND CMAKE_INSTALL_DATAROOTDIR)
+          set(CURL_COMPLETION_FISH_DIR "${CMAKE_INSTALL_DATAROOTDIR}/fish/vendor_completions.d")
+        endif()
+        if(CURL_COMPLETION_FISH_DIR)
+          install(FILES "${_completion_fish}" DESTINATION "${CURL_COMPLETION_FISH_DIR}")
+        endif()
+      endif()
+      if(CURL_COMPLETION_ZSH)
+        if(NOT CURL_COMPLETION_ZSH_DIR AND CMAKE_INSTALL_DATAROOTDIR)
+          set(CURL_COMPLETION_ZSH_DIR "${CMAKE_INSTALL_DATAROOTDIR}/zsh/site-functions")
+        endif()
+        if(CURL_COMPLETION_ZSH_DIR)
+          install(FILES "${_completion_zsh}" DESTINATION "${CURL_COMPLETION_ZSH_DIR}")
         endif()
-      else()
-        message(STATUS "We cannot install completion scripts when cross-compiling")
       endif()
     endif()
   else()