cmake: fix shell completion install when just one flavor is enabled

Also:
- tidy up the `if` tree.
- drop `include(GNUInstallDirs)` in favor of the upper-level one.

Reported-by: Daniel Engberg
Bug: https://github.com/curl/curl/issues/16946#issuecomment-2814663246
Follow-up to c8b0f0c9ad #16833

Closes #17094
This commit is contained in:
Viktor Szakats 2025-04-18 09:46:59 +02:00
parent cd0ec4784c
commit f616704980
No known key found for this signature in database
GPG key ID: B5ABD165E2AEF201

View file

@ -52,27 +52,29 @@ if(CURL_COMPLETION_FISH OR
if(NOT CURL_DISABLE_INSTALL)
if(NOT CMAKE_CROSSCOMPILING)
if(NOT CURL_COMPLETION_FISH_DIR)
find_package(PkgConfig QUIET)
pkg_get_variable(CURL_COMPLETION_FISH_DIR "fish" "completionsdir")
if(NOT _pkg_fish_completionsdir)
include(GNUInstallDirs)
if(CMAKE_INSTALL_DATAROOTDIR)
set(CURL_COMPLETION_FISH_DIR "${CMAKE_INSTALL_DATAROOTDIR}/fish/vendor_completions.d")
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 _pkg_fish_completionsdir)
if(CMAKE_INSTALL_DATAROOTDIR)
set(CURL_COMPLETION_FISH_DIR "${CMAKE_INSTALL_DATAROOTDIR}/fish/vendor_completions.d")
endif()
endif()
endif()
endif()
if(NOT CURL_COMPLETION_ZSH_DIR)
include(GNUInstallDirs)
if(CMAKE_INSTALL_DATAROOTDIR)
set(CURL_COMPLETION_ZSH_DIR "${CMAKE_INSTALL_DATAROOTDIR}/zsh/site-functions")
if(CURL_COMPLETION_FISH_DIR)
install(FILES "${_completion_fish}" DESTINATION "${CURL_COMPLETION_FISH_DIR}")
endif()
endif()
if(CURL_COMPLETION_FISH_DIR)
install(FILES "${_completion_fish}" DESTINATION "${CURL_COMPLETION_FISH_DIR}")
endif()
if(CURL_COMPLETION_ZSH_DIR)
install(FILES "${_completion_zsh}" DESTINATION "${CURL_COMPLETION_ZSH_DIR}")
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()
endif()
else()
message(STATUS "We cannot install completion scripts when cross-compiling")