4 # Finds the LibZip library
6 # The following imported target will be created:
8 # ${APP_NAME_LC}::LibZip - The LibZip library
10 include(cmake/scripts/common/ModuleHelpers.cmake)
15 # Check for existing lib
16 find_package(libzip CONFIG QUIET
17 HINTS ${DEPENDS_PATH}/lib
18 ${${CORE_PLATFORM_NAME_LC}_SEARCH_CONFIG})
20 if(NOT LIBZIP_FOUND OR libzip_VERSION VERSION_LESS ${${MODULE}_VER})
21 # Check for dependencies
22 find_package(GnuTLS REQUIRED)
24 # Eventually we will want Find modules for the following deps
28 set(CMAKE_ARGS -DBUILD_DOC=OFF
31 -DBUILD_SHARED_LIBS=OFF
34 set(LIBZIP_VERSION ${${MODULE}_VER})
38 # we only do this because we use find_package_handle_standard_args for config time output
39 # and it isnt capable of handling TARGETS, so we have to extract the info
40 get_target_property(_ZIP_CONFIGURATIONS libzip::zip IMPORTED_CONFIGURATIONS)
41 foreach(_zip_config IN LISTS _ZIP_CONFIGURATIONS)
42 # Some non standard config (eg None on Debian)
43 # Just set to RELEASE var so select_library_configurations can continue to work its magic
44 string(TOUPPER ${_zip_config} _zip_config_UPPER)
45 if((NOT ${_zip_config_UPPER} STREQUAL "RELEASE") AND
46 (NOT ${_zip_config_UPPER} STREQUAL "DEBUG"))
47 get_target_property(ZIP_LIBRARY_RELEASE libzip::zip IMPORTED_LOCATION_${_zip_config_UPPER})
49 get_target_property(ZIP_LIBRARY_${_zip_config_UPPER} libzip::zip IMPORTED_LOCATION_${_zip_config_UPPER})
53 get_target_property(ZIP_INCLUDE_DIR libzip::zip INTERFACE_INCLUDE_DIRECTORIES)
54 set(LIBZIP_VERSION ${libzip_VERSION})
56 include(SelectLibraryConfigurations)
57 select_library_configurations(LIBZIP)
58 unset(LIBZIP_LIBRARIES)
61 include(FindPackageHandleStandardArgs)
62 find_package_handle_standard_args(LibZip
63 REQUIRED_VARS LIBZIP_LIBRARY LIBZIP_INCLUDE_DIR
64 VERSION_VAR LIBZIP_VERSION)
67 # cmake target and not building internal
68 if(TARGET libzip::zip AND NOT TARGET libzip)
70 add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} ALIAS libzip::zip)
72 # ToDo: When we correctly import dependencies cmake targets for the following
73 # BZip2::BZip2, LibLZMA::LibLZMA, GnuTLS::GnuTLS, Nettle::Nettle,ZLIB::ZLIB
74 # For now, we just override
75 set_target_properties(libzip::zip PROPERTIES
76 INTERFACE_LINK_LIBRARIES "")
78 add_library(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} UNKNOWN IMPORTED)
80 set_target_properties(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} PROPERTIES
81 INTERFACE_INCLUDE_DIRECTORIES "${LIBZIP_INCLUDE_DIR}"
82 IMPORTED_LOCATION "${LIBZIP_LIBRARY}")
85 add_dependencies(${APP_NAME_LC}::${CMAKE_FIND_PACKAGE_NAME} libzip)
89 if(LibZip_FIND_REQUIRED)
90 message(FATAL_ERROR "LibZip not found.")