### tell cpack which components ###	
if ( DEFINED USE_COMPONENTS )
	message ("For installation only use specified components:  ${USE_COMPONENTS}")
	set(CPACK_COMPONENTS_ALL ${USE_COMPONENTS})	
else()
	set(CPACK_COMPONENTS_ALL main header lib data ${CPACK_COMPONENTS_ALL})	
endif()

### set display names for single components ###
if( DEFINED MAIN_DISPLAY_NAME )
	set(CPACK_COMPONENT_MAIN_DISPLAY_NAME ${MAIN_DISPLAY_NAME})
else()
	set(CPACK_COMPONENT_MAIN_DISPLAY_NAME "Main Application")
endif()

set(CPACK_COMPONENT_LIB_DISPLAY_NAME "Development Libraries")
set(CPACK_COMPONENT_HEADER_DISPLAY_NAME "Development Headers")
set(CPACK_COMPONENT_DATA_DISPLAY_NAME "Sample Data / Additional Data")

## define installation groups for components ###
# set(CPACK_COMPONENT_MAIN_GROUP "MainGroup")
# set(CPACK_COMPONENT_BINARIES_GROUP "MainGroup")
# set(CPACK_COMPONENT_DATA_GROUP "DataGroup")
# set(CPACK_COMPONENT_LIB_GROUP "DevelopmentGroup")
# set(CPACK_COMPONENT_HEADER_GROUP "DevelopmentGroup")

## provide installation groups display names ###
# set(CPACK_COMPONENT_GROUP_MAINGROUP_DISPLAY_NAME "Application Binaries")
# set(CPACK_COMPONENT_GROUP_DATAGROUP_DISPLAY_NAME "Extra Data")
# set(CPACK_COMPONENT_GROUP_DEVELOPMENTGROUP_DISPLAY_NAME "Development Files")

### set executable - symbol pairs ###
set(CPACK_PACKAGE_EXECUTABLES 
	"${PROJECTNAME}" "${CPACK_COMPONENT_MAIN_DISPLAY_NAME}")
	
#include(InstallRequiredSystemLibraries)
set(CPACK_PROJECTNAME "${CPACK_COMPONENT_MAIN_DISPLAY_NAME}")
set(CPACK_PACKAGE_NAME "${CPACK_COMPONENT_MAIN_DISPLAY_NAME}")
set(CPACK_PACKAGE_VENDOR "Dominik Rueß")
set(CPACK_PACKAGE_DESCRIPTION_FILE "${CMAKE_CURRENT_SOURCE_DIR}/README")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/../LICENSE")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "${CPACK_COMPONENT_MAIN_DISPLAY_NAME} - Installation Program")
if ( NOT DEFINED VERSION_MAJOR )
	SET(VERSION_MAJOR  0)
endif()
if ( NOT DEFINED VERSION_MINOR )
	SET(VERSION_MINOR  1)
endif()
if ( NOT DEFINED VERSION_PATCH )
	SET(VERSION_PATCH  1)
endif()
set(CPACK_PACKAGE_VERSION "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
set(CPACK_PACKAGE_VERSION_MAJOR "${VERSION_MAJOR}")
set(CPACK_PACKAGE_VERSION_MINOR "${VERSION_MINOR}")
set(CPACK_PACKAGE_VERSION_PATCH "${VERSION_PATCH}")
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PROJECTNAME}")

if (WIN32)
  IF(CMAKE_CL_64)
	SET(CMAKE_SYSTEM_PROCESSOR "X86")
    SET(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES64")
    #SET(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY} (Win64)")
    SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION} (Win64)")
  ELSE()
    SET(CPACK_NSIS_INSTALL_ROOT "$PROGRAMFILES")
    #SET(CPACK_NSIS_PACKAGE_NAME "${CPACK_PACKAGE_INSTALL_DIRECTORY}")
    SET(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "${CPACK_PACKAGE_NAME} ${CPACK_PACKAGE_VERSION}")
  ENDIF()
endif(WIN32)

# and finally
include(CPack)
