
if( WIN32 )
  set( CPACK_GENERATOR "ZIP" )
elseif( APPLE )
  message( FATAL_ERROR "Not supported yet." )
elseif( UNIX )
  if( ${CMAKE_SYSTEM_NAME} STREQUAL "FreeBSD" )
    set( CPACK_GENERATOR "FREEBSD" )
  elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Cygwin" )
    set( CPACK_GENERATOR "CYGWIN" )
  elseif( ${CMAKE_SYSTEM_NAME} STREQUAL "Linux" )
    find_program(LSB_RELEASE_EXEC lsb_release)
    if( NOT LSB_RELEASE_EXEC STREQUAL "LSB_RELEASE_EXEC-NOTFOUND" )
      execute_process(COMMAND ${LSB_RELEASE_EXEC} -is
      OUTPUT_VARIABLE LSB_RELEASE_ID_SHORT
      OUTPUT_STRIP_TRAILING_WHITESPACE
    )
    else()
      set( LSB_RELEASE_ID_SHORT "unknown" )
    endif()
    if( ${LSB_RELEASE_ID_SHORT} STREQUAL "Debian" )
      set( CPACK_GENERATOR "DEB" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "Ubuntu" )
      set( CPACK_GENERATOR "DEB" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "LinuxMint" )
      set( CPACK_GENERATOR "DEB" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "Raspbian" )
      set( CPACK_GENERATOR "DEB" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "Kali" )
      set( CPACK_GENERATOR "DEB" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "MX" )
      set( CPACK_GENERATOR "DEB" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "Devuan" )
      set( CPACK_GENERATOR "DEB" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "Vyos" )
      set( CPACK_GENERATOR "DEB" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "RedHatEnterpriseServer" )
      set( CPACK_GENERATOR "RPM" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "Fedora" )
      set( CPACK_GENERATOR "RPM" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "CentOS" )
      set( CPACK_GENERATOR "RPM" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "AlmaLinux" )
      set( CPACK_GENERATOR "RPM" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "ClearOSCommunity" )
      set( CPACK_GENERATOR "RPM" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "Rocky" )
      set( CPACK_GENERATOR "RPM" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "AmazonAMI" )
      set( CPACK_GENERATOR "RPM" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "openSUSE project" )
      set( CPACK_GENERATOR "RPM" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "SUSE LINUX" )
      set( CPACK_GENERATOR "RPM" )
    elseif( ${LSB_RELEASE_ID_SHORT} STREQUAL "Scientific" )
      set( CPACK_GENERATOR "RPM" )
    else()
      set( CPACK_GENERATOR "TGZ" )
    endif()
  else()
    set( CPACK_GENERATOR "TGZ" )
  endif()
endif()

set( CPACK_PACKAGE_NAME "${PROJECT_NAME}" )
set( CPACK_PACKAGE_VENDOR "${EASYPACK_VENDOR}" )
set( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/LICENSE" )
string( REPLACE "." ";" EASYPACK_PROJECT_VERSION "${PROJECT_VERSION}" )
list( GET EASYPACK_PROJECT_VERSION 0 EASYPACK_PROJECT_VERSION_MAJOR )
list( GET EASYPACK_PROJECT_VERSION 1 EASYPACK_PROJECT_VERSION_MINOR )
list( GET EASYPACK_PROJECT_VERSION 2 EASYPACK_PROJECT_VERSION_PATCH )
set( CPACK_PACKAGE_VERSION_MAJOR "${EASYPACK_PROJECT_VERSION_MAJOR}" )
set( CPACK_PACKAGE_VERSION_MINOR "${EASYPACK_PROJECT_VERSION_MINOR}" )
set( CPACK_PACKAGE_VERSION_PATCH "${EASYPACK_PROJECT_VERSION_PATCH}" )
set( CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CMAKE_PROJECT_DESCRIPTION}" )
set( CPACK_PACKAGE_DESCRIPTION "${CMAKE_PROJECT_DESCRIPTION}" )
set( CPACK_PACKAGE_HOMEPAGE_URL "${CMAKE_PROJECT_HOMEPAGE_URL}" )

set( CPACK_DEBIAN_PACKAGE_RELEASE "${EASYPACK_RELEASE}" )
set( CPACK_DEBIAN_FILE_NAME DEB-DEFAULT )
set( CPACK_DEBIAN_PACKAGE_MAINTAINER "${EASYPACK_MAINTAINER}" )
set( CPACK_DEBIAN_COMPRESSION_TYPE "${EASYPACK_COMPRESSION_TYPE}" )
set( CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON )
string(REPLACE ";" "," DEB_REQUIREMENTS_STR "${EASYPACK_DEB_REQUIREMENTS}")
set( CPACK_DEBIAN_PACKAGE_DEPENDS "${DEB_REQUIREMENTS_STR}" )

set( CPACK_RPM_PACKAGE_RELEASE "${EASYPACK_RELEASE}" )
set( CPACK_RPM_PACKAGE_RELEASE_DIST "${EASYPACK_VENDOR}" )
set( CPACK_RPM_PACKAGE_LICENSE "${EASYPACK_LICENSE_NAME}" )
set( CPACK_RPM_PACKAGE_URL "${CMAKE_PROJECT_HOMEPAGE_URL}" )
set( CPACK_RPM_COMPRESSION_TYPE "${EASYPACK_COMPRESSION_TYPE}" )
set( CPACK_RPM_PACKAGE_AUTOREQ ON )
string(REPLACE ";" "," RPM_REQUIREMENTS_STR "${EASYPACK_RPM_REQUIREMENTS}")
set( CPACK_DEBIAN_PACKAGE_DEPENDS "${RPM_REQUIREMENTS_STR}" )

set( CPACK_CYGWIN_PATCH_NUMBER "${EASYPCAK_RELEASE}" )

set(CPACK_SET_DESTDIR true)
include(CPack)

