cmake: install shell completions for cross-builds

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.
9c13e62b00/Formula/f/fish.rb
ce631fd2fb/cmake/Install.cmake (L15-L21)

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

Closes #17145
This commit is contained in:
Viktor Szakats 2025-04-23 10:26:38 +02:00
parent 82606325e3
commit c1c99054ab
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201

View File

@ -51,34 +51,26 @@ 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)
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")
if(NOT CURL_COMPLETION_FISH_DIR)
if(CMAKE_INSTALL_DATAROOTDIR)
endif()
if(NOT CURL_COMPLETION_FISH_DIR AND 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()
endif()
if(CURL_COMPLETION_ZSH)
if(NOT CURL_COMPLETION_ZSH_DIR)
if(CMAKE_INSTALL_DATAROOTDIR)
if(NOT CURL_COMPLETION_ZSH_DIR AND 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()
endif()
else()
message(STATUS "We cannot install completion scripts when cross-compiling")
endif()
endif()
else()
message(WARNING "No perl: cannot generate completion script")