### Installation Commands Source: https://github.com/nih-at/libzip/blob/main/lib/CMakeLists.txt Commands for installing the library and header files. ```cmake LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}) install(FILES zip.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}) ``` -------------------------------- ### Basic build and installation Source: https://github.com/nih-at/libzip/blob/main/INSTALL.md Standard procedure for building and installing libzip using cmake. ```sh mkdir build cd build cmake .. make make test make install ``` -------------------------------- ### Installation Option Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Option to control the installation of libzip and related files. ```cmake option(LIBZIP_DO_INSTALL "Install libzip and the related files" ON) ``` -------------------------------- ### CMakeLists.txt for libzip Examples Source: https://github.com/nih-at/libzip/blob/main/examples/CMakeLists.txt This CMakeLists.txt file defines how to build several example programs (add-compressed-data, autoclose-archive, in-memory) that utilize the libzip library. ```cmake cmake_minimum_required(VERSION 3.14) foreach(PROGRAM add-compressed-data autoclose-archive in-memory) add_executable(${PROGRAM} ${PROGRAM}.c) target_link_libraries(${PROGRAM} zip) target_include_directories(${PROGRAM} PRIVATE BEFORE ${PROJECT_SOURCE_DIR}/lib ${PROJECT_BINARY_DIR}) endforeach() ``` -------------------------------- ### Installation Rules Source: https://github.com/nih-at/libzip/blob/main/man/CMakeLists.txt Conditional installation rules for man pages or HTML documentation based on project configuration. ```cmake INSTALL(FILES ${PROJECT_BINARY_DIR}/man/${SOURCE}.3 DESTINATION ${CMAKE_INSTALL_DOCDIR}/${PROJECT_NAME} RENAME ${TARGET}.html) else() INSTALL(FILES ${PROJECT_BINARY_DIR}/man/${SOURCE}.3 DESTINATION ${CMAKE_INSTALL_MANDIR}/man3 RENAME ${TARGET}.3) endif() endif() endif() endforeach() ``` -------------------------------- ### Installation Rules Source: https://github.com/nih-at/libzip/blob/main/lib/CMakeLists.txt Defines installation rules for the zip target if LIBZIP_DO_INSTALL is enabled. ```cmake if(LIBZIP_DO_INSTALL) install(TARGETS zip EXPORT ${PROJECT_NAME}-targets RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} INCLUDES DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} ) ``` -------------------------------- ### Installation of Find Modules Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Installs FindNettle.cmake and Findzstd.cmake modules required by libzip-config.cmake. ```cmake if(LIBZIP_DO_INSTALL) install( FILES ${CMAKE_CURRENT_SOURCE_DIR}/cmake/FindNettle.cmake ${CMAKE_CURRENT_SOURCE_DIR}/cmake/Findzstd.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libzip/modules ) endif() ``` -------------------------------- ### CMakeLists.txt Source: https://github.com/nih-at/libzip/blob/main/examples/cmake-project/CMakeLists.txt The main CMake configuration file for the project. ```cmake cmake_minimum_required(VERSION 3.5) project(cmake-example VERSION 1.0 LANGUAGES C) find_package(libzip 1.10 REQUIRED) add_executable(cmake-example cmake-example.c) target_link_libraries(cmake-example PRIVATE libzip::zip) ``` -------------------------------- ### Fuzzing Programs Setup Source: https://github.com/nih-at/libzip/blob/main/ossfuzz/CMakeLists.txt Defines the list of fuzzing programs and configures each executable, including source files, include directories, and linked libraries. ```cmake set(FUZZ_PROGRAMS zip_read_file_fuzzer zip_read_fuzzer zip_write_encrypt_aes256_file_fuzzer zip_write_encrypt_pkware_file_fuzzer ) foreach(PROGRAM IN LISTS FUZZ_PROGRAMS) add_executable(${PROGRAM} ${PROGRAM}.c) target_sources(${PROGRAM} PRIVATE fuzz_main.c) target_include_directories(${PROGRAM} PRIVATE BEFORE ${PROJECT_SOURCE_DIR}/lib ${PROJECT_BINARY_DIR}) target_link_libraries(${PROGRAM} zip) endforeach() add_custom_target(list-fuzzers COMMAND echo FUZZERS: ${FUZZ_PROGRAMS} ) ``` -------------------------------- ### Compiling with custom CFLAGS Source: https://github.com/nih-at/libzip/blob/main/INSTALL.md Example of setting custom CFLAGS in the environment before running cmake. ```sh CFLAGS=-DMY_CUSTOM_FLAG cmake .. ``` -------------------------------- ### Example of reporting errors during zip_open Source: https://github.com/nih-at/libzip/blob/main/man/zip_open.html This example demonstrates how to handle potential errors when opening a zip archive using zip_open. ```c #include #include // Assuming progname and name are defined elsewhere // extern const char *progname; // const char *name = "myarchive.zip"; zip_t *za; int err; if ((za = zip_open(name, 0, &err)) == NULL) { zip_error_t error; zip_error_init_with_code(&error, err); fprintf(stderr, "%s: cannot open zip archive '%s': %s\n", progname, name, zip_error_strerror(&error)); zip_error_fini(&error); return -1; } // Proceed with archive operations if successful... ``` -------------------------------- ### Subdirectories Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Adds subdirectories for lib, man, src, regress, ossfuzz, and examples based on build options. ```cmake ADD_SUBDIRECTORY(lib) if(BUILD_DOC) ADD_SUBDIRECTORY(man) endif() if(BUILD_TOOLS) ADD_SUBDIRECTORY(src) else(BUILD_TOOLS) if(BUILD_REGRESS) message(WARNING "-- tools build has been disabled, but they are needed for regression tests; regression testing disabled") set(BUILD_REGRESS OFF) endif(BUILD_REGRESS) endif() find_program(NIHTEST nihtest) if(BUILD_REGRESS AND NOT NIHTEST) message(WARNING "-- nihtest not found, regression testing disabled") set(BUILD_REGRESS OFF) endif() if(BUILD_REGRESS) include(CTest) add_subdirectory(regress) endif() if(BUILD_OSSFUZZ) add_subdirectory(ossfuzz) endif() if(BUILD_EXAMPLES) add_subdirectory(examples) endif() ``` -------------------------------- ### zip_file_add example Source: https://github.com/nih-at/libzip/blob/main/man/zip_file_add.html Example demonstrating how to add a file to a zip archive using zip_file_add. ```c zip_source_t *s; const char buf[]="teststring"; if ((s=zip_source_buffer(archive, buf, sizeof(buf), 0)) == NULL || zip_file_add(archive, name, s, ZIP_FL_ENC_UTF_8) < 0) { zip_source_free(s); printf("error adding file: %s\n", zip_strerror(archive)); } ``` -------------------------------- ### RPATH Handling Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Configures CMAKE_INSTALL_RPATH for non-Linux and non-OHOS systems to include the installation directory's lib directory. ```cmake if((NOT CMAKE_SYSTEM_NAME MATCHES Linux) AND (NOT CMAKE_SYSTEM_NAME MATCHES OHOS)) set(CMAKE_INSTALL_RPATH ${CMAKE_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}) set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE) endif() ``` -------------------------------- ### zip_source_zip_file usage Source: https://github.com/nih-at/libzip/blob/main/API-CHANGES.md Example of how to use zip_source_zip_file to get compressed data for the whole file. ```C zip_source_zip_file(za, source_archive, source_index, ZIP_FL_COMPRESSED, 0, -1, NULL) ``` -------------------------------- ### Include Directories Source: https://github.com/nih-at/libzip/blob/main/lib/CMakeLists.txt Configures public include directories for the zip library, including build and install paths. ```cmake target_include_directories(zip PUBLIC $ $ $ ) ``` -------------------------------- ### Recommended Replacement Source: https://github.com/nih-at/libzip/blob/main/man/zip_error_get_sys_type.html Example of the recommended replacement for zip_error_get_sys_type using zip_error_init_with_code and zip_error_system_type. ```c zip_error_t error; zip_error_init_with_code(&error, ze); int i = zip_error_system_type(&error); ``` -------------------------------- ### Man Page List and Processing Source: https://github.com/nih-at/libzip/blob/main/man/CMakeLists.txt Defines a list of man pages and iterates through them to set up custom commands for generating HTML and man file formats, and conditionally installs them. ```cmake set(MAN_PAGES ZIP_SOURCE_GET_ARGS.3 libzip.3 zip.5 zip_add.3 zip_add_dir.3 zip_close.3 zip_compression_method_supported.3 zip_delete.3 zip_dir_add.3 zip_discard.3 zip_encryption_method_supported.3 zip_error.5 zip_error_clear.3 zip_error_code_system.3 zip_error_code_zip.3 zip_error_fini.3 zip_error_get.3 zip_error_get_sys_type.3 zip_error_init.3 zip_error_set.3 zip_error_set_from_source.3 zip_error_strerror.3 zip_error_system_type.3 zip_error_to_data.3 zip_error_to_str.3 zip_errors.3 zip_fclose.3 zip_fdopen.3 zip_file.5 zip_file_add.3 zip_file_attributes_init.3 zip_file_extra_field_delete.3 zip_file_extra_field_get.3 zip_file_extra_field_set.3 zip_file_extra_fields_count.3 zip_file_get_comment.3 zip_file_get_error.3 zip_file_get_external_attributes.3 zip_file_rename.3 zip_file_set_comment.3 zip_file_set_encryption.3 zip_file_set_external_attributes.3 zip_file_set_mtime.3 zip_file_strerror.3 zip_fopen.3 zip_fopen_encrypted.3 zip_fread.3 zip_fseek.3 zip_ftell.3 zip_get_archive_comment.3 zip_get_archive_flag.3 zip_get_error.3 zip_get_file_comment.3 zip_get_name.3 zip_get_num_entries.3 zip_get_num_files.3 zip_libzip_version.3 zip_name_locate.3 zip_open.3 zip_register_cancel_callback_with_state.3 zip_register_progress_callback.3 zip_register_progress_callback_with_state.3 zip_rename.3 zip_set_archive_comment.3 zip_set_archive_flag.3 zip_set_default_password.3 zip_set_file_comment.3 zip_set_file_compression.3 zip_source.5 zip_source_begin_write.3 zip_source_buffer.3 zip_source_buffer_fragment.3 zip_source_close.3 zip_source_commit_write.3 zip_source_error.3 zip_source_file.3 zip_source_filep.3 zip_source_free.3 zip_source_function.3 zip_source_is_deleted.3 zip_source_is_seekable.3 zip_source_layered.3 zip_source_keep.3 zip_source_make_command_bitmap.3 zip_source_open.3 zip_source_read.3 zip_source_rollback_write.3 zip_source_seek.3 zip_source_seek_compute_offset.3 zip_source_seek_write.3 zip_source_stat.3 zip_source_tell.3 zip_source_tell_write.3 zip_source_win32a.3 zip_source_win32handle.3 zip_source_win32w.3 zip_source_window_create.3 zip_source_write.3 zip_source_zip.3 zip_source_zip_file.3 zip_stat.3 zip_stat_init.3 zip_unchange.3 zip_unchange_all.3 zip_unchange_archive.3 zipcmp.1 zipmerge.1 ziptool.1 ) foreach(MAN_PAGE ${MAN_PAGES}) string(REGEX REPLACE "[1-9]$" "${DOCUMENTATION_FORMAT}" SOURCE_FILE ${MAN_PAGE}) if(LIBZIP_DO_INSTALL) if (DOCUMENTATION_FORMAT MATCHES "html") install(FILES ${PROJECT_BINARY_DIR}/man/${MAN_PAGE} DESTINATION ${CMAKE_INSTALL_DOCDIR}/${PROJECT_NAME} RENAME ${SOURCE_FILE}) else() string(REGEX REPLACE ".*(.)$" "man\\1" SUBDIR ${MAN_PAGE}) install(FILES ${PROJECT_BINARY_DIR}/man/${MAN_PAGE} DESTINATION ${CMAKE_INSTALL_MANDIR}/${SUBDIR}) endif() endif() # configure_file does not find out about updates to the sources, and it does not provide a target #configure_file(${SOURCE_FILE} ${MAN_PAGE} COPYONLY) add_custom_command(OUTPUT ${MAN_PAGE} DEPENDS ${SOURCE_FILE} COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE} ${CMAKE_CURRENT_BINARY_DIR}/${MAN_PAGE} COMMENT "Preparing ${MAN_PAGE}" ) string(REGEX REPLACE "[1-9]$" "html" HTML_FILE ${MAN_PAGE}) string(REGEX REPLACE "[1-9]$" "man" MAN_FILE ${MAN_PAGE}) string(REGEX REPLACE "[1-9]$" "mdoc" MDOC_FILE ${MAN_PAGE}) # html re-generation add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${HTML_FILE} DEPENDS ${MDOC_FILE} COMMAND ${CMAKE_COMMAND} -DIN=${CMAKE_CURRENT_SOURCE_DIR}/${MDOC_FILE} -DOUT=${CMAKE_CURRENT_BINARY_DIR}/${HTML_FILE} -P ${CMAKE_CURRENT_SOURCE_DIR}/update-html.cmake COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${HTML_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/${HTML_FILE} ) list(APPEND UPDATEHTML ${CMAKE_CURRENT_BINARY_DIR}/${HTML_FILE}) # man re-generation add_custom_command(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${MAN_FILE} DEPENDS ${MDOC_FILE} COMMAND ${CMAKE_COMMAND} -DIN=${CMAKE_CURRENT_SOURCE_DIR}/${MDOC_FILE} -DOUT=${CMAKE_CURRENT_BINARY_DIR}/${MAN_FILE} -P ${CMAKE_CURRENT_SOURCE_DIR}/update-man.cmake COMMAND ${CMAKE_COMMAND} -E copy_if_different ${CMAKE_CURRENT_BINARY_DIR}/${MAN_FILE} ${CMAKE_CURRENT_SOURCE_DIR}/${MAN_FILE} ) list(APPEND UPDATEMAN ${CMAKE_CURRENT_BINARY_DIR}/${MAN_FILE}) endforeach() add_custom_target(man ALL DEPENDS ${MAN_PAGES}) add_custom_target(update-man DEPENDS ${UPDATEMAN}) add_custom_target(update-html DEPENDS ${UPDATEHTML}) file(STRINGS links MANPAGE_LINKS) foreach(LINKS_LINE ${MANPAGE_LINKS}) if(${LINKS_LINE} MATCHES "(.*) (.*)") set(SOURCE ${CMAKE_MATCH_1}) set(TARGET ${CMAKE_MATCH_2}) if(LIBZIP_DO_INSTALL) if (DOCUMENTATION_FORMAT MATCHES "html") ``` -------------------------------- ### Archive Prefix Functions Source: https://github.com/nih-at/libzip/blob/main/TODO.md Functions for setting and getting an archive prefix, potentially for self-extracting archives. ```c zip_set_archive_prefix(struct zip *za, const zip_uint8_t *data, zip_uint64_t length); const zip_uint8_t *zip_get_archive_prefix(struct zip *za, zip_uint64_t *lengthp); ``` -------------------------------- ### Configuration Files Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Configures config.h and zipconf.h from their respective template files. ```cmake configure_file(${CMAKE_CURRENT_SOURCE_DIR}/config.h.in ${PROJECT_BINARY_DIR}/config.h) configure_file(${CMAKE_CURRENT_SOURCE_DIR}/zipconf.h.in ${PROJECT_BINARY_DIR}/zipconf.h) ``` -------------------------------- ### Pkgconfig File Generation Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Generates the libzip.pc file, setting variables for prefix, bindir, libdir, and includedir, and handling library linking. ```cmake file(RELATIVE_PATH pc_relative_bindir ${CMAKE_INSTALL_PREFIX} ${CMAKE_INSTALL_FULL_BINDIR}) set(bindir "\${prefix}/${pc_relative_bindir}") file(RELATIVE_PATH pc_relative_libdir ${CMAKE_INSTALL_PREFIX} ${CMAKE_INSTALL_FULL_LIBDIR}) set(libdir "\${prefix}/${pc_relative_libdir}") file(RELATIVE_PATH pc_relative_includedir ${CMAKE_INSTALL_PREFIX} ${CMAKE_INSTALL_FULL_INCLUDEDIR}) set(includedir "\${prefix}/${pc_relative_includedir}") if(CMAKE_SYSTEM_NAME MATCHES BSD) set(PKG_CONFIG_RPATH "-Wl,-R\${libdir}") endif(CMAKE_SYSTEM_NAME MATCHES BSD) get_target_property(LIBS_PRIVATE zip LINK_LIBRARIES) foreach(LIB ${LIBS_PRIVATE}) if(LIB MATCHES ")/") get_filename_component(LIB ${LIB} NAME_WE) string(REGEX REPLACE "^lib" "" LIB ${LIB}) endif() set(LIBS "${LIBS} -l${LIB}") endforeach() STRING(CONCAT zlib_link_name "-l" ${ZLIB_LINK_LIBRARY_NAME}) string(REGEX REPLACE "-lBZip2::BZip2" "-lbz2" LIBS ${LIBS}) string(REGEX REPLACE "-lLibLZMA::LibLZMA" "-llzma" LIBS ${LIBS}) if(zstd_TARGET) string(REGEX REPLACE "-l${zstd_TARGET}" "-lzstd" LIBS ${LIBS}) endif() string(REGEX REPLACE "-lOpenSSL::Crypto" "-lssl -lcrypto" LIBS ${LIBS}) string(REGEX REPLACE "-lZLIB::ZLIB" ${zlib_link_name} LIBS ${LIBS}) string(REGEX REPLACE "-lGnuTLS::GnuTLS" "-lgnutls" LIBS ${LIBS}) string(REGEX REPLACE "-lNettle::Nettle" "-lnettle" LIBS ${LIBS}) configure_file(libzip.pc.in libzip.pc @ONLY) if(LIBZIP_DO_INSTALL) install(FILES ${PROJECT_BINARY_DIR}/libzip.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) endif() ``` -------------------------------- ### Deprecated Usage Source: https://github.com/nih-at/libzip/blob/main/man/zip_error_get_sys_type.html Example of the deprecated way to use zip_error_get_sys_type. ```c #include int i = zip_error_get_sys_type(ze); ``` -------------------------------- ### Enabling test suite code coverage Source: https://github.com/nih-at/libzip/blob/main/INSTALL.md Instructions to enable code coverage collection during the build and testing process. ```sh make coverage ``` -------------------------------- ### Project Definition Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Defines the project name, version, and languages. ```cmake project(libzip VERSION 1.11.4 LANGUAGES C) ``` -------------------------------- ### Testing Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Enables testing for the project. ```cmake ENABLE_TESTING() ``` -------------------------------- ### Example: Convert DOS attributes to mode_t Source: https://github.com/nih-at/libzip/blob/main/man/zip_file_get_external_attributes.html This code snippet demonstrates how to convert external attributes for the DOS operating system into a POSIX mode_t value. ```c #include #define FA_RDONLY 0x01 // FILE_ATTRIBUTE_READONLY #define FA_DIREC 0x10 // FILE_ATTRIBUTE_DIRECTORY static mode_t _zip_dos_attr2mode(zip_uint32_t attr) { mode_t m = S_IRUSR | S_IRGRP | S_IROTH; if (0 == (attr & FA_RDONLY)) m |= S_IWUSR | S_IWGRP | S_IWOTH; if (attr & FA_DIREC) m = (S_IFDIR | (m & ~S_IFMT)) | S_IXUSR | S_IXGRP | S_IXOTH; return m; } ``` -------------------------------- ### Function Signatures Source: https://github.com/nih-at/libzip/blob/main/man/zip_source_win32handle.html The C function signatures for creating a zip source from a Windows file handle. ```c #include zip_source_t * `zip_source_win32handle`(zip_t *archive, HANDLE h, zip_uint64_t start, zip_int64_t len); zip_source_t * `zip_source_win32handle_create`(HANDLE h, zip_uint64_t start, zip_int64_t len, zip_error_t *error); ``` -------------------------------- ### Synopsis for zip_source_begin_write_cloning Source: https://github.com/nih-at/libzip/blob/main/man/zip_source_begin_write.html The C function signature for zip_source_begin_write_cloning. ```c #include int zip_source_begin_write_cloning(zip_source_t *source, zip_uint64_t offset); ``` -------------------------------- ### Synopsis Source: https://github.com/nih-at/libzip/blob/main/man/zip_libzip_version.html The synopsis shows the function signature and the header file required to use zip_libzip_version. ```c #include const char * `zip_libzip_version`(void); ``` -------------------------------- ### Synopsis for zip_source_begin_write Source: https://github.com/nih-at/libzip/blob/main/man/zip_source_begin_write.html The C function signature for zip_source_begin_write. ```c #include int zip_source_begin_write(zip_source_t *source); ``` -------------------------------- ### Package Configuration File Generation Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Generates the package configuration file and version file for CMake. ```cmake include(CMakePackageConfigHelpers) write_basic_package_version_file("${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config-version.cmake" COMPATIBILITY AnyNewerVersion) if(LIBZIP_DO_INSTALL) configure_package_config_file("${PROJECT_NAME}-config.cmake.in" "${PROJECT_BINARY_DIR}/${PROJECT_NAME}-config.cmake" INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libzip) endif() ``` -------------------------------- ### Code Completion Frameworks Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Enables CMAKE_EXPORT_COMPILE_COMMANDS for code completion frameworks. ```cmake set(CMAKE_EXPORT_COMPILE_COMMANDS ON) ``` -------------------------------- ### Synopsis Source: https://github.com/nih-at/libzip/blob/main/man/zip_compression_method_supported.html The function signature for zip_compression_method_supported. ```c #include int zip_compression_method_supported(zip_int32_t method, int compress); ``` -------------------------------- ### Coverage Options Source: https://github.com/nih-at/libzip/blob/main/lib/CMakeLists.txt Enables coverage compilation and linking options if ENABLE_COVERAGE is set. ```cmake if (ENABLE_COVERAGE) target_compile_options(zip PRIVATE -coverage) target_link_options(zip PRIVATE -coverage) endif() ``` -------------------------------- ### Function Signature Source: https://github.com/nih-at/libzip/blob/main/man/zip_source_make_command_bitmap.html The C function signature for zip_source_make_command_bitmap. ```c #include zip_int64_t zip_source_make_command_bitmap(zip_source_cmd_t command, ...); ``` -------------------------------- ### SYNOPSIS Source: https://github.com/nih-at/libzip/blob/main/man/zip_source_filep.html Synopsis for zip_source_filep and zip_source_filep_create functions. ```c #include zip_source_t * `zip_source_filep`(zip_t *archive, FILE *file, zip_uint64_t start, zip_int64_t len); zip_source_t * `zip_source_filep_create`(FILE *file, zip_uint64_t start, zip_int64_t len, zip_error_t *error); ``` -------------------------------- ### Shared Libraries Option Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Option to control building shared libraries. ```cmake option(BUILD_SHARED_LIBS "Build shared libraries" ON) ``` -------------------------------- ### Shared Library Versioning Option Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Option to add SO versioning for shared libraries. ```cmake option(SHARED_LIB_VERSIONNING "Add SO version in .so build" ON) ``` -------------------------------- ### ZLIB Find Package Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Finds the ZLIB package and sets up library name overrides. ```cmake find_package(ZLIB 1.1.2 REQUIRED) # so developers on systems where zlib is named differently (Windows, sometimes) # can override the name used in the pkg-config file if (NOT ZLIB_LINK_LIBRARY_NAME) set(ZLIB_LINK_LIBRARY_NAME "z") # Get the correct name in common cases list(LENGTH ZLIB_LIBRARIES N_ZLIB_LIBRARIES) if(N_ZLIB_LIBRARIES EQUAL 1) set(ZLIB_FILENAME ${ZLIB_LIBRARIES}) elseif(N_ZLIB_LIBRARIES EQUAL 4) # ZLIB_LIBRARIES might have the target_link_library() format like # "optimized;path/to/zlib.lib;debug;path/to/zlibd.lib". Use the 'optimized' # case unless we know we are in a Debug build. if(CMAKE_BUILD_TYPE STREQUAL "Debug") list(FIND ZLIB_LIBRARIES "debug" ZLIB_LIBRARIES_INDEX_OF_CONFIG) else() list(FIND ZLIB_LIBRARIES "optimized" ZLIB_LIBRARIES_INDEX_OF_CONFIG) endif() if(ZLIB_LIBRARIES_INDEX_OF_CONFIG GREATER_EQUAL 0) math(EXPR ZLIB_FILENAME_INDEX "${ZLIB_LIBRARIES_INDEX_OF_CONFIG}+1") list(GET ZLIB_LIBRARIES ${ZLIB_FILENAME_INDEX} ZLIB_FILENAME) endif() endif() if(ZLIB_FILENAME) get_filename_component(ZLIB_FILENAME ${ZLIB_FILENAME} NAME_WE) string(REGEX REPLACE "^lib" "" ZLIB_LINK_LIBRARY_NAME ${ZLIB_FILENAME}) endif() endif(NOT ZLIB_LINK_LIBRARY_NAME) ``` -------------------------------- ### Synopsis Source: https://github.com/nih-at/libzip/blob/main/man/zip_error_init.html Function signatures for zip_error_init and zip_error_init_with_code. ```c #include void zip_error_init(zip_error_t *error); void zip_error_init_with_code(zip_error_t *error, int ze); ``` -------------------------------- ### Documentation Format Detection Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Detects the available tool for generating documentation (mdoc, man, or html). ```cmake find_program(MDOCTOOL NAMES mandoc groff) if (MDOCTOOL) set(DOCUMENTATION_FORMAT "mdoc" CACHE STRING "Documentation format") else() find_program(MANTOOL NAMES nroff) if (MANTOOL) set(DOCUMENTATION_FORMAT "man" CACHE STRING "Documentation format") else() set(DOCUMENTATION_FORMAT "html" CACHE STRING "Documentation format") endif() endif() ``` -------------------------------- ### Coverage Build Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Finds lcov and genhtml if ENABLE_COVERAGE is set. ```cmake if(ENABLE_COVERAGE) find_program(LCOV lcov REQUIRED) find_program(GENHTML genhtml REQUIRED) endif() ``` -------------------------------- ### Synopsis Source: https://github.com/nih-at/libzip/blob/main/man/zip_source_buffer_fragment.html Function signatures for creating a zip source from buffer fragments. ```c #include zip_source_t * `zip_source_buffer_fragment`(zip_t *archive, zip_buffer_fragment_t *fragments, zip_uint64_t nfragments, int freep); zip_source_t * `zip_source_buffer_fragment_create`(zip_buffer_fragment_t *fragments, zip_uint64_t nfragments, int freep, zip_error_t *error); ``` -------------------------------- ### Function Signatures Source: https://github.com/nih-at/libzip/blob/main/man/zip_source_file.html The C function signatures for zip_source_file and zip_source_file_create. ```c #include zip_source_t * `zip_source_file`(zip_t *archive, const char *fname, zip_uint64_t start, zip_int64_t len); zip_source_t * `zip_source_file_create`(const char *fname, zip_uint64_t start, zip_int64_t len, zip_error_t *error); ``` -------------------------------- ### Main Library Target Source: https://github.com/nih-at/libzip/blob/main/lib/CMakeLists.txt Defines the main 'zip' library target and its source files. ```cmake add_library(zip zip_add.c zip_add_dir.c zip_add_entry.c zip_algorithm_deflate.c zip_buffer.c zip_close.c zip_delete.c zip_dir_add.c zip_dirent.c zip_discard.c zip_entry.c zip_error.c zip_error_clear.c zip_error_get.c zip_error_get_sys_type.c zip_error_strerror.c zip_error_to_str.c zip_extra_field.c zip_extra_field_api.c zip_fclose.c zip_fdopen.c zip_file_add.c zip_file_error_clear.c zip_file_error_get.c zip_file_get_comment.c zip_file_get_external_attributes.c zip_file_get_offset.c zip_file_rename.c zip_file_replace.c zip_file_set_comment.c zip_file_set_encryption.c zip_file_set_external_attributes.c zip_file_set_mtime.c zip_file_strerror.c zip_fopen.c zip_fopen_encrypted.c zip_fopen_index.c zip_fopen_index_encrypted.c zip_fread.c zip_fseek.c zip_ftell.c zip_get_archive_comment.c zip_get_archive_flag.c zip_get_encryption_implementation.c zip_get_file_comment.c zip_get_name.c zip_get_num_entries.c zip_get_num_files.c zip_hash.c zip_io_util.c zip_libzip_version.c zip_memdup.c zip_name_locate.c zip_new.c zip_open.c zip_pkware.c zip_progress.c zip_realloc.c zip_rename.c zip_replace.c zip_set_archive_comment.c zip_set_archive_flag.c zip_set_default_password.c zip_set_file_comment.c zip_set_file_compression.c zip_set_name.c zip_source_accept_empty.c zip_source_begin_write.c zip_source_begin_write_cloning.c zip_source_buffer.c zip_source_call.c zip_source_close.c zip_source_commit_write.c zip_source_compress.c zip_source_crc.c zip_source_error.c zip_source_file_common.c zip_source_file_stdio.c zip_source_free.c zip_source_function.c zip_source_get_dostime.c zip_source_get_file_attributes.c zip_source_is_deleted.c zip_source_layered.c zip_source_open.c zip_source_pass_to_lower_layer.c zip_source_pkware_decode.c zip_source_pkware_encode.c zip_source_read.c zip_source_remove.c zip_source_rollback_write.c zip_source_seek.c zip_source_seek_write.c zip_source_stat.c zip_source_supports.c zip_source_tell.c zip_source_tell_write.c zip_source_window.c zip_source_write.c zip_source_zip.c zip_source_zip_new.c zip_stat.c zip_stat_index.c zip_stat_init.c zip_strerror.c zip_string.c zip_unchange.c zip_unchange_all.c zip_unchange_archive.c zip_unchange_data.c zip_utf-8.c ${CMAKE_CURRENT_BINARY_DIR}/zip_err_str.c ) add_library(libzip::zip ALIAS zip) ``` -------------------------------- ### zip_source_win32w and zip_source_win32w_create Synopsis Source: https://github.com/nih-at/libzip/blob/main/man/zip_source_win32w.html The synopsis shows the function signatures for creating a zip source from a Windows Unicode file name. ```c #include zip_source_t * zip_source_win32w(zip_t *archive, const wchar_t *fname, zip_uint64_t start, zip_int64_t len); zip_source_t * zip_source_win32w_create(const wchar_t *fname, zip_uint64_t start, zip_int64_t len, zip_error_t *error); ``` -------------------------------- ### Secure Library Functions Check Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Requests ISO C secure library functions. ```cmake list(APPEND CMAKE_REQUIRED_DEFINITIONS -D__STDC_WANT_LIB_EXT1__=1) ``` -------------------------------- ### Function Signature Source: https://github.com/nih-at/libzip/blob/main/man/zip_source_window_create.html The C function signature for zip_source_window_create. ```c #include zip_source_t * `zip_source_window_create`(zip_source_t *source, zip_uint64_t start, zip_int64_t len, zip_error_t *error); ``` -------------------------------- ### Function Signatures Source: https://github.com/nih-at/libzip/blob/main/man/zip_source_zip_file.html The C function signatures for creating a zip source from a zip file. ```c #include zip_source_t * `zip_source_zip_file`(zip_t *archive, zip_t *srcarchive, zip_uint64_t srcidx, zip_flags_t flags, zip_uint64_t start, zip_int64_t length, const char *password); zip_source_t * `zip_source_zip_file_create`(zip_t *srcarchive, zip_uint64_t srcidx, zip_flags_t flags, zip_uint64_t start, zip_int64_t length, const char *password, zip_error_t *error); ``` -------------------------------- ### CMake Minimum Required Version Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Specifies the minimum required CMake version for the project. ```cmake cmake_minimum_required(VERSION 3.14) ``` -------------------------------- ### Uninstall Target (Commented Out) Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt A commented-out custom target for uninstallation. ```cmake #ADD_CUSTOM_TARGET(uninstall # COMMAND cat ${PROJECT_BINARY_DIR}/install_manifest.txt | xargs rm # WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR} # ) ``` -------------------------------- ### Synopsis Source: https://github.com/nih-at/libzip/blob/main/man/zip_fopen.html Function signatures for zip_fopen and zip_fopen_index. ```c #include zip_file_t * zip_fopen(zip_t *archive, const char *fname, zip_flags_t flags); zip_file_t * zip_fopen_index(zip_t *archive, zip_uint64_t index, zip_flags_t flags); ``` -------------------------------- ### Windows Platform Specific Definitions Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Adds compile definitions for Windows Phone or Windows Store builds. ```cmake if(WIN32) if(CMAKE_SYSTEM_NAME MATCHES WindowsPhone OR CMAKE_SYSTEM_NAME MATCHES WindowsStore) add_compile_definitions(MS_UWP) endif(CMAKE_SYSTEM_NAME MATCHES WindowsPhone OR CMAKE_SYSTEM_NAME MATCHES WindowsStore) endif(WIN32) ``` -------------------------------- ### Distribute Package Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Includes the Dist module for package distribution. ```cmake include(Dist) Dist(${CMAKE_PROJECT_NAME}-${CMAKE_PROJECT_VERSION}) ``` -------------------------------- ### LibLZMA Find Package Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Finds the LibLZMA package if enabled. ```cmake if(ENABLE_LZMA) find_package(LibLZMA 5.2) if(LIBLZMA_FOUND) set(HAVE_LIBLZMA 1) else() message(WARNING "-- lzma library not found; lzma/xz support disabled") endif(LIBLZMA_FOUND) endif(ENABLE_LZMA) ``` -------------------------------- ### SYNOPSIS Source: https://github.com/nih-at/libzip/blob/main/man/zip_source_layered.html Synopsis for zip_source_layered and zip_source_layered_create. ```c #include zip_source_t * `zip_source_layered`(zip_t *archive, zip_source_t *source, zip_source_layered_callback fn, void *userdata); zip_source_t * `zip_source_layered_create`(zip_source_t *source, zip_source_layered_callback fn, void *userdata, zip_error_t *error); ``` -------------------------------- ### Shared Library Versioning Source: https://github.com/nih-at/libzip/blob/main/lib/CMakeLists.txt Sets version properties for the shared library, including SOVERSION and MACHO versions. ```cmake if(SHARED_LIB_VERSIONNING) # MACHO_*_VERSION can be removed when SOVERSION gets increased. Cf #405 set_target_properties(zip PROPERTIES VERSION 5.5 SOVERSION 5 MACHO_CURRENT_VERSION 6.5 MACHO_COMPATIBILITY_VERSION 6) endif() ``` -------------------------------- ### BZip2 Find Package Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Finds the BZip2 package if enabled. ```cmake if(ENABLE_BZIP2) find_package(BZip2) if(BZIP2_FOUND) set(HAVE_LIBBZ2 1) else() message(WARNING "-- bzip2 library not found; bzip2 support disabled") endif(BZIP2_FOUND) endif(ENABLE_BZIP2) ``` -------------------------------- ### Zstandard Find Package Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Finds the zstd package if enabled. ```cmake if(ENABLE_ZSTD) find_package(zstd 1.4.0) if(zstd_FOUND) set(HAVE_LIBZSTD 1) if(TARGET zstd::libzstd_shared AND BUILD_SHARED_LIBS) set(zstd_TARGET zstd::libzstd_shared) else() set(zstd_TARGET zstd::libzstd_static) endif() else() message(WARNING "-- zstd library not found; zstandard support disabled") endif(zstd_FOUND) endif(ENABLE_ZSTD) ``` -------------------------------- ### Windows Specific Sources Source: https://github.com/nih-at/libzip/blob/main/lib/CMakeLists.txt Adds Windows-specific source files and link libraries when building on Windows. ```cmake if(WIN32) target_compile_definitions(zip PRIVATE WIN32_LEAN_AND_MEAN) target_sources(zip PRIVATE zip_source_file_win32.c zip_source_file_win32_named.c zip_source_file_win32_utf16.c zip_source_file_win32_utf8.c ) if(CMAKE_SYSTEM_NAME MATCHES WindowsPhone OR CMAKE_SYSTEM_NAME MATCHES WindowsStore) target_sources(zip PRIVATE zip_random_uwp.c) else() target_sources(zip PRIVATE zip_source_file_win32_ansi.c zip_random_win32.c) target_link_libraries(zip PRIVATE advapi32) endif() else(WIN32) target_sources(zip PRIVATE zip_source_file_stdio_named.c zip_random_unix.c ) endif(WIN32) ``` -------------------------------- ### FTS Header Check Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Checks for the existence of fts_open function and the fts library. ```cmake if(HAVE_FTS_H) check_function_exists(fts_open HAVE_FTS_OPEN) if(NOT HAVE_FTS_OPEN) check_library_exists(fts fts_open "" HAVE_LIB_FTS) else(NOT HAVE_FTS_OPEN) set(HAVE_LIB_FTS "" CACHE INTERNAL "") endif(NOT HAVE_FTS_OPEN) else(HAVE_FTS_H) set(HAVE_LIB_FTS "" CACHE INTERNAL "") endif(HAVE_FTS_H) if(HAVE_LIB_FTS) set(FTS_LIB fts CACHE INTERNAL "") else() set(FTS_LIB "" CACHE INTERNAL "") endif() ``` -------------------------------- ### ZIP_SOURCE_GET_ARGS Macro Signature Source: https://github.com/nih-at/libzip/blob/main/man/ZIP_SOURCE_GET_ARGS.html The synopsis shows the include directive and the type signature for the ZIP_SOURCE_GET_ARGS macro. ```c #include type * `ZIP_SOURCE_GET_ARGS`(type, void *data, zip_uint64_t len, zip_error_t *error); ``` -------------------------------- ### Feature Options Source: https://github.com/nih-at/libzip/blob/main/CMakeLists.txt Defines boolean options for enabling various features and libraries. ```cmake option(ENABLE_COMMONCRYPTO "Enable use of CommonCrypto" ON) option(ENABLE_GNUTLS "Enable use of GnuTLS" ON) option(ENABLE_OPENSSL "Enable use of OpenSSL" ON) option(ENABLE_WINDOWS_CRYPTO "Enable use of Windows cryptography libraries" ON) option(ENABLE_BZIP2 "Enable use of BZip2" ON) option(ENABLE_LZMA "Enable use of LZMA" ON) option(ENABLE_ZSTD "Enable use of Zstandard" ON) option(ENABLE_FDOPEN "Enable zip_fdopen, which is not allowed in Microsoft CRT secure libraries" ON) option(ENABLE_COVERAGE "Enable code coverage reporting of test suite" OFF) option(BUILD_TOOLS "Build tools in the src directory (zipcmp, zipmerge, ziptool)" ON) option(BUILD_REGRESS "Build regression tests" ON) option(BUILD_OSSFUZZ "Build fuzzers for ossfuzz" ON) option(BUILD_EXAMPLES "Build examples" ON) option(BUILD_DOC "Build documentation" ON) ```