set(CPACK_PACKAGE_NAME "${PROJECT_NAME}")
set(CPACK_PACKAGE_VENDOR "neo4j")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "seabolt: The C Connector Library for Neo4j")
set(CPACK_PACKAGE_HOMEPAGE_URL "https://github.com/neo4j-drivers/seabolt")

set(CPACK_RESOURCE_FILE_LICENSE "${PROJECT_SOURCE_DIR}/LICENSE")

set(CPACK_MONOLITHIC_INSTALL ON)
if (WIN32 OR MINGW)
    unset(CPACK_PACKAGING_INSTALL_PREFIX)
else ()
    set(CPACK_PACKAGING_INSTALL_PREFIX "/usr/local")
endif ()

set(CPACK_PACKAGE_VERSION_MAJOR "${PROJECT_VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${PROJECT_VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${PROJECT_VERSION_PATCH}")
set(CPACK_PACKAGE_VERSION_TWEAK "${PROJECT_VERSION_TWEAK}")
set(CPACK_PACKAGE_VERSION "${PROJECT_VERSION}")

set(CPACK_PACKAGE_CHECKSUM "SHA256")
set(CPACK_SOURCE_IGNORE_FILES "${PROJECT_BINARY_DIR};/.git/;.gitignore;menu.yml")
set(CPACK_PACKAGE_DIRECTORY "${PROJECT_BINARY_DIR}/dist-package")

if (UNIX)
    set(CPACK_GENERATOR "TGZ")
else ()
    set(CPACK_GENERATOR "ZIP")
endif ()

if (CMAKE_SYSTEM_NAME STREQUAL "Linux")
    set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-${CMAKE_SYSTEM_NAME}-${OS_ID}-${OS_VERSION_ID}")
endif ()

if (CMAKE_SYSTEM_NAME STREQUAL "Windows")
    if ("${CMAKE_SIZEOF_VOID_P}" STREQUAL "8")
        set(CMAKE_BITNESS "64")
    elseif (CMAKE_SIZEOF_VOID_P STREQUAL "4")
        set(CMAKE_BITNESS "32")
    endif ()

    if (MSVC)
        set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win${CMAKE_BITNESS}-msvc")
    else ()
        set(CPACK_PACKAGE_FILE_NAME "${PROJECT_NAME}-${PROJECT_VERSION}-win${CMAKE_BITNESS}-mingw")
    endif ()
endif ()

if (UNIX)
    if (OS_ID_LIKE MATCHES "debian")
        list(APPEND CPACK_GENERATOR "DEB")
        set(CPACK_DEBIAN_PACKAGE_NAME "${SEABOLT_NAME}")
        set(CPACK_DEBIAN_PACKAGE_VERSION "${PROJECT_VERSION}")
        set(CPACK_DEBIAN_PACKAGE_MAINTAINER "neo4j")
        set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
        set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
        set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CMAKE_CURRENT_SOURCE_DIR}/cmake/package/deb/postinst;${CMAKE_CURRENT_SOURCE_DIR}/cmake/package/deb/postrm;")
    endif ()

    if (OS_ID_LIKE MATCHES "rhel|fedora|suse")
        list(APPEND CPACK_GENERATOR "RPM")
        set(CPACK_RPM_PACKAGE_NAME "${SEABOLT_NAME}")
        set(CPACK_RPM_PACKAGE_RELEASE "1")
        set(CPACK_RPM_PACKAGE_LICENSE "Apache")
        set(CPACK_RPM_POST_INSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/package/rpm/post")
        set(CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE "${CMAKE_CURRENT_SOURCE_DIR}/cmake/package/rpm/postun")
    endif ()
endif ()

message(STATUS "CPack generators: ${CPACK_GENERATOR}")

include(CPack)
