include(InstallRequiredSystemLibraries)

#install_directory_permissions( DIRECTORY usr/${CMAKE_INSTALL_INCLUDEDIR}/myeosio )

set(CPACK_PACKAGE_CONTACT "admin@myeosio.org")
set(CPACK_OUTPUT_FILE_PREFIX ${CMAKE_BINARY_DIR}/packages)
if(NOT DEFINED CMAKE_INSTALL_PREFIX)
  set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install)
endif()

SET(CPACK_PACKAGE_DIRECTORY "${CMAKE_BINARY_DIR}/install")
set(CPACK_PACKAGE_NAME "MyEOSIO")
set(CPACK_PACKAGE_VENDOR "myeosio.org")
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_PACKAGE_DESCRIPTION "Software for the MyEOSIO network")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Software for the MyEOSIO network")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "MyEOSIO ${CPACK_PACKAGE_VERSION}")

if(WIN32)
  set(CPACK_GENERATOR "ZIP;NSIS")
  set(CPACK_NSIS_EXECUTABLES_DIRECTORY .)
  set(CPACK_NSIS_PACKAGE_NAME "MyEOSIO v${CPACK_PACKAGE_VERSION}")
  set(CPACK_NSIS_DISPLAY_NAME "${CPACK_NSIS_PACKAGE_NAME}")
  set(CPACK_NSIS_DEFINES "  !define MUI_STARTMENUPAGE_DEFAULTFOLDER \\\"MyEOSIO\\\"")
  # windows zip files usually don't have a single directory inside them, unix tgz usually do
  set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY 0)
elseif(APPLE)
  set(CPACK_GENERATOR "DragNDrop")
else()
  set(CPACK_GENERATOR "DEB")
  set(CPACK_DEBIAN_PACKAGE_RELEASE 0)
  if(CMAKE_VERSION VERSION_GREATER 3.6.0) # Buggy in 3.5, behaves like VERSION_GREATER_EQUAL
    set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT")
  else()
    string(TOLOWER ${CPACK_PACKAGE_NAME} CPACK_DEBIAN_PACKAGE_NAME)
    execute_process(COMMAND dpkg --print-architecture OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE)
    SET(CPACK_PACKAGE_FILE_NAME ${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}-${CPACK_DEBIAN_PACKAGE_RELEASE}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})
  endif()
  set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
  set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY TRUE)
  set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE)
  set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/myeosio/myeosio")
endif()

include(CPack)
