diff --git a/CMakeLists.txt b/CMakeLists.txt index 0999294..9f965d3 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,11 @@ -cmake_minimum_required(VERSION 3.12.0) +cmake_minimum_required(VERSION 3.16.0) -project(libzippp VERSION 3.0.0) +project(libzippp + VERSION 6.0.0 + DESCRIPTION "C++ wrapper for libzip" + HOMEPAGE_URL "http://github.com/ctabin/libzippp" + LANGUAGES CXX +) # Use C++11 set(CMAKE_CXX_STANDARD 11) @@ -29,17 +34,35 @@ option(LIBZIPPP_INSTALL "Install library" ${is_root_project}) option(LIBZIPPP_INSTALL_HEADERS "Install the headers" ${is_root_project}) option(LIBZIPPP_BUILD_TESTS "Build unit tests" ${is_root_project}) option(LIBZIPPP_ENABLE_ENCRYPTION "Build with encryption enabled" OFF) +option(LIBZIPPP_CMAKE_CONFIG_MODE "Build with libzip installed cmake config files" OFF) +option(LIBZIPPP_GNUINSTALLDIRS "Install into directories taken from GNUInstallDirs" OFF) list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") -find_package(LIBZIP MODULE REQUIRED) +if(LIBZIPPP_CMAKE_CONFIG_MODE) + set(LIBZIP_PKGNAME "libzip") + set(fp_mode "CONFIG") +else() + set(LIBZIP_PKGNAME "LIBZIP") + set(fp_mode "MODULE") +endif() + +find_package(${LIBZIP_PKGNAME} ${fp_mode} REQUIRED) + +if(LIBZIPPP_GNUINSTALLDIRS) + include(GNUInstallDirs) + set(install_include_location ${CMAKE_INSTALL_INCLUDEDIR}/libzippp) +else() + set(install_include_location include/libzippp) +endif() add_library(libzippp "src/libzippp.cpp") add_library(libzippp::libzippp ALIAS libzippp) # Convenience alias -target_include_directories(libzippp - PUBLIC +target_include_directories(libzippp + PUBLIC $ - $ + $ + ) set_target_properties(libzippp PROPERTIES PREFIX "") # Avoid duplicate "lib" prefix target_link_libraries(libzippp PRIVATE libzip::zip) @@ -61,7 +84,7 @@ if(LIBZIPPP_BUILD_TESTS) add_executable(libzippp_test "tests/tests.cpp") target_link_libraries(libzippp_test PRIVATE libzippp) add_test(NAME libzippp_tests COMMAND libzippp_test) - + if (BUILD_SHARED_LIBS) set_target_properties(libzippp_test PROPERTIES OUTPUT_NAME "libzippp_shared_test") else() @@ -71,30 +94,34 @@ endif() if(LIBZIPPP_INSTALL) install( - TARGETS libzippp + TARGETS libzippp EXPORT libzipppTargets - LIBRARY DESTINATION lib - ARCHIVE DESTINATION lib - RUNTIME DESTINATION bin ) if(LIBZIPPP_INSTALL_HEADERS) - install(FILES src/libzippp.h DESTINATION include/libzippp) + install( + FILES src/libzippp.h + DESTINATION ${install_include_location} + ) endif() include(CMakePackageConfigHelpers) set(PROJECT_CONFIG_FILE "${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}Config.cmake") set(PROJECT_VERSION_FILE "${CMAKE_CURRENT_BINARY_DIR}/generated/${PROJECT_NAME}ConfigVersion.cmake") - if(WIN32) - set(configInstallDestination cmake/${PROJECT_NAME}) + if(LIBZIPPP_GNUINSTALLDIRS) + set(configInstallDestination ${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}) else() - set(configInstallDestination share/${PROJECT_NAME}) + if(WIN32) + set(configInstallDestination cmake/${PROJECT_NAME}) + else() + set(configInstallDestination share/${PROJECT_NAME}) + endif() endif() - + configure_package_config_file( - "Config.cmake.in" - ${PROJECT_CONFIG_FILE} + "Config.cmake.in" + ${PROJECT_CONFIG_FILE} INSTALL_DESTINATION ${configInstallDestination} ) write_basic_package_version_file( @@ -103,7 +130,8 @@ if(LIBZIPPP_INSTALL) ) install( - FILES ${PROJECT_CONFIG_FILE} ${PROJECT_VERSION_FILE} cmake/FindLIBZIP.cmake + FILES ${PROJECT_CONFIG_FILE} ${PROJECT_VERSION_FILE} + $<$>:cmake/FindLIBZIP.cmake> DESTINATION ${configInstallDestination} ) @@ -112,5 +140,20 @@ if(LIBZIPPP_INSTALL) NAMESPACE "${PROJECT_NAME}::" DESTINATION ${configInstallDestination} ) -endif() + if(BUILD_SHARED_LIBS AND LIBZIPPP_GNUINSTALLDIRS AND LIBZIPPP_INSTALL_HEADERS) + string( + REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${prefix}" + pc_includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}" + ) + string( + REGEX REPLACE "^${CMAKE_INSTALL_PREFIX}" "\${exec_prefix}" + pc_libdir "${CMAKE_INSTALL_FULL_LIBDIR}" + ) + configure_file(libzippp.pc.in generated/libzippp.pc @ONLY) + install( + FILES ${CMAKE_CURRENT_BINARYDIR}/generated/libzipp.pc + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig + ) + endif() +endif() diff --git a/Config.cmake.in b/Config.cmake.in index 0ad1525..334d2ef 100644 --- a/Config.cmake.in +++ b/Config.cmake.in @@ -1,10 +1,10 @@ @PACKAGE_INIT@ -find_package(LIBZIP QUIET) -if(NOT LIBZIP_FOUND) +find_package(@LIBZIP_PKGNAME@ QUIET) +if(NOT @LIBZIP_PKGNAME@_FOUND) list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}) include(CMakeFindDependencyMacro) - find_dependency(LIBZIP REQUIRED) + find_dependency(@LIBZIP_PKGNAME@ REQUIRED) endif() include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake") diff --git a/README.md b/README.md index 10a93e6..dcde422 100644 --- a/README.md +++ b/README.md @@ -81,6 +81,8 @@ Set via commandline as `cmake -DNAME=VALUE ` or via CMake GUI or CCM - `LIBZIPPP_INSTALL_HEADERS`: Enable/Disable installation of libzippp headers. Default is OFF when using via `add_subdirectory`, else ON - `LIBZIPPP_BUILD_TESTS`: Enable/Disable building libzippp tests. Default is OFF when using via `add_subdirectory`, else ON - `LIBZIPPP_ENABLE_ENCRYPTION`: Enable/Disable building libzippp with encryption capabilities. Default is OFF. +- `LIBZIPPP_CMAKE_CONFIG_MODE`: Enable/Disable building with libzip installed cmake config files. Default is OFF. +- `LIBZIPPP_GNUINSTALLDIRS`: Enable/Disable building with install directories taken from [GNUInstallDirs](https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html). Default is OFF. - `CMAKE_INSTALL_PREFIX`: Where to install the project to - `CMAKE_BUILD_TYPE`: Set to Release or Debug to build with or without optimizations - `CMAKE_PREFIX_PATH`: Colon-separated list of prefix paths (paths containing `lib` and `include` folders) for installed libs to be used by this diff --git a/cmake/FindLIBZIP.cmake b/cmake/FindLIBZIP.cmake index c51c09a..bf43e18 100644 --- a/cmake/FindLIBZIP.cmake +++ b/cmake/FindLIBZIP.cmake @@ -9,13 +9,13 @@ mark_as_advanced(LIBZIP_LIBRARY) get_filename_component(_libzip_libdir ${LIBZIP_LIBRARY} DIRECTORY) find_file(_libzip_pkgcfg libzip.pc HINTS ${_libzip_libdir} ${LIBZIP_INCLUDE_DIR}/.. - PATH_SUFFIXES pkgconfig lib/pkgconfig + PATH_SUFFIXES pkgconfig lib/pkgconfig libdata/pkgconfig NO_DEFAULT_PATH ) include(FindPackageHandleStandardArgs) find_package_handle_standard_args( - LIBZIP + LIBZIP REQUIRED_VARS LIBZIP_LIBRARY LIBZIP_INCLUDE_DIR @@ -42,15 +42,15 @@ if (LIBZIP_FOUND) set_property(TARGET libzip::zip APPEND PROPERTY INTERFACE_LINK_LIBRARIES OpenSSL::Crypto) endif() if(_have_extra_libs MATCHES "-lgnutls") - find_package(GnuTLS::GnuTLS REQUIRED) + find_package(GnuTLS REQUIRED) set_property(TARGET libzip::zip APPEND PROPERTY INTERFACE_LINK_LIBRARIES GnuTLS::GnuTLS) endif() - if(_have_extra_libs MATCHES "lgnutls") - find_package(Nettle::Nettle REQUIRED) + if(_have_extra_libs MATCHES "-lnettle") + find_package(Nettle REQUIRED) set_property(TARGET libzip::zip APPEND PROPERTY INTERFACE_LINK_LIBRARIES Nettle::Nettle) endif() if(_have_extra_libs MATCHES "-llzma") - find_package(LibLZMA::LibLZMA REQUIRED) + find_package(LibLZMA REQUIRED) set_property(TARGET libzip::zip APPEND PROPERTY INTERFACE_LINK_LIBRARIES LibLZMA::LibLZMA) endif() if(_have_extra_libs MATCHES "-lz") diff --git a/libzippp.pc.in b/libzippp.pc.in new file mode 100644 index 0000000..833058e --- /dev/null +++ b/libzippp.pc.in @@ -0,0 +1,12 @@ +prefix=@CMAKE_INSTALL_PREFIX@ +exec_prefix=${prefix} +includedir=@pc_includedir@ +libdir=@pc_libdir@ + +Name: libzippp +Description: @PROJECT_DESCRIPTION@ +URL: @PROJECT_HOMEPAGE_URL@ +Version: @PROJECT_VERSION@ + +Libs: -L${libdir} -lzippp +Cflags: -I${includedir} diff --git a/src/libzippp.h b/src/libzippp.h index 27cf398..3cb3301 100644 --- a/src/libzippp.h +++ b/src/libzippp.h @@ -35,7 +35,9 @@ OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ - +#ifndef _WIN32 +#include +#endif #include #include #include @@ -64,11 +66,11 @@ struct zip_source; #define LIBZIPPP_SHARED_LIBRARY_IMPORT #else //standard ISO c++ does not support long long - typedef long int libzippp_int64; - typedef unsigned long int libzippp_uint64; - typedef unsigned int libzippp_uint32; - typedef unsigned short libzippp_uint16; - + typedef std::int64_t libzippp_int64; + typedef std::uint64_t libzippp_uint64; + typedef std::uint32_t libzippp_uint32; + typedef std::uint16_t libzippp_uint16; + #define LIBZIPPP_SHARED_LIBRARY_EXPORT #define LIBZIPPP_SHARED_LIBRARY_IMPORT #endif diff --git a/tests/exampleProject/CMakeLists.txt b/tests/exampleProject/CMakeLists.txt index a235b7c..952ecb4 100644 --- a/tests/exampleProject/CMakeLists.txt +++ b/tests/exampleProject/CMakeLists.txt @@ -2,7 +2,7 @@ cmake_minimum_required(VERSION 3.8.0) project(libzippp_example_project) -find_package(libzippp 3.0 REQUIRED) +find_package(libzippp 6.0 REQUIRED) enable_testing() add_executable(example "../tests.cpp")