# set some project metadata for the installer
set(CPACK_PACKAGE_NAME ${CMAKE_PROJECT_NAME})
set(CPACK_PACKAGE_VENDOR "cfd.university")
set(CPACK_PACKAGE_CONTACT "tom@cfd.university")
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY "A C++ library for Complex Numbers")
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CPACK_PACKAGE_NAME})
set(CPACK_PACKAGE_VERSION_MAJOR ${CMAKE_PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${CMAKE_PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${CMAKE_PROJECT_VERSION_PATCH})
set(CPACK_VERBATIM_VARIABLES YES)

# if we not call the line below, groups won't show properlly in the GUI installer
set(CPACK_COMPONENTS_GROUPING IGNORE)

# ignore directories and files
set(CPACK_SOURCE_IGNORE_FILES
  "/.git/"
  "/.vscode/"
  "/build/"
  "/CMakeCache.txt"
  "/CMakeFiles/"
  "/cmake_install.cmake"
  "/CPackConfig.cmake"
)

# we are interested in cross-platform support. IFW is the only generator that allows for it, so set it explicitly
set(CPACK_GENERATOR "IFW")
set(CPACK_IFW_ROOT "C:/Qt/Tools/QtInstallerFramework/4.8")

# set some IFW specific variables, which can be derived from the more generic variables given above
set(CPACK_IFW_VERBOSE ON)
set(CPACK_IFW_PACKAGE_TITLE ${CPACK_PACKAGE_NAME})
set(CPACK_IFW_PACKAGE_PUBLISHER ${CPACK_PACKAGE_VENDOR})
set(CPACK_IFW_PRODUCT_URL "https://cfd.university")

# create a more memorable name for the maintenance tool (used for uninstalling the package)
set(CPACK_IFW_PACKAGE_MAINTENANCE_TOOL_NAME ${PROJECT_NAME}_MaintenanceTool)
set(CPACK_IFW_PACKAGE_MAINTENANCE_TOOL_INI_FILE ${CPACK_IFW_PACKAGE_MAINTENANCE_TOOL_NAME}.ini)

# customise the theme if required
set(CPACK_IFW_PACKAGE_WIZARD_STYLE "Modern")

# adjust the default size
set(CPACK_IFW_PACKAGE_WIZARD_DEFAULT_HEIGHT 400)

# set the installer icon and logo
if(WIN32)
  set(CPACK_IFW_PACKAGE_ICON ${CMAKE_CURRENT_LIST_DIR}/resources/logo.ico)
  elseif(APPLE)
  set(CPACK_IFW_PACKAGE_ICON ${CMAKE_CURRENT_LIST_DIR}/resources/logo.icns)
endif()
set(CPACK_IFW_PACKAGE_WINDOWS_LOGO ${CMAKE_CURRENT_LIST_DIR}/resources/logo.png)
set(CPACK_IFW_PACKAGE_LOGO ${CMAKE_CURRENT_LIST_DIR}/resources/logo.png)

# now include the relevant (cross-platform) packaging script
include(CPack)
include(CPackIFW)

# add the library as a component to the installer
cpack_add_component(complexLib
  REQUIRED
  DISPLAY_NAME "Complex Number Library"
  DESCRIPTION "Install the complex number library"
)

cpack_ifw_configure_component(complexLib
  REQUIRED
  LICENSES "MIT License" ${CMAKE_SOURCE_DIR}/cmake/resources/license.txt
  SORTING_PRIORITY 99
)

# add the documentation under a "developer" group component
if (BUILD_DOCS)
  cpack_add_component(documentation
    DISPLAY_NAME "API Documentation"
    DESCRIPTION "Documentation for the complex numbers library"
    GROUP documentationGroup
  )
    
  cpack_ifw_configure_component(documentation
    DEFAULT FALSE
    GROUP documentationGroup
    SORTING_PRIORITY 1
  )

  cpack_add_component_group(documentationGroup
    EXPANDED
    DISPLAY_NAME "Documentation"
    DESCRIPTION "Install the complex Number Library documentation"
  )

  cpack_ifw_configure_component_group(documentationGroup
    SORTING_PRIORITY 1
  )
endif(BUILD_DOCS)