Added findzip
This commit is contained in:
86
cmake/modules/Findlibzip.cmake
Normal file
86
cmake/modules/Findlibzip.cmake
Normal file
@@ -0,0 +1,86 @@
|
|||||||
|
# Copyright (c) 2025 Dominic Masters
|
||||||
|
#
|
||||||
|
# This software is released under the MIT License.
|
||||||
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
|
set(LIBZIP_ALLOW_FETCH ON CACHE BOOL "Allow fetching libzip if not found")
|
||||||
|
set(LIBZIP_FETCH_GIT_REPO "https://github.com/nih-at/libzip.git" CACHE STRING "libzip Git repository")
|
||||||
|
set(LIBZIP_FETCH_GIT_TAG "v1.11.1" CACHE STRING "libzip Git tag to fetch")
|
||||||
|
set(LIBZIP_MIN_VERSION "" CACHE STRING "Required minimum libzip version (optional)")
|
||||||
|
|
||||||
|
unset(LIBZIP_FOUND CACHE)
|
||||||
|
unset(LIBZIP_TARGET CACHE)
|
||||||
|
unset(LIBZIP_INCLUDE_DIRS CACHE)
|
||||||
|
unset(LIBZIP_LIBRARIES CACHE)
|
||||||
|
|
||||||
|
set(_find_args CONFIG QUIET)
|
||||||
|
if(LIBZIP_MIN_VERSION)
|
||||||
|
list(PREPEND _find_args ${LIBZIP_MIN_VERSION})
|
||||||
|
endif()
|
||||||
|
|
||||||
|
find_package(libzip ${_find_args})
|
||||||
|
|
||||||
|
if(TARGET libzip::zip)
|
||||||
|
set(LIBZIP_FOUND ON)
|
||||||
|
set(LIBZIP_TARGET libzip::zip)
|
||||||
|
elseif(TARGET zip) # some builds expose an un-namespaced "zip"
|
||||||
|
add_library(libzip::zip ALIAS zip)
|
||||||
|
set(LIBZIP_FOUND ON)
|
||||||
|
set(LIBZIP_TARGET libzip::zip)
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(NOT LIBZIP_FOUND)
|
||||||
|
find_package(PkgConfig QUIET)
|
||||||
|
if(PkgConfig_FOUND)
|
||||||
|
pkg_check_modules(LIBZIP_PC QUIET libzip)
|
||||||
|
if(LIBZIP_PC_FOUND)
|
||||||
|
# Create a consistent imported target matching libzip::zip
|
||||||
|
add_library(libzip::zip INTERFACE IMPORTED)
|
||||||
|
set_target_properties(libzip::zip PROPERTIES
|
||||||
|
INTERFACE_INCLUDE_DIRECTORIES "${LIBZIP_PC_INCLUDE_DIRS}"
|
||||||
|
INTERFACE_LINK_LIBRARIES "${LIBZIP_PC_LINK_LIBRARIES}"
|
||||||
|
)
|
||||||
|
set(LIBZIP_FOUND ON)
|
||||||
|
set(LIBZIP_TARGET libzip::zip)
|
||||||
|
set(LIBZIP_INCLUDE_DIRS "${LIBZIP_PC_INCLUDE_DIRS}")
|
||||||
|
set(LIBZIP_LIBRARIES "${LIBZIP_PC_LINK_LIBRARIES}")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# ---- 3) FetchContent as a last resort ---------------------------------------
|
||||||
|
if(NOT LIBZIP_FOUND AND LIBZIP_ALLOW_FETCH)
|
||||||
|
include(FetchContent)
|
||||||
|
|
||||||
|
set(BUILD_SHARED_LIBS OFF CACHE BOOL "" FORCE)
|
||||||
|
set(LIBZIP_DO_INSTALL OFF CACHE BOOL "" FORCE)
|
||||||
|
set(ENABLE_BZIP2 OFF CACHE BOOL "" FORCE)
|
||||||
|
set(ENABLE_LZMA OFF CACHE BOOL "" FORCE)
|
||||||
|
set(ENABLE_ZSTD OFF CACHE BOOL "" FORCE)
|
||||||
|
|
||||||
|
FetchContent_Declare(
|
||||||
|
libzip_fetch
|
||||||
|
GIT_REPOSITORY "${LIBZIP_FETCH_GIT_REPO}"
|
||||||
|
GIT_TAG "${LIBZIP_FETCH_GIT_TAG}"
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(libzip_fetch)
|
||||||
|
|
||||||
|
if(NOT TARGET libzip::zip)
|
||||||
|
if(TARGET zip)
|
||||||
|
add_library(libzip::zip ALIAS zip)
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(TARGET libzip::zip)
|
||||||
|
set(LIBZIP_FOUND ON)
|
||||||
|
set(LIBZIP_TARGET libzip::zip)
|
||||||
|
else()
|
||||||
|
message(FATAL_ERROR "libzip fetch succeeded but target 'libzip::zip' (or 'zip') was not created.")
|
||||||
|
endif()
|
||||||
|
endif()
|
||||||
|
|
||||||
|
# Final guard
|
||||||
|
if(NOT LIBZIP_FOUND)
|
||||||
|
message(FATAL_ERROR "libzip not found and fetching is disabled or failed. "
|
||||||
|
"Set LIBZIP_ALLOW_FETCH=ON or install libzip development files.")
|
||||||
|
endif()
|
@@ -4,6 +4,7 @@
|
|||||||
# https://opensource.org/licenses/MIT
|
# https://opensource.org/licenses/MIT
|
||||||
|
|
||||||
find_package(cglm REQUIRED)
|
find_package(cglm REQUIRED)
|
||||||
|
find_package(libzip REQUIRED)
|
||||||
|
|
||||||
# Libs
|
# Libs
|
||||||
target_link_libraries(${DUSK_TARGET_NAME}
|
target_link_libraries(${DUSK_TARGET_NAME}
|
||||||
|
Reference in New Issue
Block a user