diff options
author | fuzzard <fuzzard@kodi.tv> | 2024-05-11 22:56:16 +1000 |
---|---|---|
committer | fuzzard <fuzzard@kodi.tv> | 2024-05-18 11:27:12 +1000 |
commit | c1bfdc2543cd23c727cf064648d3cf580a2d5e7c (patch) | |
tree | 2062c2960b79541f7044311d4d158190783777af /cmake | |
parent | a945a7fb01000ca60581baf1b1fe49cc163f7279 (diff) |
[cmake][modules] FindLibZip cleanup and use core_target_link_libraries
Diffstat (limited to 'cmake')
-rw-r--r-- | cmake/modules/FindLibZip.cmake | 70 |
1 files changed, 38 insertions, 32 deletions
diff --git a/cmake/modules/FindLibZip.cmake b/cmake/modules/FindLibZip.cmake index ccbc4e38a6..c108970c34 100644 --- a/cmake/modules/FindLibZip.cmake +++ b/cmake/modules/FindLibZip.cmake @@ -3,15 +3,9 @@ # ----------- # Finds the LibZip library # -# This will define the following variables:: +# The following imported target will be created: # -# LIBZIP_FOUND - system has LibZip -# LIBZIP_INCLUDE_DIRS - the LibZip include directory -# LIBZIP_LIBRARIES - the LibZip libraries -# -# and the following imported targets: -# -# libzip::zip - The LibZip library +# ${APP_NAME_LC}::LibZip - The LibZip library include(cmake/scripts/common/ModuleHelpers.cmake) @@ -19,11 +13,11 @@ set(MODULE_LC libzip) SETUP_BUILD_VARS() # Check for existing lib -find_package(LIBZIP CONFIG QUIET +find_package(libzip CONFIG QUIET HINTS ${DEPENDS_PATH}/lib ${${CORE_PLATFORM_NAME_LC}_SEARCH_CONFIG}) -if(NOT LIBZIP_FOUND OR LIBZIP_VERSION VERSION_LESS ${${MODULE}_VER}) +if(NOT LIBZIP_FOUND OR libzip_VERSION VERSION_LESS ${${MODULE}_VER}) # Check for dependencies find_package(GnuTLS MODULE REQUIRED) @@ -41,13 +35,27 @@ if(NOT LIBZIP_FOUND OR LIBZIP_VERSION VERSION_LESS ${${MODULE}_VER}) BUILD_DEP_TARGET() else() - find_path(LIBZIP_INCLUDE_DIR NAMES zip.h - HINTS ${DEPENDS_PATH}/include - ${${CORE_PLATFORM_NAME_LC}_SEARCH_CONFIG}) + # we only do this because we use find_package_handle_standard_args for config time output + # and it isnt capable of handling TARGETS, so we have to extract the info + get_target_property(_ZIP_CONFIGURATIONS libzip::zip IMPORTED_CONFIGURATIONS) + foreach(_zip_config IN LISTS _ZIP_CONFIGURATIONS) + # Some non standard config (eg None on Debian) + # Just set to RELEASE var so select_library_configurations can continue to work its magic + string(TOUPPER ${_zip_config} _zip_config_UPPER) + if((NOT ${_zip_config_UPPER} STREQUAL "RELEASE") AND + (NOT ${_zip_config_UPPER} STREQUAL "DEBUG")) + get_target_property(ZIP_LIBRARY_RELEASE libzip::zip IMPORTED_LOCATION_${_zip_config_UPPER}) + else() + get_target_property(ZIP_LIBRARY_${_zip_config_UPPER} libzip::zip IMPORTED_LOCATION_${_zip_config_UPPER}) + endif() + endforeach() + + get_target_property(ZIP_INCLUDE_DIR libzip::zip INTERFACE_INCLUDE_DIRECTORIES) + set(LIBZIP_VERSION ${libzip_VERSION}) - find_library(LIBZIP_LIBRARY NAMES zip - HINTS ${DEPENDS_PATH}/lib - ${${CORE_PLATFORM_NAME_LC}_SEARCH_CONFIG}) + include(SelectLibraryConfigurations) + select_library_configurations(LIBZIP) + unset(LIBZIP_LIBRARIES) endif() include(FindPackageHandleStandardArgs) @@ -56,31 +64,29 @@ find_package_handle_standard_args(LibZip VERSION_VAR LIBZIP_VERSION) if(LIBZIP_FOUND) - set(LIBZIP_LIBRARIES ${LIBZIP_LIBRARY}) - set(LIBZIP_INCLUDE_DIRS ${LIBZIP_INCLUDE_DIR}) + # cmake target and not building internal + if(TARGET libzip::zip AND NOT TARGET libzip) - if(NOT TARGET libzip::zip) - add_library(libzip::zip UNKNOWN IMPORTED) + add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} ALIAS libzip::zip) - set_target_properties(libzip::zip PROPERTIES - INTERFACE_INCLUDE_DIRECTORIES "${LIBZIP_INCLUDE_DIR}" - IMPORTED_LOCATION "${LIBZIP_LIBRARY}") - - if(TARGET libzip) - add_dependencies(libzip::zip libzip) - endif() - else() # ToDo: When we correctly import dependencies cmake targets for the following # BZip2::BZip2, LibLZMA::LibLZMA, GnuTLS::GnuTLS, Nettle::Nettle,ZLIB::ZLIB # For now, we just override set_target_properties(libzip::zip PROPERTIES INTERFACE_LINK_LIBRARIES "") + else() + add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED) + + set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES + INTERFACE_INCLUDE_DIRECTORIES "${LIBZIP_INCLUDE_DIR}" + IMPORTED_LOCATION "${LIBZIP_LIBRARY}") + + if(TARGET libzip) + add_dependencies(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} libzip) + endif() endif() - set_property(GLOBAL APPEND PROPERTY INTERNAL_DEPS_PROP libzip::zip) else() - if(LIBZIP_FIND_REQUIRED) + if(LibZip_FIND_REQUIRED) message(FATAL_ERROR "LibZip not found.") endif() endif() - -mark_as_advanced(LIBZIP_INCLUDE_DIR LIBZIP_LIBRARY) |