set(CPACK_SET_DESTDIR "on")
set(CPACK_PACKAGING_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/../packages")
set(CPACK_GENERATOR "DEB")

#Control file stuff
if (NOT DEFINED PACKAGE_NAME)
	message(FATAL_NAME "Set the pacakge name under PACKAGE_NAME.")
endif()

string(TOLOWER ${PACKAGE_NAME} PACKAGE_NAME)
set(CPACK_PACKAGE_NAME ${PACKAGE_NAME})

if ( DEFINED MAJOR_VERSION AND DEFINED MINOR_VERSION )
	set(CPACK_PACKAGE_VERSION ${MAJOR_VERSION}.${MINOR_VERSION})
else ()
	message(FATAL_ERROR "MAJOR_VERSION and MINOR_VERISON not set.")
endif()

execute_process(COMMAND dpkg --print-architecture OUTPUT_VARIABLE SYSTEM_ARCHITECTURE OUTPUT_STRIP_TRAILING_WHITESPACE)
set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE ${SYSTEM_ARCHITECTURE})
#set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386)

if (NOT DEFINED CPACK_DEBIAN_PACKAGE_DEPENDS)
	message(FATAL_ERROR "Define dependencies in CPACK_DEBIAN_PACKAGE_DEPENDS")
endif ()

set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Đula Nađ <dula.nad@gmail.com>")

if (NOT DEFINED CPACK_PACKAGE_DESCRIPTION_SUMMARY)
	message(FATAL_ERROR "Write package descrpition in CPACK_PACKAGE_DESCRIPTION_SUMMARY")
endif ()

#if (NOT DEFINED ${DEBIAN_PACKAGE_BUILDS_DEPENDS})
#	message(FATAL_ERROR "Specify build dependencies in DEBIAN_PACKAGE_BUILDS_DEPENDS")
#endif ()
set(CPACK_SYSTEM_NAME "linux_${SYSTEM_ARCHITECTURE}")
set(CPACK_PACKAGE_FILE_NAME "${CPACK_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}~${CPACK_SYSTEM_NAME}")
