# Xiphos build script
#
# Copyright (C) 2018 Xiphos Development Team
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU Library General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
#

# packaging xiphos


# setting up common variables to all packagers
message(STATUS "Configuring binary and source packagers")

# The name of the package (or application). If not specified, defaults to
# the project name.
set (CPACK_PACKAGE_NAME "${PROJECT_NAME}")

# The name of the package vendor.
set(CPACK_PACKAGE_VENDOR "The Xiphos Development Team")
set(CPACK_PACKAGE_CONTACT "xiphos-devel@crosswire.org")

# The directory in which CPack is doing its packaging. If it is not set then
# this will default (internally) to the build dir.
# set(CPACK_PACKAGE_DIRECTORY ${CMAKE_BINARY_DIR}/packages)

# Package major Version
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})

# Package minor Version
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})

# Package patch Version
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})

# Package full version, used internally. By default, this is built from
# CPACK_PACKAGE_VERSION_MAJOR, CPACK_PACKAGE_VERSION_MINOR,
# and CPACK_PACKAGE_VERSION_PATCH.
set(CPACK_PACKAGE_VERSION ${PROJECT_VERSION})

# A text file used to describe the project. Used, for example, the introduction
# screen of a CPack-generated Windows installer to describe the project.
set(CPACK_PACKAGE_DESCRIPTION_FILE ${CMAKE_CURRENT_SOURCE_DIR}/xiphos.desc)

# Short description of the project (only a few words).
set(CPACK_PACKAGE_DESCRIPTION_SUMMARY
  "An environment for Bible reading, study, and research")

# The name of the package file to generate, not including the extension.
# The default value is:
# ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}-${CPACK_SYSTEM_NAME}
#set(CPACK_PACKAGE_FILE_NAME ${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION})

# Installation directory on the target system. This may be used by some CPack
# generators like NSIS to create an installation directory below the
# installation prefix. All installed element will be put inside this directory.
set(CPACK_PACKAGE_INSTALL_DIRECTORY ${CMAKE_BINARY_DIR})

# A branding image that will be displayed by GUI installers.
set(CPACK_PACKAGE_ICON ${PROJECT_SOURCE_DIR}/win32/nsis/pixmaps/header.bmp)

# CPack-time project CPack configuration file. This file included at cpack time,
# once per generator after CPack has set CPACK_GENERATOR to the actual generator
# being used. It allows per-generator setting of CPACK* variables at cpack time.
#set(CPACK_PROJECT_CONFIG_FILE ${CMAKE_CURRENT_SOURCE_DIR}/XiphosCPackConfig.cmake)

# License to be embedded in the installer. It will typically be displayed to the
# user by the produced installer. This license file is not installed.
set(CPACK_RESOURCE_FILE_LICENSE ${PROJECT_SOURCE_DIR}/COPYING)

# README file to be embedded in the installer. It typically describes the
# purpose of the project during the installation. Not all CPack generators uses
# this file.
#set(CPACK_RESOURCE_FILE_README "")

# Welcome file to be embedded in the installer. It welcomes users to this
# installer. Typically used in the graphical installers on Windows and Mac OS X.
#set(CPACK_RESOURCE_FILE_WELCOME "")

# Disables the component-based installation mechanism. When set the component
# specification is ignored and all installed items are put in a single
# “MONOLITHIC” package. Some CPack generators do monolithic packaging by default
# and may be asked to do component packaging by setting
# CPACK_<GENNAME>_COMPONENT_INSTALL to 1/TRUE.
set(CPACK_MONOLITHIC_INSTALL "OFF")

# List of CPack generators to use. If not specified, CPack will create a set of
# options CPACK_BINARY_<GENNAME> (e.g., CPACK_BINARY_NSIS) allowing the user to
# enable/disable individual generators.
set(CPACK_GENERATOR "DEB;RPM")

# The name of the CPack binary configuration file. This file is the CPack
# configuration generated by the CPack module for binary installers.
# Defaults to CPackConfig.cmake.
#set(CPACK_OUTPUT_CONFIG_FILE CPackConfig.cmake)

