# cd build ; cmake -DCPACK_GENERATOR=DEB .. ; make package

INCLUDE(InstallRequiredSystemLibraries)

set(CPACK_PACKAGING_INSTALL_PREFIX /usr/local)

SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Tomahawk desktop player")
SET(CPACK_PACKAGE_NAME "tomahawk")
SET(CPACK_PACKAGE_VENDOR "tomahawk.org")
SET(CPACK_PACKAGE_CONTACT "Richard Jones")
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER "rj@tomahawk.org")

SET(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/../README")
SET(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE.txt")
SET(CPACK_PACKAGE_VERSION_MAJOR "0")
SET(CPACK_PACKAGE_VERSION_MINOR "0")
SET(CPACK_PACKAGE_VERSION_PATCH "1")
SET(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")

#SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "i386") # Default: Output of dpkg --print-architecture or i386
# Copied from generator script, needs to be set for inclusion into filename of package:
# $ dpkg --print-architecture
FIND_PROGRAM(DPKG_CMD dpkg)
IF(NOT DPKG_CMD)
    MESSAGE(STATUS "Can not find dpkg in your path, default to i386.")
    SET(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)
ELSE(NOT DPKG_CMD)
    EXECUTE_PROCESS(COMMAND "${DPKG_CMD}" --print-architecture
                OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
                OUTPUT_STRIP_TRAILING_WHITESPACE
    )
ENDIF(NOT DPKG_CMD)

EXECUTE_PROCESS(COMMAND "date" "+%s"
                OUTPUT_VARIABLE TIMEMARK
                OUTPUT_STRIP_TRAILING_WHITESPACE
               )

# eg: tomahawk-i386-1.0.0
SET(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}-${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}-${CPACK_PACKAGE_VERSION}_${TIMEMARK}")

SET(CPACK_PACKAGE_INSTALL_DIRECTORY "CMake ${CMake_VERSION_MAJOR}.${CMake_VERSION_MINOR}")

IF(WIN32 AND NOT UNIX)
  ###
ELSE(WIN32 AND NOT UNIX)
#  SET(CPACK_STRIP_FILES "tomahawk")
#  SET(CPACK_SOURCE_STRIP_FILES "")
ENDIF(WIN32 AND NOT UNIX)

# Nsis only? SET(CPACK_PACKAGE_EXECUTABLES "tomahawk" "tomahawk")

#gnutls is in here because gloox needs it, and we link statically to gloox:
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libqtgui4 (>=4:4.7.0-0ubuntu1), libtag1c2a (>=1.6.2-0ubuntu1), liblastfm-dev (>=0.4.0~really0.3.3-0ubuntu1), libqt4-sql-sqlite (>=4:4.7.0-0ubuntu1), libvorbis0a (>=1.2.3-3ubuntu1), libmad0 (>=0.15.1b-4ubuntu1), libasound2 (>=1.0.22-0ubuntu7), zlib1g (>=1:1.2.3.3.dfsg-15ubuntu1), libqjson-dev (>=0.7.1-1), libgnutls26 (>= 2.7.14-0), libgloox8 (>=1.0-1)")

#SET(CPACK_DEBIAN_PACKAGE_SECTION "music")

INSTALL(
    TARGETS tomahawk DESTINATION bin
    RUNTIME DESTINATION bin
#    LIBRARY DESTINATION lib${LIB_SUFFIX}
#    ARCHIVE DESTINATION lib${LIB_SUFFIX}
       )

INSTALL(
    PROGRAMS ${CMAKE_BINARY_DIR}/tomahawk
    DESTINATION bin
    )

INCLUDE(CPack)
