Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,8 @@ if(LIBZIP_DO_INSTALL)

# Install Find* modules, they are required by libzip-config.cmake to resolve dependencies
install(FILES
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindBZip2.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindLibLZMA.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindNettle.cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findzstd.cmake
DESTINATION
Expand Down
48 changes: 48 additions & 0 deletions cmake/FindBZip2.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
# - Try to find BZip2
# Once done this will define
#
# BZIP2_FOUND - system has BZip2
# BZIP2_INCLUDE_DIRS - the BZip2 include directory
# BZIP2_LIBRARIES - Link these to use BZip2
# BZIP2_VERSION - The version of the BZip2 library found

find_package(PkgConfig)
pkg_check_modules(PC_BZIP2 QUIET bzip2)

find_path(BZIP2_INCLUDE_DIR bzlib.h
HINTS ${PC_BZIP2_INCLUDEDIR}
PATHS /usr/include /usr/local/include
)

find_library(BZIP2_LIBRARY NAMES bz2
HINTS ${PC_BZIP2_LIBDIR}
PATHS /usr/lib /usr/local/lib /lib
PATH_SUFFIXES x86_64-linux-gnu
)

set(BZIP2_INCLUDE_DIRS ${BZIP2_INCLUDE_DIR})
set(BZIP2_LIBRARIES ${BZIP2_LIBRARY})

if(BZIP2_INCLUDE_DIR AND EXISTS "${BZIP2_INCLUDE_DIR}/bzlib.h")
file(STRINGS "${BZIP2_INCLUDE_DIR}/bzlib.h" BZIP2_VERSION_LINE REGEX "^#define BZ_VERSION[ \t]+\".*\"")
if(BZIP2_VERSION_LINE)
string(REGEX REPLACE "^#define BZ_VERSION[ \t]+\"([0-9.]+).*\"" "\\1" BZIP2_VERSION "${BZIP2_VERSION_LINE}")
endif()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(BZip2
FOUND_VAR BZIP2_FOUND
REQUIRED_VARS BZIP2_LIBRARY BZIP2_INCLUDE_DIR
VERSION_VAR BZIP2_VERSION
)

if(BZIP2_FOUND AND NOT TARGET BZip2::BZip2)
add_library(BZip2::BZip2 UNKNOWN IMPORTED)
set_target_properties(BZip2::BZip2 PROPERTIES
IMPORTED_LOCATION "${BZIP2_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${BZIP2_INCLUDE_DIRS}"
)
endif()

mark_as_advanced(BZIP2_INCLUDE_DIR BZIP2_LIBRARY)
45 changes: 45 additions & 0 deletions cmake/FindLibLZMA.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
# - Try to find LibLZMA
# Once done this will define
#
# LIBLZMA_FOUND - system has LibLZMA
# LIBLZMA_INCLUDE_DIRS - the LibLZMA include directory
# LIBLZMA_LIBRARIES - Link these to use LibLZMA
# LIBLZMA_VERSION - The version of the LibLZMA library found

find_package(PkgConfig)
pkg_check_modules(PC_LIBLZMA QUIET liblzma)

find_path(LIBLZMA_INCLUDE_DIR lzma.h
HINTS ${PC_LIBLZMA_INCLUDEDIR}
)

find_library(LIBLZMA_LIBRARY NAMES lzma
HINTS ${PC_LIBLZMA_LIBDIR}
)

set(LIBLZMA_INCLUDE_DIRS ${LIBLZMA_INCLUDE_DIR})
set(LIBLZMA_LIBRARIES ${LIBLZMA_LIBRARY})

if(LIBLZMA_INCLUDE_DIR AND EXISTS "${LIBLZMA_INCLUDE_DIR}/lzma.h")
file(STRINGS "${LIBLZMA_INCLUDE_DIR}/lzma.h" LIBLZMA_VERSION_LINE REGEX "^#define LZMA_VERSION_STRING[ \t]+\".*\"")
if(LIBLZMA_VERSION_LINE)
string(REGEX REPLACE "^#define LZMA_VERSION_STRING[ \t]+\"([0-9.]+)\"" "\\1" LIBLZMA_VERSION "${LIBLZMA_VERSION_LINE}")
endif()
endif()

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(LibLZMA
FOUND_VAR LIBLZMA_FOUND
REQUIRED_VARS LIBLZMA_LIBRARY LIBLZMA_INCLUDE_DIR
VERSION_VAR LIBLZMA_VERSION
)

if(LIBLZMA_FOUND AND NOT TARGET LibLZMA::LibLZMA)
add_library(LibLZMA::LibLZMA UNKNOWN IMPORTED)
set_target_properties(LibLZMA::LibLZMA PROPERTIES
IMPORTED_LOCATION "${LIBLZMA_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${LIBLZMA_INCLUDE_DIRS}"
)
endif()

mark_as_advanced(LIBLZMA_INCLUDE_DIR LIBLZMA_LIBRARY)
31 changes: 31 additions & 0 deletions cmake/FindZLIB.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# - Find ZLIB
# Find the native ZLIB includes and library.
#
# ZLIB_INCLUDE_DIRS - where to find zlib.h, etc.
# ZLIB_LIBRARIES - List of libraries when using zlib.
# ZLIB_FOUND - True if zlib found.

find_package(PkgConfig)
pkg_check_modules(PC_ZLIB QUIET zlib)

find_path(ZLIB_INCLUDE_DIR zlib.h
HINTS ${PC_ZLIB_INCLUDEDIR} ${PC_ZLIB_INCLUDE_DIRS})

find_library(ZLIB_LIBRARY NAMES z zlib
HINTS ${PC_ZLIB_LIBDIR} ${PC_ZLIB_LIBRARY_DIRS})

set(ZLIB_LIBRARIES ${ZLIB_LIBRARY})
set(ZLIB_INCLUDE_DIRS ${ZLIB_INCLUDE_DIR})

include(FindPackageHandleStandardArgs)
find_package_handle_standard_args(ZLIB DEFAULT_MSG
ZLIB_LIBRARY ZLIB_INCLUDE_DIR)

if(ZLIB_FOUND AND NOT TARGET ZLIB::ZLIB)
add_library(ZLIB::ZLIB UNKNOWN IMPORTED)
set_target_properties(ZLIB::ZLIB PROPERTIES
IMPORTED_LOCATION "${ZLIB_LIBRARY}"
INTERFACE_INCLUDE_DIRECTORIES "${ZLIB_INCLUDE_DIR}")
endif()

mark_as_advanced(ZLIB_INCLUDE_DIR ZLIB_LIBRARY)
7 changes: 6 additions & 1 deletion lib/zip_source_file_stdio.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,20 @@
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <fcntl.h>

#include "zipint.h"

#include "zip_source_file.h"
#include "zip_source_file_stdio.h"

#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>

#if defined(__TINYC__)
#include "compat.h"
#endif

#ifdef _WIN32
#ifndef S_IWUSR
#define S_IWUSR _S_IWRITE
Expand Down
7 changes: 6 additions & 1 deletion lib/zip_source_file_stdio_named.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,18 +31,23 @@
IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#include <fcntl.h>

#include "zipint.h"

#include "zip_source_file.h"
#include "zip_source_file_stdio.h"

#include <fcntl.h>
#include <stdlib.h>
#include <sys/stat.h>
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif

#if defined(__TINYC__)
#include "compat.h"
#endif

#ifdef HAVE_CLONEFILE
#include <sys/attr.h>
#include <sys/clonefile.h>
Expand Down