# Lists each of the executables and associated text label to be used to create
# Start Menu shortcuts. For example, setting this to the list ccmake;CMake will
# create a shortcut named “CMake” that will execute the installed executable
# ccmake. Not all CPack generators use it (at least NSIS, WIX and OSXX11 do).
set(CPACK_PACKAGE_EXECUTABLES "Xiphos;xiphos")

# A boolean variable which enables stripping of all files.
set(CPACK_STRIP_FILES ON)

# If set to TRUE, values of variables prefixed with CPACK will be escaped before
# being written to the configuration files, so that the cpack program receives
# them exactly as they were specified. If not, characters like quotes and
# backslashes can cause parsing errors or alter the value received by the cpack
# program. Defaults to FALSE for backwards compatibility.
set(CPACK_VERBATIM_VARIABLES ON)


# The following CPack variables are specific to source packages, and will not
# affect binary packages:

# The name of the source package.
set(CPACK_SOURCE_PACKAGE_FILE_NAME
  "${CPACK_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}")

# A boolean variable which enables stripping of all source files
set(CPACK_SOURCE_STRIP_FILES ON)

# List of generators used for the source packages. As with CPACK_GENERATOR, if
# this is not specified then CPack will create a set of options allowing users
# to select which packages will be generated.
set(CPACK_SOURCE_GENERATOR "ZIP;TGZ")

#  The name of the CPack source configuration file. This file is the CPack
# configuration generated by the CPack module for source installers. Defaults
# to CPackSourceConfig.cmake.
#set(CPACK_SOURCE_OUTPUT_CONFIG_FILE CPackSourceConfig.cmake)

# Pattern of files in the source tree that won’t be packaged when building
# a source package
set (CPACK_SOURCE_IGNORE_FILES
  "${CMAKE_BINARY_DIR}/"
  "/.bzrignore"
  "/.bzrrules"
  "/.git/"
  "/.gitignore"
  "/.github"
  "/.bzrignore/"
  "/.bzrrules/"
  "/.clang-format"
  "/.ci-build.yml"
  "/xiphos-${CPACK_PACKAGE_VERSION}-win32.exe"
  "/xiphos-${CPACK_PACKAGE_VERSION}-win64.exe"
  )


# The following variables are for advanced uses of CPack:

#   What CMake generator should be used if the project is CMake project.
# Defaults to the value of CMAKE_GENERATOR
#set(CPACK_CMAKE_GENERATOR ${CMAKE_GENERATOR})

# List of four values that specify what project to install. The four values are:
# Build directory, Project Name, Project Component, Directory.
# If omitted, CPack will build an installer that installs everything.
#set(CPACK_INSTALL_CMAKE_PROJECTS "")

# System name, defaults to the value of ${CMAKE_SYSTEM_NAME}.
#set(CPACK_SYSTEM_NAME$ {CMAKE_SYSTEM_NAME})

# Directory for the installed files.
#set(CPACK_TOPLEVEL_TAG "")

# Extra commands to install components.
#set(CPACK_INSTALL_COMMANDS "")

# Extra directories to install.
#set(CPACK_INSTALLED_DIRECTORIES "")

# Registry key used when installing this project. This is only used by installer
# for Windows. The default value is based on the installation directory.
#set(CPACK_PACKAGE_INSTALL_REGISTRY_KEY "")

#  List of desktop links to create. Each desktop link requires a corresponding
# start menu shortcut as created by CPACK_PACKAGE_EXECUTABLES.
#set(CPACK_CREATE_DESKTOP_LINKS "")

# Try to find architecture
if(UNIX)
  execute_process(COMMAND uname -m OUTPUT_VARIABLE CPACK_PACKAGE_ARCHITECTURE)
  string(STRIP "${CPACK_PACKAGE_ARCHITECTURE}" CPACK_PACKAGE_ARCHITECTURE)
endif(UNIX)

# call generators
if (UNIX)
    # CPack RPM generator
    include(fedora/XiphosRPMPkg.cmake)
    # CPack Debian generator (Unix only)
    include(debian/XiphosDebianPkg.cmake)
endif (UNIX)

if(WIN32)
  set(CPACK_GENERATOR "NSIS")
  # CPack NSIS generator on Windows using the Nullsoft Installation System
  include(windows/XiphosWindowsPkg.cmake)
endif(WIN32)

# run CPack
include(CPack)
