### versions
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 "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")

### general settings
#set(CPACK_PACKAGE_ICON "${CMAKE_SOURCE_DIR}/resources\\\\flag.bmp")

set(CPACK_PACKAGE_NAME "${APPLICATION_NAME}")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Roman numerals en-/decoder.")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_SOURCE_DIR}/../README.md")
set(CPACK_PACKAGE_VENDOR "C++ Usergroup Zentralschweiz")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "Roman numerals ${PROJECT_VERSION_MAJOR}.${PROJECT_VERSION_MINOR}")

set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_SOURCE_DIR}/../LICENSE")
set(CPACK_OUTPUT_FILE_PREFIX "${CMAKE_SOURCE_DIR}/../install")

set(CPACK_COMPONENTS_ALL main library headers doc)

set(CPACK_COMPONENT_MAIN_REQUIRED)
set(CPACK_COMPONENT_MAIN_GROUP "Program")
set(CPACK_COMPONENT_MAIN_DISPLAY_NAME "${APPLICATION_NAME}.exe")
set(CPACK_COMPONENT_MAIN_DESCRIPTION "The actual executable")

set(CPACK_COMPONENT_GROUP_PROGRAM_DESCRIPTION
    "The main application"
    )

### nsis generator (Windows)

#set(CPACK_NSIS_MUI_ICON "${CMAKE_SOURCE_DIR}/resources/ship-wheel.ico")
#set(CPACK_NSIS_MUI_UNIICON "${CMAKE_SOURCE_DIR}/resources/skull-and-bones.ico")
#set(CPACK_NSIS_MODIFY_PATH "ON")

set(CPACK_CREATE_DESKTOP_LINKS "${APPLICATION_NAME}")

set(CPACK_NSIS_DISPLAY_NAME "${APPLICATION_NAME}")
set(CPACK_NSIS_COMPRESSOR "/SOLID zlib")

set(CPACK_NSIS_CONTACT "estermann.michel@gmail.com")
set(CPACK_NSIS_HELP_LINK "https://github.com/CppUsergroupZentralschweiz/roman_numerals")
set(CPACK_NSIS_URL_INFO_ABOUT "https://github.com/CppUsergroupZentralschweiz/roman_numerals")

set(CPACK_NSIS_CREATE_ICONS "
  SetOutPath \\\"$INSTDIR\\\\bin\\\"
  CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\License.lnk\\\" \\\"$INSTDIR\\\\doc\\\\LICENSE\\\"
  CreateShortCut \\\"$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\README.lnk\\\" \\\"$INSTDIR\\\\doc\\\\README.md\\\"
")
set(CPACK_NSIS_DELETE_ICONS "
  Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\License.lnk\\\"
  Delete \\\"$SMPROGRAMS\\\\$MUI_TEMP\\\\README.lnk\\\"
")
# DEB package config
string(TOLOWER ${PROJECT_NAME} LOWER_CASE_PROJECT_NAME)
set(CPACK_DEBIAN_PACKAGE_NAME ${LOWER_CASE_PROJECT_NAME})
set(CPACK_DEBIAN_PACKAGE_MAINTAINER "Michel Estermann <estermann.michel@gmail.com>")
set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "https://github.com/CppUsergroupZentralschweiz/roman_numerals")
#set(CPACK_DEBIAN_PACKAGE_SECTION "")
#set(CPACK_DEBIAN_PACKAGE_DEPENDS "")

set(CPACK_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX})

set(CPACK_GENERATOR "TGZ;STGZ;TBZ2;ZIP")
find_program(NSIS_PROGRAM NSIS)
if(NSIS_PROGRAM)
    list(APPEND CPACK_GENERATOR "NSIS")
endif(NSIS_PROGRAM)

find_program(DPKG_PROGRAM dpkg)
if(DPKG_PROGRAM)
    # Determine current architecture
    macro(dpkg_arch VAR_NAME)
        execute_process(
            COMMAND ${DPKG_PROGRAM} --print-architecture
            OUTPUT_VARIABLE ${VAR_NAME}
            OUTPUT_STRIP_TRAILING_WHITESPACE
        )
    endmacro(dpkg_arch)

    set(CPACK_SET_DESTDIR true)

    dpkg_arch(CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
    if(CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
        set(CPACK_PACKAGE_FILE_NAME ${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE})
    else(CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
        set(CPACK_PACKAGE_FILE_NAME ${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_PACKAGE_VERSION}_${CMAKE_SYSTEM_NAME})
    endif(CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
    list(APPEND CPACK_GENERATOR "DEB")
endif(DPKG_PROGRAM)

include(CPack)
include(InstallRequiredSystemLibraries)
