From 48bc8b2b8226882c44faaf0a043e6fbc004241d1 Mon Sep 17 00:00:00 2001 From: Kyle Edwards Date: Fri, 15 Jun 2018 13:43:47 -0400 Subject: CPack: Move internal implementation modules into Internal/CPack directory These modules are not meant to be included by user code, they are only an internal implementation detail for CPack. Having them live in the main Modules directory with documentation was misleading, so they have been moved into Modules/Internal/CPack, and their documentation has been stripped following its move into the new "CPack Generators" section. No-op modules which contained only documentation have been removed entirely. The only module that hasn't been moved is CPackIFW, because it contains user-facing macros which would be lost if it were moved. So, the CPackIFW module has been updated with a note explaining what needs to (eventually) happen. --- Modules/CPackArchive.cmake | 39 - Modules/CPackBundle.cmake | 70 - Modules/CPackCygwin.cmake | 27 - Modules/CPackDMG.cmake | 105 -- Modules/CPackDeb.cmake | 1112 ------------ Modules/CPackFreeBSD.cmake | 248 --- Modules/CPackIFW.cmake | 8 + Modules/CPackNSIS.cmake | 138 -- Modules/CPackNuGet.cmake | 556 ------ Modules/CPackPackageMaker.cmake | 27 - Modules/CPackProductBuild.cmake | 72 - Modules/CPackRPM.cmake | 2824 ----------------------------- Modules/CPackWIX.cmake | 307 ---- Modules/CPackZIP.cmake | 31 - Modules/Internal/CPack/CPackDeb.cmake | 581 ++++++ Modules/Internal/CPack/CPackFreeBSD.cmake | 107 ++ Modules/Internal/CPack/CPackNuGet.cmake | 363 ++++ Modules/Internal/CPack/CPackRPM.cmake | 1867 +++++++++++++++++++ Modules/Internal/CPack/CPackWIX.cmake | 20 + Modules/Internal/CPack/CPackZIP.cmake | 30 + Source/CPack/WiX/cmCPackWIXGenerator.cxx | 2 +- Source/CPack/cmCPackDebGenerator.cxx | 4 +- Source/CPack/cmCPackFreeBSDGenerator.cxx | 2 +- Source/CPack/cmCPackNSISGenerator.cxx | 2 +- Source/CPack/cmCPackNuGetGenerator.cxx | 2 +- Source/CPack/cmCPackRPMGenerator.cxx | 4 +- 26 files changed, 2984 insertions(+), 5564 deletions(-) delete mode 100644 Modules/CPackArchive.cmake delete mode 100644 Modules/CPackBundle.cmake delete mode 100644 Modules/CPackCygwin.cmake delete mode 100644 Modules/CPackDMG.cmake delete mode 100644 Modules/CPackDeb.cmake delete mode 100644 Modules/CPackFreeBSD.cmake delete mode 100644 Modules/CPackNSIS.cmake delete mode 100644 Modules/CPackNuGet.cmake delete mode 100644 Modules/CPackPackageMaker.cmake delete mode 100644 Modules/CPackProductBuild.cmake delete mode 100644 Modules/CPackRPM.cmake delete mode 100644 Modules/CPackWIX.cmake delete mode 100644 Modules/CPackZIP.cmake create mode 100644 Modules/Internal/CPack/CPackDeb.cmake create mode 100644 Modules/Internal/CPack/CPackFreeBSD.cmake create mode 100644 Modules/Internal/CPack/CPackNuGet.cmake create mode 100644 Modules/Internal/CPack/CPackRPM.cmake create mode 100644 Modules/Internal/CPack/CPackWIX.cmake create mode 100644 Modules/Internal/CPack/CPackZIP.cmake diff --git a/Modules/CPackArchive.cmake b/Modules/CPackArchive.cmake deleted file mode 100644 index 741fb1f..0000000 --- a/Modules/CPackArchive.cmake +++ /dev/null @@ -1,39 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# CPackArchive -# ------------ -# -# Archive CPack generator that supports packaging of sources and binaries in -# different formats: -# -# - 7Z - 7zip - (.7z) -# - TBZ2 (.tar.bz2) -# - TGZ (.tar.gz) -# - TXZ (.tar.xz) -# - TZ (.tar.Z) -# - ZIP (.zip) -# -# Variables specific to CPack Archive generator -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# .. variable:: CPACK_ARCHIVE_FILE_NAME -# CPACK_ARCHIVE__FILE_NAME -# -# Package file name without extension which is added automatically depending -# on the archive format. -# -# * Mandatory : YES -# * Default : ``[-].`` with -# spaces replaced by '-' -# -# .. variable:: CPACK_ARCHIVE_COMPONENT_INSTALL -# -# Enable component packaging for CPackArchive -# -# * Mandatory : NO -# * Default : OFF -# -# If enabled (ON) multiple packages are generated. By default a single package -# containing files of all components is generated. diff --git a/Modules/CPackBundle.cmake b/Modules/CPackBundle.cmake deleted file mode 100644 index 8f37ef8..0000000 --- a/Modules/CPackBundle.cmake +++ /dev/null @@ -1,70 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# CPackBundle -# ----------- -# -# CPack Bundle generator (Mac OS X) specific options -# -# Variables specific to CPack Bundle generator -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# Installers built on Mac OS X using the Bundle generator use the -# aforementioned DragNDrop (CPACK_DMG_xxx) variables, plus the following -# Bundle-specific parameters (CPACK_BUNDLE_xxx). -# -# .. variable:: CPACK_BUNDLE_NAME -# -# The name of the generated bundle. This appears in the OSX finder as the -# bundle name. Required. -# -# .. variable:: CPACK_BUNDLE_PLIST -# -# Path to an OSX plist file that will be used for the generated bundle. This -# assumes that the caller has generated or specified their own Info.plist -# file. Required. -# -# .. variable:: CPACK_BUNDLE_ICON -# -# Path to an OSX icon file that will be used as the icon for the generated -# bundle. This is the icon that appears in the OSX finder for the bundle, and -# in the OSX dock when the bundle is opened. Required. -# -# .. variable:: CPACK_BUNDLE_STARTUP_COMMAND -# -# Path to a startup script. This is a path to an executable or script that -# will be run whenever an end-user double-clicks the generated bundle in the -# OSX Finder. Optional. -# -# .. variable:: CPACK_BUNDLE_APPLE_CERT_APP -# -# The name of your Apple supplied code signing certificate for the application. -# The name usually takes the form "Developer ID Application: [Name]" or -# "3rd Party Mac Developer Application: [Name]". If this variable is not set -# the application will not be signed. -# -# .. variable:: CPACK_BUNDLE_APPLE_ENTITLEMENTS -# -# The name of the plist file that contains your apple entitlements for sandboxing -# your application. This file is required for submission to the Mac App Store. -# -# .. variable:: CPACK_BUNDLE_APPLE_CODESIGN_FILES -# -# A list of additional files that you wish to be signed. You do not need to -# list the main application folder, or the main executable. You should -# list any frameworks and plugins that are included in your app bundle. -# -# .. variable:: CPACK_BUNDLE_APPLE_CODESIGN_PARAMETER -# -# Additional parameter that will passed to codesign. -# Default value: "--deep -f" -# -# .. variable:: CPACK_COMMAND_CODESIGN -# -# Path to the codesign(1) command used to sign applications with an -# Apple cert. This variable can be used to override the automatically -# detected command (or specify its location if the auto-detection fails -# to find it.) - -#Bundle Generator specific code should be put here diff --git a/Modules/CPackCygwin.cmake b/Modules/CPackCygwin.cmake deleted file mode 100644 index 6d203c3..0000000 --- a/Modules/CPackCygwin.cmake +++ /dev/null @@ -1,27 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# CPackCygwin -# ----------- -# -# Cygwin CPack generator (Cygwin). -# -# Variables specific to CPack Cygwin generator -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# The -# following variable is specific to installers build on and/or for -# Cygwin: -# -# .. variable:: CPACK_CYGWIN_PATCH_NUMBER -# -# The Cygwin patch number. FIXME: This documentation is incomplete. -# -# .. variable:: CPACK_CYGWIN_PATCH_FILE -# -# The Cygwin patch file. FIXME: This documentation is incomplete. -# -# .. variable:: CPACK_CYGWIN_BUILD_SCRIPT -# -# The Cygwin build script. FIXME: This documentation is incomplete. diff --git a/Modules/CPackDMG.cmake b/Modules/CPackDMG.cmake deleted file mode 100644 index bda600f..0000000 --- a/Modules/CPackDMG.cmake +++ /dev/null @@ -1,105 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# CPackDMG -# -------- -# -# DragNDrop CPack generator (Mac OS X). -# -# Variables specific to CPack DragNDrop generator -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# The following variables are specific to the DragNDrop installers built -# on Mac OS X: -# -# .. variable:: CPACK_DMG_VOLUME_NAME -# -# The volume name of the generated disk image. Defaults to -# CPACK_PACKAGE_FILE_NAME. -# -# .. variable:: CPACK_DMG_FORMAT -# -# The disk image format. Common values are UDRO (UDIF read-only), UDZO (UDIF -# zlib-compressed) or UDBZ (UDIF bzip2-compressed). Refer to hdiutil(1) for -# more information on other available formats. Defaults to UDZO. -# -# .. variable:: CPACK_DMG_DS_STORE -# -# Path to a custom DS_Store file. This .DS_Store file e.g. can be used to -# specify the Finder window position/geometry and layout (such as hidden -# toolbars, placement of the icons etc.). This file has to be generated by -# the Finder (either manually or through AppleScript) using a normal folder -# from which the .DS_Store file can then be extracted. -# -# .. variable:: CPACK_DMG_DS_STORE_SETUP_SCRIPT -# -# Path to a custom AppleScript file. This AppleScript is used to generate -# a .DS_Store file which specifies the Finder window position/geometry and -# layout (such as hidden toolbars, placement of the icons etc.). -# By specifying a custom AppleScript there is no need to use -# CPACK_DMG_DS_STORE, as the .DS_Store that is generated by the AppleScript -# will be packaged. -# -# .. variable:: CPACK_DMG_BACKGROUND_IMAGE -# -# Path to an image file to be used as the background. This file will be -# copied to .background/background., where ext is the original image file -# extension. The background image is installed into the image before -# CPACK_DMG_DS_STORE_SETUP_SCRIPT is executed or CPACK_DMG_DS_STORE is -# installed. By default no background image is set. -# -# .. variable:: CPACK_DMG_DISABLE_APPLICATIONS_SYMLINK -# -# Default behaviour is to include a symlink to ``/Applications`` in the DMG. -# Set this option to ``ON`` to avoid adding the symlink. -# -# .. variable:: CPACK_DMG_SLA_DIR -# -# Directory where license and menu files for different languages are stored. -# Setting this causes CPack to look for a ``.menu.txt`` and -# ``.license.txt`` file for every language defined in -# ``CPACK_DMG_SLA_LANGUAGES``. If both this variable and -# ``CPACK_RESOURCE_FILE_LICENSE`` are set, CPack will only look for the menu -# files and use the same license file for all languages. -# -# .. variable:: CPACK_DMG_SLA_LANGUAGES -# -# Languages for which a license agreement is provided when mounting the -# generated DMG. A menu file consists of 9 lines of text. The first line is -# is the name of the language itself, uppercase, in English (e.g. German). -# The other lines are translations of the following strings: -# -# - Agree -# - Disagree -# - Print -# - Save... -# - You agree to the terms of the License Agreement when you click the -# "Agree" button. -# - Software License Agreement -# - This text cannot be saved. The disk may be full or locked, or the file -# may be locked. -# - Unable to print. Make sure you have selected a printer. -# -# For every language in this list, CPack will try to find files -# ``.menu.txt`` and ``.license.txt`` in the directory -# specified by the :variable:`CPACK_DMG_SLA_DIR` variable. -# -# .. variable:: CPACK_COMMAND_HDIUTIL -# -# Path to the hdiutil(1) command used to operate on disk image files on Mac -# OS X. This variable can be used to override the automatically detected -# command (or specify its location if the auto-detection fails to find it.) -# -# .. variable:: CPACK_COMMAND_SETFILE -# -# Path to the SetFile(1) command used to set extended attributes on files and -# directories on Mac OS X. This variable can be used to override the -# automatically detected command (or specify its location if the -# auto-detection fails to find it.) -# -# .. variable:: CPACK_COMMAND_REZ -# -# Path to the Rez(1) command used to compile resources on Mac OS X. This -# variable can be used to override the automatically detected command (or -# specify its location if the auto-detection fails to find it.) diff --git a/Modules/CPackDeb.cmake b/Modules/CPackDeb.cmake deleted file mode 100644 index fdbae32..0000000 --- a/Modules/CPackDeb.cmake +++ /dev/null @@ -1,1112 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# CPackDeb -# -------- -# -# The built in (binary) CPack Deb generator (Unix only) -# -# Variables specific to CPack Debian (DEB) generator -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# CPackDeb may be used to create Deb package using :module:`CPack`. -# CPackDeb is a :module:`CPack` generator thus it uses the ``CPACK_XXX`` -# variables used by :module:`CPack`. -# -# CPackDeb generator should work on any Linux host but it will produce -# better deb package when Debian specific tools ``dpkg-xxx`` are usable on -# the build system. -# -# CPackDeb has specific features which are controlled by the specifics -# :code:`CPACK_DEBIAN_XXX` variables. -# -# :code:`CPACK_DEBIAN__XXXX` variables may be used in order to have -# **component** specific values. Note however that ```` refers to -# the **grouping name** written in upper case. It may be either a component name -# or a component GROUP name. -# -# Here are some CPackDeb wiki resources that are here for historic reasons and -# are no longer maintained but may still prove useful: -# -# - https://gitlab.kitware.com/cmake/community/wikis/doc/cpack/Configuration -# - https://gitlab.kitware.com/cmake/community/wikis/doc/cpack/PackageGenerators#deb-unix-only -# -# List of CPackDEB specific variables: -# -# .. variable:: CPACK_DEB_COMPONENT_INSTALL -# -# Enable component packaging for CPackDEB -# -# * Mandatory : NO -# * Default : OFF -# -# If enabled (ON) multiple packages are generated. By default a single package -# containing files of all components is generated. -# -# .. variable:: CPACK_DEBIAN_PACKAGE_NAME -# CPACK_DEBIAN__PACKAGE_NAME -# -# Set Package control field (variable is automatically transformed to lower -# case). -# -# * Mandatory : YES -# * Default : -# -# - :variable:`CPACK_PACKAGE_NAME` for non-component based -# installations -# - :variable:`CPACK_DEBIAN_PACKAGE_NAME` suffixed with - -# for component-based installations. -# -# See https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source -# -# .. variable:: CPACK_DEBIAN_FILE_NAME -# CPACK_DEBIAN__FILE_NAME -# -# Package file name. -# -# * Mandatory : YES -# * Default : ``[-].deb`` -# -# This may be set to ``DEB-DEFAULT`` to allow CPackDeb to generate package file -# name by itself in deb format:: -# -# _-_.deb -# -# Alternatively provided package file name must end -# with either ``.deb`` or ``.ipk`` suffix. -# -# .. note:: -# -# Preferred setting of this variable is ``DEB-DEFAULT`` but for backward -# compatibility with CPackDeb in CMake prior to version 3.6 this feature -# is disabled by default. -# -# .. note:: -# -# By using non default filenames duplicate names may occur. Duplicate files -# get overwritten and it is up to the packager to set the variables in a -# manner that will prevent such errors. -# -# .. variable:: CPACK_DEBIAN_PACKAGE_EPOCH -# -# The Debian package epoch -# -# * Mandatory : No -# * Default : - -# -# Optional number that should be incremented when changing versioning schemas -# or fixing mistakes in the version numbers of older packages. -# -# .. variable:: CPACK_DEBIAN_PACKAGE_VERSION -# -# The Debian package version -# -# * Mandatory : YES -# * Default : :variable:`CPACK_PACKAGE_VERSION` -# -# This variable may contain only alphanumerics (A-Za-z0-9) and the characters -# . + - ~ (full stop, plus, hyphen, tilde) and should start with a digit. If -# :variable:`CPACK_DEBIAN_PACKAGE_RELEASE` is not set then hyphens are not -# allowed. -# -# .. note:: -# -# For backward compatibility with CMake 3.9 and lower a failed test of this -# variable's content is not a hard error when both -# :variable:`CPACK_DEBIAN_PACKAGE_RELEASE` and -# :variable:`CPACK_DEBIAN_PACKAGE_EPOCH` variables are not set. An author -# warning is reported instead. -# -# .. variable:: CPACK_DEBIAN_PACKAGE_RELEASE -# -# The Debian package release - Debian revision number. -# -# * Mandatory : No -# * Default : - -# -# This is the numbering of the DEB package itself, i.e. the version of the -# packaging and not the version of the content (see -# :variable:`CPACK_DEBIAN_PACKAGE_VERSION`). One may change the default value -# if the previous packaging was buggy and/or you want to put here a fancy Linux -# distro specific numbering. -# -# .. variable:: CPACK_DEBIAN_PACKAGE_ARCHITECTURE -# CPACK_DEBIAN__PACKAGE_ARCHITECTURE -# -# The Debian package architecture -# -# * Mandatory : YES -# * Default : Output of :code:`dpkg --print-architecture` (or :code:`i386` -# if :code:`dpkg` is not found) -# -# .. variable:: CPACK_DEBIAN_PACKAGE_DEPENDS -# CPACK_DEBIAN__PACKAGE_DEPENDS -# -# Sets the Debian dependencies of this package. -# -# * Mandatory : NO -# * Default : -# -# - An empty string for non-component based installations -# - :variable:`CPACK_DEBIAN_PACKAGE_DEPENDS` for component-based -# installations. -# -# .. note:: -# -# If :variable:`CPACK_DEBIAN_PACKAGE_SHLIBDEPS` or -# more specifically :variable:`CPACK_DEBIAN__PACKAGE_SHLIBDEPS` -# is set for this component, the discovered dependencies will be appended -# to :variable:`CPACK_DEBIAN__PACKAGE_DEPENDS` instead of -# :variable:`CPACK_DEBIAN_PACKAGE_DEPENDS`. If -# :variable:`CPACK_DEBIAN__PACKAGE_DEPENDS` is an empty string, -# only the automatically discovered dependencies will be set for this -# component. -# -# Example:: -# -# set(CPACK_DEBIAN_PACKAGE_DEPENDS "libc6 (>= 2.3.1-6), libc6 (< 2.4)") -# -# .. variable:: CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS -# -# Sets inter component dependencies if listed with -# :variable:`CPACK_COMPONENT__DEPENDS` variables. -# -# * Mandatory : NO -# * Default : - -# -# .. variable:: CPACK_DEBIAN_PACKAGE_MAINTAINER -# -# The Debian package maintainer -# -# * Mandatory : YES -# * Default : :code:`CPACK_PACKAGE_CONTACT` -# -# .. variable:: CPACK_DEBIAN_PACKAGE_DESCRIPTION -# CPACK_COMPONENT__DESCRIPTION -# -# The Debian package description -# -# * Mandatory : YES -# * Default : -# -# - :variable:`CPACK_DEBIAN_PACKAGE_DESCRIPTION` if set or -# - :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY` -# -# -# .. variable:: CPACK_DEBIAN_PACKAGE_SECTION -# CPACK_DEBIAN__PACKAGE_SECTION -# -# Set Section control field e.g. admin, devel, doc, ... -# -# * Mandatory : YES -# * Default : "devel" -# -# See https://www.debian.org/doc/debian-policy/ch-archive.html#s-subsections -# -# .. variable:: CPACK_DEBIAN_ARCHIVE_TYPE -# -# The archive format used for creating the Debian package. -# -# * Mandatory : YES -# * Default : "paxr" -# -# Possible values are: -# -# - paxr -# - gnutar -# -# .. note:: -# -# Default pax archive format is the most portable format and generates -# packages that do not treat sparse files specially. -# GNU tar format on the other hand supports longer filenames. -# -# .. variable:: CPACK_DEBIAN_COMPRESSION_TYPE -# -# The compression used for creating the Debian package. -# -# * Mandatory : YES -# * Default : "gzip" -# -# Possible values are: -# -# - lzma -# - xz -# - bzip2 -# - gzip -# -# .. variable:: CPACK_DEBIAN_PACKAGE_PRIORITY -# CPACK_DEBIAN__PACKAGE_PRIORITY -# -# Set Priority control field e.g. required, important, standard, optional, -# extra -# -# * Mandatory : YES -# * Default : "optional" -# -# See https://www.debian.org/doc/debian-policy/ch-archive.html#s-priorities -# -# .. variable:: CPACK_DEBIAN_PACKAGE_HOMEPAGE -# -# The URL of the web site for this package, preferably (when applicable) the -# site from which the original source can be obtained and any additional -# upstream documentation or information may be found. -# -# * Mandatory : NO -# * Default : :variable:`CMAKE_PROJECT_HOMEPAGE_URL` -# -# .. note:: -# -# The content of this field is a simple URL without any surrounding -# characters such as <>. -# -# .. variable:: CPACK_DEBIAN_PACKAGE_SHLIBDEPS -# CPACK_DEBIAN__PACKAGE_SHLIBDEPS -# -# May be set to ON in order to use :code:`dpkg-shlibdeps` to generate -# better package dependency list. -# -# * Mandatory : NO -# * Default : -# -# - :variable:`CPACK_DEBIAN_PACKAGE_SHLIBDEPS` if set or -# - OFF -# -# .. note:: -# -# You may need set :variable:`CMAKE_INSTALL_RPATH` to an appropriate value -# if you use this feature, because if you don't :code:`dpkg-shlibdeps` -# may fail to find your own shared libs. -# See https://gitlab.kitware.com/cmake/community/wikis/doc/cmake/RPATH-handling -# -# .. variable:: CPACK_DEBIAN_PACKAGE_DEBUG -# -# May be set when invoking cpack in order to trace debug information -# during CPackDeb run. -# -# * Mandatory : NO -# * Default : - -# -# .. variable:: CPACK_DEBIAN_PACKAGE_PREDEPENDS -# CPACK_DEBIAN__PACKAGE_PREDEPENDS -# -# Sets the `Pre-Depends` field of the Debian package. -# Like :variable:`Depends `, except that it -# also forces :code:`dpkg` to complete installation of the packages named -# before even starting the installation of the package which declares the -# pre-dependency. -# -# * Mandatory : NO -# * Default : -# -# - An empty string for non-component based installations -# - :variable:`CPACK_DEBIAN_PACKAGE_PREDEPENDS` for component-based -# installations. -# -# See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps -# -# .. variable:: CPACK_DEBIAN_PACKAGE_ENHANCES -# CPACK_DEBIAN__PACKAGE_ENHANCES -# -# Sets the `Enhances` field of the Debian package. -# Similar to :variable:`Suggests ` but works -# in the opposite direction: declares that a package can enhance the -# functionality of another package. -# -# * Mandatory : NO -# * Default : -# -# - An empty string for non-component based installations -# - :variable:`CPACK_DEBIAN_PACKAGE_ENHANCES` for component-based -# installations. -# -# See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps -# -# .. variable:: CPACK_DEBIAN_PACKAGE_BREAKS -# CPACK_DEBIAN__PACKAGE_BREAKS -# -# Sets the `Breaks` field of the Debian package. -# When a binary package (P) declares that it breaks other packages (B), -# :code:`dpkg` will not allow the package (P) which declares `Breaks` be -# **unpacked** unless the packages that will be broken (B) are deconfigured -# first. -# As long as the package (P) is configured, the previously deconfigured -# packages (B) cannot be reconfigured again. -# -# * Mandatory : NO -# * Default : -# -# - An empty string for non-component based installations -# - :variable:`CPACK_DEBIAN_PACKAGE_BREAKS` for component-based -# installations. -# -# See https://www.debian.org/doc/debian-policy/ch-relationships.html#s-breaks -# -# .. variable:: CPACK_DEBIAN_PACKAGE_CONFLICTS -# CPACK_DEBIAN__PACKAGE_CONFLICTS -# -# Sets the `Conflicts` field of the Debian package. -# When one binary package declares a conflict with another using a `Conflicts` -# field, :code:`dpkg` will not allow them to be unpacked on the system at -# the same time. -# -# * Mandatory : NO -# * Default : -# -# - An empty string for non-component based installations -# - :variable:`CPACK_DEBIAN_PACKAGE_CONFLICTS` for component-based -# installations. -# -# See https://www.debian.org/doc/debian-policy/ch-relationships.html#s-conflicts -# -# .. note:: -# -# This is a stronger restriction than -# :variable:`Breaks `, which prevents the -# broken package from being configured while the breaking package is in -# the "Unpacked" state but allows both packages to be unpacked at the same -# time. -# -# .. variable:: CPACK_DEBIAN_PACKAGE_PROVIDES -# CPACK_DEBIAN__PACKAGE_PROVIDES -# -# Sets the `Provides` field of the Debian package. -# A virtual package is one which appears in the `Provides` control field of -# another package. -# -# * Mandatory : NO -# * Default : -# -# - An empty string for non-component based installations -# - :variable:`CPACK_DEBIAN_PACKAGE_PROVIDES` for component-based -# installations. -# -# See https://www.debian.org/doc/debian-policy/ch-relationships.html#s-virtual -# -# .. variable:: CPACK_DEBIAN_PACKAGE_REPLACES -# CPACK_DEBIAN__PACKAGE_REPLACES -# -# Sets the `Replaces` field of the Debian package. -# Packages can declare in their control file that they should overwrite -# files in certain other packages, or completely replace other packages. -# -# * Mandatory : NO -# * Default : -# -# - An empty string for non-component based installations -# - :variable:`CPACK_DEBIAN_PACKAGE_REPLACES` for component-based -# installations. -# -# See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps -# -# .. variable:: CPACK_DEBIAN_PACKAGE_RECOMMENDS -# CPACK_DEBIAN__PACKAGE_RECOMMENDS -# -# Sets the `Recommends` field of the Debian package. -# Allows packages to declare a strong, but not absolute, dependency on other -# packages. -# -# * Mandatory : NO -# * Default : -# -# - An empty string for non-component based installations -# - :variable:`CPACK_DEBIAN_PACKAGE_RECOMMENDS` for component-based -# installations. -# -# See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps -# -# .. variable:: CPACK_DEBIAN_PACKAGE_SUGGESTS -# CPACK_DEBIAN__PACKAGE_SUGGESTS -# -# Sets the `Suggests` field of the Debian package. -# Allows packages to declare a suggested package install grouping. -# -# * Mandatory : NO -# * Default : -# -# - An empty string for non-component based installations -# - :variable:`CPACK_DEBIAN_PACKAGE_SUGGESTS` for component-based -# installations. -# -# See http://www.debian.org/doc/debian-policy/ch-relationships.html#s-binarydeps -# -# .. variable:: CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS -# -# * Mandatory : NO -# * Default : OFF -# -# Allows to generate shlibs control file automatically. Compatibility is defined by -# :variable:`CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY` variable value. -# -# .. note:: -# -# Libraries are only considered if they have both library name and version -# set. This can be done by setting SOVERSION property with -# :command:`set_target_properties` command. -# -# .. variable:: CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY -# -# Compatibility policy for auto-generated shlibs control file. -# -# * Mandatory : NO -# * Default : "=" -# -# Defines compatibility policy for auto-generated shlibs control file. -# Possible values: "=", ">=" -# -# See https://www.debian.org/doc/debian-policy/ch-sharedlibs.html#s-sharedlibs-shlibdeps -# -# .. variable:: CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA -# CPACK_DEBIAN__PACKAGE_CONTROL_EXTRA -# -# This variable allow advanced user to add custom script to the -# control.tar.gz. -# Typical usage is for conffiles, postinst, postrm, prerm. -# -# * Mandatory : NO -# * Default : - -# -# Usage:: -# -# set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA -# "${CMAKE_CURRENT_SOURCE_DIR}/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm") -# -# .. note:: -# -# The original permissions of the files will be used in the final -# package unless the variable -# :variable:`CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION` is set. -# In particular, the scripts should have the proper executable -# flag prior to the generation of the package. -# -# .. variable:: CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION -# CPACK_DEBIAN__PACKAGE_CONTROL_STRICT_PERMISSION -# -# This variable indicates if the Debian policy on control files should be -# strictly followed. -# -# * Mandatory : NO -# * Default : FALSE -# -# Usage:: -# -# set(CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION TRUE) -# -# .. note:: -# -# This overrides the permissions on the original files, following the rules -# set by Debian policy -# https://www.debian.org/doc/debian-policy/ch-files.html#s-permissions-owners -# -# .. variable:: CPACK_DEBIAN_PACKAGE_SOURCE -# CPACK_DEBIAN__PACKAGE_SOURCE -# -# Sets the ``Source`` field of the binary Debian package. -# When the binary package name is not the same as the source package name -# (in particular when several components/binaries are generated from one -# source) the source from which the binary has been generated should be -# indicated with the field ``Source``. -# -# * Mandatory : NO -# * Default : -# -# - An empty string for non-component based installations -# - :variable:`CPACK_DEBIAN_PACKAGE_SOURCE` for component-based -# installations. -# -# See https://www.debian.org/doc/debian-policy/ch-controlfields.html#s-f-Source -# -# .. note:: -# -# This value is not interpreted. It is possible to pass an optional -# revision number of the referenced source package as well. -# -# Building Debian packages on Windows -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# To communicate UNIX file permissions from the install stage -# to the CPack DEB generator the "cmake_mode_t" NTFS -# alternate data stream (ADT) is used. -# -# When a filesystem without ADT support is used only owner read/write -# permissions can be preserved. - -# CPack script for creating Debian package -# Author: Mathieu Malaterre -# -# http://wiki.debian.org/HowToPackageForDebian - -if(CMAKE_BINARY_DIR) - message(FATAL_ERROR "CPackDeb.cmake may only be used by CPack internally.") -endif() - -function(cpack_deb_variable_fallback OUTPUT_VAR_NAME) - set(FALLBACK_VAR_NAMES ${ARGN}) - - foreach(variable_name IN LISTS FALLBACK_VAR_NAMES) - if(${variable_name}) - set(${OUTPUT_VAR_NAME} "${${variable_name}}" PARENT_SCOPE) - break() - endif() - endforeach() -endfunction() - -function(get_component_package_name var component) - string(TOUPPER "${component}" component_upcase) - if(CPACK_DEBIAN_${component_upcase}_PACKAGE_NAME) - string(TOLOWER "${CPACK_DEBIAN_${component_upcase}_PACKAGE_NAME}" package_name) - else() - string(TOLOWER "${CPACK_DEBIAN_PACKAGE_NAME}-${component}" package_name) - endif() - - set("${var}" "${package_name}" PARENT_SCOPE) -endfunction() - -#extract library name and version for given shared object -function(extract_so_info shared_object libname version) - if(READELF_EXECUTABLE) - execute_process(COMMAND "${READELF_EXECUTABLE}" -d "${shared_object}" - WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" - RESULT_VARIABLE result - OUTPUT_VARIABLE output - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - if(result EQUAL 0) - string(REGEX MATCH "\\(SONAME\\)[^\n]*\\[([^\n]+)\\.so\\.([^\n]*)\\]" soname "${output}") - set(${libname} "${CMAKE_MATCH_1}" PARENT_SCOPE) - set(${version} "${CMAKE_MATCH_2}" PARENT_SCOPE) - else() - message(WARNING "Error running readelf for \"${shared_object}\"") - endif() - else() - message(FATAL_ERROR "Readelf utility is not available.") - endif() -endfunction() - -function(cpack_deb_prepare_package_vars) - # CPACK_DEBIAN_PACKAGE_SHLIBDEPS - # If specify OFF, only user depends are used - if(NOT DEFINED CPACK_DEBIAN_PACKAGE_SHLIBDEPS) - set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OFF) - endif() - - set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_DEB_PACKAGE_COMPONENT_PART_PATH}") - - # per component automatic discover: some of the component might not have - # binaries. - if(CPACK_DEB_PACKAGE_COMPONENT) - string(TOUPPER "${CPACK_DEB_PACKAGE_COMPONENT}" _local_component_name) - set(_component_shlibdeps_var "CPACK_DEBIAN_${_local_component_name}_PACKAGE_SHLIBDEPS") - - # if set, overrides the global configuration - if(DEFINED ${_component_shlibdeps_var}) - set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS "${${_component_shlibdeps_var}}") - if(CPACK_DEBIAN_PACKAGE_DEBUG) - message("CPackDeb Debug: component '${CPACK_DEB_PACKAGE_COMPONENT}' dpkg-shlibdeps set to ${CPACK_DEBIAN_PACKAGE_SHLIBDEPS}") - endif() - endif() - endif() - - if(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OR CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS) - # Generating binary list - Get type of all install files - file(GLOB_RECURSE FILE_PATHS_ LIST_DIRECTORIES false RELATIVE "${WDIR}" "${WDIR}/*") - - find_program(FILE_EXECUTABLE file) - if(NOT FILE_EXECUTABLE) - message(FATAL_ERROR "CPackDeb: file utility is not available. CPACK_DEBIAN_PACKAGE_SHLIBDEPS and CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS options are not available.") - endif() - - # get file info so that we can determine if file is executable or not - unset(CPACK_DEB_INSTALL_FILES) - foreach(FILE_ IN LISTS FILE_PATHS_) - execute_process(COMMAND env LC_ALL=C ${FILE_EXECUTABLE} "./${FILE_}" - WORKING_DIRECTORY "${WDIR}" - RESULT_VARIABLE FILE_RESULT_ - OUTPUT_VARIABLE INSTALL_FILE_) - if(NOT FILE_RESULT_ EQUAL 0) - message (FATAL_ERROR "CPackDeb: execution of command: '${FILE_EXECUTABLE} ./${FILE_}' failed with exit code: ${FILE_RESULT_}") - endif() - list(APPEND CPACK_DEB_INSTALL_FILES "${INSTALL_FILE_}") - endforeach() - - # Only dynamically linked ELF files are included - # Extract only file name infront of ":" - foreach(_FILE IN LISTS CPACK_DEB_INSTALL_FILES) - if(_FILE MATCHES "ELF.*dynamically linked") - string(REGEX MATCH "(^.*):" _FILE_NAME "${_FILE}") - list(APPEND CPACK_DEB_BINARY_FILES "${CMAKE_MATCH_1}") - set(CONTAINS_EXECUTABLE_FILES_ TRUE) - endif() - if(_FILE MATCHES "ELF.*shared object") - string(REGEX MATCH "(^.*):" _FILE_NAME "${_FILE}") - list(APPEND CPACK_DEB_SHARED_OBJECT_FILES "${CMAKE_MATCH_1}") - endif() - endforeach() - endif() - - if(CPACK_DEBIAN_PACKAGE_SHLIBDEPS) - # dpkg-shlibdeps is a Debian utility for generating dependency list - find_program(SHLIBDEPS_EXECUTABLE dpkg-shlibdeps) - - if(SHLIBDEPS_EXECUTABLE) - # Check version of the dpkg-shlibdeps tool using CPackDEB method - execute_process(COMMAND env LC_ALL=C ${SHLIBDEPS_EXECUTABLE} --version - OUTPUT_VARIABLE _TMP_VERSION - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - if(_TMP_VERSION MATCHES "dpkg-shlibdeps version ([0-9]+\\.[0-9]+\\.[0-9]+)") - set(SHLIBDEPS_EXECUTABLE_VERSION "${CMAKE_MATCH_1}") - else() - set(SHLIBDEPS_EXECUTABLE_VERSION "") - endif() - - if(CPACK_DEBIAN_PACKAGE_DEBUG) - message("CPackDeb Debug: dpkg-shlibdeps --version output is '${_TMP_VERSION}'") - message("CPackDeb Debug: dpkg-shlibdeps version is <${SHLIBDEPS_EXECUTABLE_VERSION}>") - endif() - - if(CONTAINS_EXECUTABLE_FILES_) - message("CPackDeb: - Generating dependency list") - - # Create blank control file for running dpkg-shlibdeps - # There might be some other way to invoke dpkg-shlibdeps without creating this file - # but standard debian package should not have anything that can collide with this file or directory - file(MAKE_DIRECTORY ${CPACK_TEMPORARY_DIRECTORY}/debian) - file(WRITE ${CPACK_TEMPORARY_DIRECTORY}/debian/control "") - - # Create a DEBIAN directory so that dpkg-shlibdeps can find the package dir when resolving $ORIGIN. - file(MAKE_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}/DEBIAN") - - # Add --ignore-missing-info if the tool supports it - execute_process(COMMAND env LC_ALL=C ${SHLIBDEPS_EXECUTABLE} --help - OUTPUT_VARIABLE _TMP_HELP - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - if(_TMP_HELP MATCHES "--ignore-missing-info") - set(IGNORE_MISSING_INFO_FLAG "--ignore-missing-info") - endif() - - # Execute dpkg-shlibdeps - # --ignore-missing-info : allow dpkg-shlibdeps to run even if some libs do not belong to a package - # -O : print to STDOUT - execute_process(COMMAND ${SHLIBDEPS_EXECUTABLE} ${IGNORE_MISSING_INFO_FLAG} -O ${CPACK_DEB_BINARY_FILES} - WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" - OUTPUT_VARIABLE SHLIBDEPS_OUTPUT - RESULT_VARIABLE SHLIBDEPS_RESULT - ERROR_VARIABLE SHLIBDEPS_ERROR - OUTPUT_STRIP_TRAILING_WHITESPACE ) - if(CPACK_DEBIAN_PACKAGE_DEBUG) - # dpkg-shlibdeps will throw some warnings if some input files are not binary - message( "CPackDeb Debug: dpkg-shlibdeps warnings \n${SHLIBDEPS_ERROR}") - endif() - if(NOT SHLIBDEPS_RESULT EQUAL 0) - message (FATAL_ERROR "CPackDeb: dpkg-shlibdeps: '${SHLIBDEPS_ERROR}';\n" - "executed command: '${SHLIBDEPS_EXECUTABLE} ${IGNORE_MISSING_INFO_FLAG} -O ${CPACK_DEB_BINARY_FILES}';\n" - "found files: '${INSTALL_FILE_}';\n" - "files info: '${CPACK_DEB_INSTALL_FILES}';\n" - "binary files: '${CPACK_DEB_BINARY_FILES}'") - endif() - - #Get rid of prefix generated by dpkg-shlibdeps - string(REGEX REPLACE "^.*Depends=" "" CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS "${SHLIBDEPS_OUTPUT}") - - if(CPACK_DEBIAN_PACKAGE_DEBUG) - message("CPackDeb Debug: Found dependency: ${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS} from output ${SHLIBDEPS_OUTPUT}") - endif() - - # Remove blank control file - # Might not be safe if package actual contain file or directory named debian - file(REMOVE_RECURSE "${CPACK_TEMPORARY_DIRECTORY}/debian") - - # remove temporary directory that was created only for dpkg-shlibdeps execution - file(REMOVE_RECURSE "${CPACK_TEMPORARY_DIRECTORY}/DEBIAN") - else() - if(CPACK_DEBIAN_PACKAGE_DEBUG) - message(AUTHOR_WARNING "CPackDeb Debug: Using only user-provided depends because package does not contain executable files that link to shared libraries.") - endif() - endif() - else() - message("CPackDeb: Using only user-provided dependencies because dpkg-shlibdeps is not found.") - endif() - - else() - if(CPACK_DEBIAN_PACKAGE_DEBUG) - message("CPackDeb Debug: Using only user-provided dependencies") - endif() - endif() - - # Let's define the control file found in debian package: - - # Binary package: - # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles - - # DEBIAN/control - # debian policy enforce lower case for package name - # Package: (mandatory) - if(NOT CPACK_DEBIAN_PACKAGE_NAME) - string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME) - endif() - - # Version: (mandatory) - if(NOT CPACK_DEBIAN_PACKAGE_VERSION) - if(NOT CPACK_PACKAGE_VERSION) - message(FATAL_ERROR "CPackDeb: Debian package requires a package version") - endif() - set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}) - endif() - - if(DEFINED CPACK_DEBIAN_PACKAGE_RELEASE OR DEFINED CPACK_DEBIAN_PACKAGE_EPOCH) - # only test the version format if CPACK_DEBIAN_PACKAGE_RELEASE or - # CPACK_DEBIAN_PACKAGE_EPOCH is set - if(NOT CPACK_DEBIAN_PACKAGE_VERSION MATCHES "^[0-9][A-Za-z0-9.+~-]*$") - message(FATAL_ERROR - "CPackDeb: Debian package version must confirm to \"^[0-9][A-Za-z0-9.+~-]*$\" regex!") - endif() - else() - # before CMake 3.10 version format was not tested so only warn to preserve - # backward compatibility - if(NOT CPACK_DEBIAN_PACKAGE_VERSION MATCHES "^([0-9]+:)?[0-9][A-Za-z0-9.+~-]*$") - message(AUTHOR_WARNING - "CPackDeb: Debian package versioning ([:][-])" - " should confirm to \"^([0-9]+:)?[0-9][A-Za-z0-9.+~-]*$\" regex in" - " order to satisfy Debian packaging rules.") - endif() - endif() - - if(CPACK_DEBIAN_PACKAGE_RELEASE) - if(NOT CPACK_DEBIAN_PACKAGE_RELEASE MATCHES "^[A-Za-z0-9.+~]+$") - message(FATAL_ERROR - "CPackDeb: Debian package release must confirm to \"^[A-Za-z0-9.+~]+$\" regex!") - endif() - string(APPEND CPACK_DEBIAN_PACKAGE_VERSION - "-${CPACK_DEBIAN_PACKAGE_RELEASE}") - elseif(DEFINED CPACK_DEBIAN_PACKAGE_EPOCH) - # only test the version format if CPACK_DEBIAN_PACKAGE_RELEASE or - # CPACK_DEBIAN_PACKAGE_EPOCH is set - versions CPack/Deb generator before - # CMake 3.10 did not check for version format so we have to preserve - # backward compatibility - if(CPACK_DEBIAN_PACKAGE_VERSION MATCHES ".*-.*") - message(FATAL_ERROR - "CPackDeb: Debian package version must not contain hyphens when CPACK_DEBIAN_PACKAGE_RELEASE is not provided!") - endif() - endif() - - if(CPACK_DEBIAN_PACKAGE_EPOCH) - if(NOT CPACK_DEBIAN_PACKAGE_EPOCH MATCHES "^[0-9]+$") - message(FATAL_ERROR - "CPackDeb: Debian package epoch must confirm to \"^[0-9]+$\" regex!") - endif() - set(CPACK_DEBIAN_PACKAGE_VERSION - "${CPACK_DEBIAN_PACKAGE_EPOCH}:${CPACK_DEBIAN_PACKAGE_VERSION}") - endif() - - # Architecture: (mandatory) - if(CPACK_DEB_PACKAGE_COMPONENT AND CPACK_DEBIAN_${_local_component_name}_PACKAGE_ARCHITECTURE) - set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CPACK_DEBIAN_${_local_component_name}_PACKAGE_ARCHITECTURE}") - elseif(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE) - # There is no such thing as i686 architecture on debian, you should use i386 instead - # $ dpkg --print-architecture - find_program(DPKG_CMD dpkg) - if(NOT DPKG_CMD) - message(STATUS "CPackDeb: Can not find dpkg in your path, default to i386.") - set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386) - endif() - execute_process(COMMAND "${DPKG_CMD}" --print-architecture - OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE - OUTPUT_STRIP_TRAILING_WHITESPACE - ) - endif() - - # Source: (optional) - # in case several packages are constructed from a unique source - # (multipackaging), the source may be indicated as well. - # The source might contain a version if the generated package - # version is different from the source version - if(NOT CPACK_DEBIAN_PACKAGE_SOURCE) - set(CPACK_DEBIAN_PACKAGE_SOURCE "") - endif() - - # have a look at get_property(result GLOBAL PROPERTY ENABLED_FEATURES), - # this returns the successful find_package() calls, maybe this can help - # Depends: - # You should set: DEBIAN_PACKAGE_DEPENDS - # TODO: automate 'objdump -p | grep NEEDED' - - # if per-component variable, overrides the global CPACK_DEBIAN_PACKAGE_${variable_type_} - # automatic dependency discovery will be performed afterwards. - if(CPACK_DEB_PACKAGE_COMPONENT) - foreach(value_type_ DEPENDS RECOMMENDS SUGGESTS PREDEPENDS ENHANCES BREAKS CONFLICTS PROVIDES REPLACES SOURCE SECTION PRIORITY NAME) - set(_component_var "CPACK_DEBIAN_${_local_component_name}_PACKAGE_${value_type_}") - - # if set, overrides the global variable - if(DEFINED ${_component_var}) - set(CPACK_DEBIAN_PACKAGE_${value_type_} "${${_component_var}}") - if(CPACK_DEBIAN_PACKAGE_DEBUG) - message("CPackDeb Debug: component '${_local_component_name}' ${value_type_} " - "value set to '${CPACK_DEBIAN_PACKAGE_${value_type_}}'") - endif() - endif() - endforeach() - - if(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS) - set(COMPONENT_DEPENDS "") - foreach (_PACK ${CPACK_COMPONENT_${_local_component_name}_DEPENDS}) - get_component_package_name(_PACK_NAME "${_PACK}") - if(COMPONENT_DEPENDS) - set(COMPONENT_DEPENDS "${_PACK_NAME} (= ${CPACK_DEBIAN_PACKAGE_VERSION}), ${COMPONENT_DEPENDS}") - else() - set(COMPONENT_DEPENDS "${_PACK_NAME} (= ${CPACK_DEBIAN_PACKAGE_VERSION})") - endif() - endforeach() - if(COMPONENT_DEPENDS) - if(CPACK_DEBIAN_PACKAGE_DEPENDS) - set(CPACK_DEBIAN_PACKAGE_DEPENDS "${COMPONENT_DEPENDS}, ${CPACK_DEBIAN_PACKAGE_DEPENDS}") - else() - set(CPACK_DEBIAN_PACKAGE_DEPENDS "${COMPONENT_DEPENDS}") - endif() - endif() - endif() - endif() - - # at this point, the CPACK_DEBIAN_PACKAGE_DEPENDS is properly set - # to the minimal dependency of the package - # Append automatically discovered dependencies . - if(NOT "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}" STREQUAL "") - if (CPACK_DEBIAN_PACKAGE_DEPENDS) - set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, ${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}") - else () - set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}") - endif () - endif() - - if(NOT CPACK_DEBIAN_PACKAGE_DEPENDS) - message(STATUS "CPACK_DEBIAN_PACKAGE_DEPENDS not set, the package will have no dependencies.") - endif() - - # Maintainer: (mandatory) - if(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER) - if(NOT CPACK_PACKAGE_CONTACT) - message(FATAL_ERROR "CPackDeb: Debian package requires a maintainer for a package, set CPACK_PACKAGE_CONTACT or CPACK_DEBIAN_PACKAGE_MAINTAINER") - endif() - set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT}) - endif() - - # Description: (mandatory) - if(NOT CPACK_DEB_PACKAGE_COMPONENT) - if(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION) - if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY) - message(FATAL_ERROR "CPackDeb: Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION") - endif() - set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}) - endif() - else() - set(component_description_var CPACK_COMPONENT_${_local_component_name}_DESCRIPTION) - - # component description overrides package description - if(${component_description_var}) - set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${${component_description_var}}) - elseif(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION) - if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY) - message(FATAL_ERROR "CPackDeb: Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION or ${component_description_var}") - endif() - set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}) - endif() - endif() - - # Homepage: (optional) - if(NOT CPACK_DEBIAN_PACKAGE_HOMEPAGE AND CMAKE_PROJECT_HOMEPAGE_URL) - set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CMAKE_PROJECT_HOMEPAGE_URL}") - endif() - - # Section: (recommended) - if(NOT CPACK_DEBIAN_PACKAGE_SECTION) - set(CPACK_DEBIAN_PACKAGE_SECTION "devel") - endif() - - # Priority: (recommended) - if(NOT CPACK_DEBIAN_PACKAGE_PRIORITY) - set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") - endif() - - if(CPACK_DEBIAN_ARCHIVE_TYPE) - set(archive_types_ "paxr;gnutar") - if(NOT CPACK_DEBIAN_ARCHIVE_TYPE IN_LIST archive_types_) - message(FATAL_ERROR "CPACK_DEBIAN_ARCHIVE_TYPE set to unsupported" - "type ${CPACK_DEBIAN_ARCHIVE_TYPE}") - endif() - else() - set(CPACK_DEBIAN_ARCHIVE_TYPE "paxr") - endif() - - # Compression: (recommended) - if(NOT CPACK_DEBIAN_COMPRESSION_TYPE) - set(CPACK_DEBIAN_COMPRESSION_TYPE "gzip") - endif() - - # Recommends: - # You should set: CPACK_DEBIAN_PACKAGE_RECOMMENDS - - # Suggests: - # You should set: CPACK_DEBIAN_PACKAGE_SUGGESTS - - # CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA - # This variable allow advanced user to add custom script to the control.tar.gz (inside the .deb archive) - # Typical examples are: - # - conffiles - # - postinst - # - postrm - # - prerm - # Usage: - # set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA - # "${CMAKE_CURRENT_SOURCE_DIR}/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm") - - # Are we packaging components ? - if(CPACK_DEB_PACKAGE_COMPONENT) - # override values with per component version if set - foreach(VAR_NAME_ "PACKAGE_CONTROL_EXTRA" "PACKAGE_CONTROL_STRICT_PERMISSION") - if(CPACK_DEBIAN_${_local_component_name}_${VAR_NAME_}) - set(CPACK_DEBIAN_${VAR_NAME_} "${CPACK_DEBIAN_${_local_component_name}_${VAR_NAME_}}") - endif() - endforeach() - get_component_package_name(CPACK_DEBIAN_PACKAGE_NAME ${_local_component_name}) - endif() - - set(CPACK_DEBIAN_PACKAGE_SHLIBS_LIST "") - - if (NOT CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY) - set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY "=") - endif() - - find_program(READELF_EXECUTABLE NAMES readelf) - - if(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS) - if(READELF_EXECUTABLE) - foreach(_FILE IN LISTS CPACK_DEB_SHARED_OBJECT_FILES) - extract_so_info("${_FILE}" libname soversion) - if(libname AND DEFINED soversion) - list(APPEND CPACK_DEBIAN_PACKAGE_SHLIBS_LIST - "${libname} ${soversion} ${CPACK_DEBIAN_PACKAGE_NAME} (${CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY} ${CPACK_DEBIAN_PACKAGE_VERSION})") - else() - message(AUTHOR_WARNING "Shared library '${_FILE}' is missing soname or soversion. Library will not be added to DEBIAN/shlibs control file.") - endif() - endforeach() - if (CPACK_DEBIAN_PACKAGE_SHLIBS_LIST) - string(REPLACE ";" "\n" CPACK_DEBIAN_PACKAGE_SHLIBS_LIST "${CPACK_DEBIAN_PACKAGE_SHLIBS_LIST}") - endif() - else() - message(FATAL_ERROR "Readelf utility is not available. CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS option is not available.") - endif() - endif() - - # add ldconfig call in default postrm and postint - set(CPACK_ADD_LDCONFIG_CALL 0) - foreach(_FILE ${CPACK_DEB_SHARED_OBJECT_FILES}) - get_filename_component(_DIR ${_FILE} DIRECTORY) - # all files in CPACK_DEB_SHARED_OBJECT_FILES have dot at the beginning - if(_DIR STREQUAL "./lib" OR _DIR STREQUAL "./usr/lib") - set(CPACK_ADD_LDCONFIG_CALL 1) - endif() - endforeach() - - if(CPACK_ADD_LDCONFIG_CALL) - set(CPACK_DEBIAN_GENERATE_POSTINST 1) - set(CPACK_DEBIAN_GENERATE_POSTRM 1) - foreach(f ${PACKAGE_CONTROL_EXTRA}) - get_filename_component(n "${f}" NAME) - if("${n}" STREQUAL "postinst") - set(CPACK_DEBIAN_GENERATE_POSTINST 0) - endif() - if("${n}" STREQUAL "postrm") - set(CPACK_DEBIAN_GENERATE_POSTRM 0) - endif() - endforeach() - else() - set(CPACK_DEBIAN_GENERATE_POSTINST 0) - set(CPACK_DEBIAN_GENERATE_POSTRM 0) - endif() - - cpack_deb_variable_fallback("CPACK_DEBIAN_FILE_NAME" - "CPACK_DEBIAN_${_local_component_name}_FILE_NAME" - "CPACK_DEBIAN_FILE_NAME") - if(CPACK_DEBIAN_FILE_NAME) - if(CPACK_DEBIAN_FILE_NAME STREQUAL "DEB-DEFAULT") - # Patch package file name to be in correct debian format: - # _-_.deb - set(CPACK_OUTPUT_FILE_NAME - "${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") - else() - if(NOT CPACK_DEBIAN_FILE_NAME MATCHES ".*\\.(deb|ipk)") - message(FATAL_ERROR "'${CPACK_DEBIAN_FILE_NAME}' is not a valid DEB package file name as it must end with '.deb' or '.ipk'!") - endif() - - set(CPACK_OUTPUT_FILE_NAME "${CPACK_DEBIAN_FILE_NAME}") - endif() - - set(CPACK_TEMPORARY_PACKAGE_FILE_NAME "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_OUTPUT_FILE_NAME}") - get_filename_component(BINARY_DIR "${CPACK_OUTPUT_FILE_PATH}" DIRECTORY) - set(CPACK_OUTPUT_FILE_PATH "${BINARY_DIR}/${CPACK_OUTPUT_FILE_NAME}") - endif() # else() back compatibility - don't change the name - - # Print out some debug information if we were asked for that - if(CPACK_DEBIAN_PACKAGE_DEBUG) - message("CPackDeb:Debug: CPACK_TOPLEVEL_DIRECTORY = '${CPACK_TOPLEVEL_DIRECTORY}'") - message("CPackDeb:Debug: CPACK_TOPLEVEL_TAG = '${CPACK_TOPLEVEL_TAG}'") - message("CPackDeb:Debug: CPACK_TEMPORARY_DIRECTORY = '${CPACK_TEMPORARY_DIRECTORY}'") - message("CPackDeb:Debug: CPACK_OUTPUT_FILE_NAME = '${CPACK_OUTPUT_FILE_NAME}'") - message("CPackDeb:Debug: CPACK_OUTPUT_FILE_PATH = '${CPACK_OUTPUT_FILE_PATH}'") - message("CPackDeb:Debug: CPACK_PACKAGE_FILE_NAME = '${CPACK_PACKAGE_FILE_NAME}'") - message("CPackDeb:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = '${CPACK_PACKAGE_INSTALL_DIRECTORY}'") - message("CPackDeb:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = '${CPACK_TEMPORARY_PACKAGE_FILE_NAME}'") - message("CPackDeb:Debug: CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION = '${CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION}'") - message("CPackDeb:Debug: CPACK_DEBIAN_PACKAGE_SOURCE = '${CPACK_DEBIAN_PACKAGE_SOURCE}'") - endif() - - # For debian source packages: - # debian/control - # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-sourcecontrolfiles - - # .dsc - # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-debiansourcecontrolfiles - - # Builds-Depends: - #if(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS) - # set(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS - # "debhelper (>> 5.0.0), libncurses5-dev, tcl8.4" - # ) - #endif() - - # move variables to parent scope so that they may be used to create debian package - set(GEN_CPACK_OUTPUT_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}" PARENT_SCOPE) - set(GEN_CPACK_TEMPORARY_PACKAGE_FILE_NAME "${CPACK_TEMPORARY_PACKAGE_FILE_NAME}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_NAME "${CPACK_DEBIAN_PACKAGE_NAME}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_DEBIAN_PACKAGE_VERSION}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_SECTION "${CPACK_DEBIAN_PACKAGE_SECTION}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_PRIORITY "${CPACK_DEBIAN_PACKAGE_PRIORITY}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_DEBIAN_PACKAGE_MAINTAINER}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_DEBIAN_PACKAGE_DESCRIPTION}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_ARCHIVE_TYPE "${CPACK_DEBIAN_ARCHIVE_TYPE}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_COMPRESSION_TYPE "${CPACK_DEBIAN_COMPRESSION_TYPE}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_RECOMMENDS "${CPACK_DEBIAN_PACKAGE_RECOMMENDS}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_SUGGESTS "${CPACK_DEBIAN_PACKAGE_SUGGESTS}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_DEBIAN_PACKAGE_HOMEPAGE}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_PREDEPENDS "${CPACK_DEBIAN_PACKAGE_PREDEPENDS}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_ENHANCES "${CPACK_DEBIAN_PACKAGE_ENHANCES}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_BREAKS "${CPACK_DEBIAN_PACKAGE_BREAKS}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_CONFLICTS "${CPACK_DEBIAN_PACKAGE_CONFLICTS}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_PROVIDES "${CPACK_DEBIAN_PACKAGE_PROVIDES}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_REPLACES "${CPACK_DEBIAN_PACKAGE_REPLACES}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_SHLIBS "${CPACK_DEBIAN_PACKAGE_SHLIBS_LIST}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION - "${CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_PACKAGE_SOURCE - "${CPACK_DEBIAN_PACKAGE_SOURCE}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_GENERATE_POSTINST "${CPACK_DEBIAN_GENERATE_POSTINST}" PARENT_SCOPE) - set(GEN_CPACK_DEBIAN_GENERATE_POSTRM "${CPACK_DEBIAN_GENERATE_POSTRM}" PARENT_SCOPE) - set(GEN_WDIR "${WDIR}" PARENT_SCOPE) -endfunction() - -cpack_deb_prepare_package_vars() diff --git a/Modules/CPackFreeBSD.cmake b/Modules/CPackFreeBSD.cmake deleted file mode 100644 index b681d4f..0000000 --- a/Modules/CPackFreeBSD.cmake +++ /dev/null @@ -1,248 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#[=======================================================================[.rst: -CPackFreeBSD ------------- - -The built in (binary) CPack FreeBSD (pkg) generator (Unix only) - -Variables specific to CPack FreeBSD (pkg) generator -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -CPackFreeBSD may be used to create pkg(8) packages -- these may be used -on FreeBSD, DragonflyBSD, NetBSD, OpenBSD, but also on Linux or OSX, -depending on the installed package-management tools -- using :module:`CPack`. - -CPackFreeBSD is a :module:`CPack` generator and uses the ``CPACK_XXX`` -variables used by :module:`CPack`. It tries to re-use packaging information -that may already be specified for Debian packages for the :module:`CPackDeb` -generator. it also tries to re-use RPM packaging information when Debian -does not specify. - -CPackFreeBSD generator should work on any host with libpkg installed. The -packages it produces are specific to the host architecture and ABI. - -CPackFreeBSD sets package-metadata through :code:`CPACK_FREEBSD_XXX` variables. -CPackFreeBSD, unlike CPackDeb, does not specially support componentized -packages; a single package is created from all the software artifacts -created through CMake. - -All of the variables can be set specifically for FreeBSD packaging in -the CPackConfig file or in CMakeLists.txt, but most of them have defaults -that use general settings (e.g. CMAKE_PROJECT_NAME) or Debian-specific -variables when those make sense (e.g. the homepage of an upstream project -is usually unchanged by the flavor of packaging). When there is no Debian -information to fall back on, but the RPM packaging has it, fall back to -the RPM information (e.g. package license). - -.. variable:: CPACK_FREEBSD_PACKAGE_NAME - - Sets the package name (in the package manifest, but also affects the - output filename). - - * Mandatory: YES - * Default: - - - :variable:`CPACK_PACKAGE_NAME` (this is always set by CPack itself, - based on CMAKE_PROJECT_NAME). - -.. variable:: CPACK_FREEBSD_PACKAGE_COMMENT - - Sets the package comment. This is the short description displayed by - pkg(8) in standard "pkg info" output. - - * Mandatory: YES - * Default: - - - :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY` (this is always set - by CPack itself, if nothing else sets it explicitly). - - :variable:`PROJECT_DESCRIPTION` (this can be set with the DESCRIPTION - parameter for :command:`project`). - -.. variable:: CPACK_FREEBSD_PACKAGE_DESCRIPTION - - Sets the package description. This is the long description of the package, - given by "pkg info" with a specific package as argument. - - * Mandatory: YES - * Default: - - - :variable:`CPACK_DEBIAN_PACKAGE_DESCRIPTION` (this may be set already - for Debian packaging, so we may as well re-use it). - -.. variable:: CPACK_FREEBSD_PACKAGE_WWW - - The URL of the web site for this package, preferably (when applicable) the - site from which the original source can be obtained and any additional - upstream documentation or information may be found. - - * Mandatory: YES - * Default: - - - :variable:`CMAKE_PROJECT_HOMEPAGE_URL`, or if that is not set, - :variable:`CPACK_DEBIAN_PACKAGE_HOMEPAGE` (this may be set already - for Debian packaging, so we may as well re-use it). - -.. variable:: CPACK_FREEBSD_PACKAGE_LICENSE - - The license, or licenses, which apply to this software package. This must - be one or more license-identifiers that pkg recognizes as acceptable license - identifiers (e.g. "GPLv2"). - - * Mandatory: YES - * Default: - - - :variable:`CPACK_RPM_PACKAGE_LICENSE` - -.. variable:: CPACK_FREEBSD_PACKAGE_LICENSE_LOGIC - - This variable is only of importance if there is more than one license. - The default is "single", which is only applicable to a single license. - Other acceptable values are determined by pkg -- those are "dual" or "multi" -- - meaning choice (OR) or simultaneous (AND) application of the licenses. - - * Mandatory: NO - * Default: single - -.. variable:: CPACK_FREEBSD_PACKAGE_MAINTAINER - - The FreeBSD maintainer (e.g. kde@freebsd.org) of this package. - - * Mandatory: YES - * Default: none - -.. variable:: CPACK_FREEBSD_PACKAGE_ORIGIN - - The origin (ports label) of this package; for packages built by CPack - outside of the ports system this is of less importance. The default - puts the package somewhere under misc/, as a stopgap. - - * Mandatory: YES - * Default: misc/ - -.. variable:: CPACK_FREEBSD_PACKAGE_CATEGORIES - - The ports categories where this package lives (if it were to be built - from ports). If none is set a single category is determined based on - the package origin. - - * Mandatory: YES - * Default: derived from ORIGIN - -.. variable:: CPACK_FREEBSD_PACKAGE_DEPS - - A list of package origins that should be added as package dependencies. - These are in the form /, e.g. x11/libkonq. - No version information needs to be provided (this is not included - in the manifest). - - * Mandatory: NO - * Default: empty -#]=======================================================================] - - - -if(CMAKE_BINARY_DIR) - message(FATAL_ERROR "CPackFreeBSD.cmake may only be used by CPack internally.") -endif() - -if(NOT UNIX) - message(FATAL_ERROR "CPackFreeBSD.cmake may only be used under UNIX.") -endif() - - -### -# -# These bits are copied from the Debian packaging file; slightly modified. -# They are used for filling in FreeBSD-packaging variables that can take -# on values from elsewhere -- e.g. the package description may as well be -# copied from Debian. -# -function(_cpack_freebsd_fallback_var OUTPUT_VAR_NAME) - set(FALLBACK_VAR_NAMES ${ARGN}) - - set(VALUE "${${OUTPUT_VAR_NAME}}") - if(VALUE) - return() - endif() - - foreach(variable_name IN LISTS FALLBACK_VAR_NAMES) - if(${variable_name}) - set(${OUTPUT_VAR_NAME} "${${variable_name}}" PARENT_SCOPE) - set(VALUE "${${variable_name}}") - break() - endif() - endforeach() - if(NOT VALUE) - message(WARNING "Variable ${OUTPUT_VAR_NAME} could not be given a fallback value from any variable ${FALLBACK_VAR_NAMES}.") - endif() -endfunction() - -function(check_required_var VAR_NAME) - if(NOT ${VAR_NAME}) - message(FATAL_ERROR "Variable ${VAR_NAME} is not set.") - endif() -endfunction() - -set(_cpack_freebsd_fallback_origin "misc/bogus") - -_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_NAME" - "CPACK_PACKAGE_NAME" - "CMAKE_PROJECT_NAME" - ) - -set(_cpack_freebsd_fallback_www "http://example.com/?pkg=${CPACK_FREEBSD_PACKAGE_NAME}") - -_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_COMMENT" - "CPACK_PACKAGE_DESCRIPTION_SUMMARY" - ) - -# TODO: maybe read the PACKAGE_DESCRIPTION file for the longer -# FreeBSD pkg-descr? -_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_DESCRIPTION" - "CPACK_DEBIAN_PACKAGE_DESCRIPTION" - "CPACK_PACKAGE_DESCRIPTION_SUMMARY" - "PACKAGE_DESCRIPTION" - ) - -# There's really only one homepage for a project, so -# re-use the Debian setting if it's there. -_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_WWW" - "CMAKE_PROJECT_HOMEPAGE_URL" - "CPACK_DEBIAN_PACKAGE_HOMEPAGE" - "_cpack_freebsd_fallback_www" - ) - -_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_VERSION" - "CMAKE_PROJECT_VERSION" - "${CMAKE_PROJECT_NAME}_VERSION" - "PROJECT_VERSION" - "CPACK_PACKAGE_VERSION" - "CPACK_PACKAGE_VERSION" - ) - -_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_MAINTAINER" - "CPACK_PACKAGE_CONTACT" - ) - -_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_LICENSE" - "CPACK_RPM_PACKAGE_LICENSE" - ) - -_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_ORIGIN" - "_cpack_freebsd_fallback_origin" - ) - -if(NOT CPACK_FREEBSD_PACKAGE_CATEGORIES) - string(REGEX REPLACE "/.*" "" CPACK_FREEBSD_PACKAGE_CATEGORIES ${CPACK_FREEBSD_PACKAGE_ORIGIN}) -endif() - -check_required_var("CPACK_FREEBSD_PACKAGE_NAME") -check_required_var("CPACK_FREEBSD_PACKAGE_ORIGIN") -check_required_var("CPACK_FREEBSD_PACKAGE_VERSION") -check_required_var("CPACK_FREEBSD_PACKAGE_MAINTAINER") -check_required_var("CPACK_FREEBSD_PACKAGE_COMMENT") -check_required_var("CPACK_FREEBSD_PACKAGE_DESCRIPTION") -check_required_var("CPACK_FREEBSD_PACKAGE_WWW") -check_required_var("CPACK_FREEBSD_PACKAGE_LICENSE") diff --git a/Modules/CPackIFW.cmake b/Modules/CPackIFW.cmake index 5a14f3f..141e842 100644 --- a/Modules/CPackIFW.cmake +++ b/Modules/CPackIFW.cmake @@ -319,6 +319,14 @@ The module defines the following commands: #]=======================================================================] +# TODO: +# All of the internal implementation CMake modules for other CPack generators +# have been moved into the Internal/CPack directory. This one has not, because +# it contains user-facing macros which would be lost if it were moved. At some +# point, this module should be split into user-facing macros (which would live +# in this module) and internal implementation details (which would live in +# Internal/CPack/CPackIFW.cmake). + #============================================================================= # Search Qt Installer Framework tools #============================================================================= diff --git a/Modules/CPackNSIS.cmake b/Modules/CPackNSIS.cmake deleted file mode 100644 index 5bc4395..0000000 --- a/Modules/CPackNSIS.cmake +++ /dev/null @@ -1,138 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# CPackNSIS -# --------- -# -# CPack NSIS generator specific options -# -# Variables specific to CPack NSIS generator -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# The following variables are specific to the graphical installers built -# on Windows using the Nullsoft Installation System. -# -# .. variable:: CPACK_NSIS_INSTALL_ROOT -# -# The default installation directory presented to the end user by the NSIS -# installer is under this root dir. The full directory presented to the end -# user is: ${CPACK_NSIS_INSTALL_ROOT}/${CPACK_PACKAGE_INSTALL_DIRECTORY} -# -# .. variable:: CPACK_NSIS_MUI_ICON -# -# An icon filename. The name of a ``*.ico`` file used as the main icon for the -# generated install program. -# -# .. variable:: CPACK_NSIS_MUI_UNIICON -# -# An icon filename. The name of a ``*.ico`` file used as the main icon for the -# generated uninstall program. -# -# .. variable:: CPACK_NSIS_INSTALLER_MUI_ICON_CODE -# -# undocumented. -# -# .. variable:: CPACK_NSIS_MUI_WELCOMEFINISHPAGE_BITMAP -# -# The filename of a bitmap to use as the NSIS MUI_WELCOMEFINISHPAGE_BITMAP. -# -# .. variable:: CPACK_NSIS_MUI_UNWELCOMEFINISHPAGE_BITMAP -# -# The filename of a bitmap to use as the NSIS MUI_UNWELCOMEFINISHPAGE_BITMAP. -# -# .. variable:: CPACK_NSIS_EXTRA_PREINSTALL_COMMANDS -# -# Extra NSIS commands that will be added to the beginning of the install -# Section, before your install tree is available on the target system. -# -# .. variable:: CPACK_NSIS_EXTRA_INSTALL_COMMANDS -# -# Extra NSIS commands that will be added to the end of the install Section, -# after your install tree is available on the target system. -# -# .. variable:: CPACK_NSIS_EXTRA_UNINSTALL_COMMANDS -# -# Extra NSIS commands that will be added to the uninstall Section, before -# your install tree is removed from the target system. -# -# .. variable:: CPACK_NSIS_COMPRESSOR -# -# The arguments that will be passed to the NSIS SetCompressor command. -# -# .. variable:: CPACK_NSIS_ENABLE_UNINSTALL_BEFORE_INSTALL -# -# Ask about uninstalling previous versions first. If this is set to "ON", -# then an installer will look for previous installed versions and if one is -# found, ask the user whether to uninstall it before proceeding with the -# install. -# -# .. variable:: CPACK_NSIS_MODIFY_PATH -# -# Modify PATH toggle. If this is set to "ON", then an extra page will appear -# in the installer that will allow the user to choose whether the program -# directory should be added to the system PATH variable. -# -# .. variable:: CPACK_NSIS_DISPLAY_NAME -# -# The display name string that appears in the Windows Add/Remove Program -# control panel -# -# .. variable:: CPACK_NSIS_PACKAGE_NAME -# -# The title displayed at the top of the installer. -# -# .. variable:: CPACK_NSIS_INSTALLED_ICON_NAME -# -# A path to the executable that contains the installer icon. -# -# .. variable:: CPACK_NSIS_HELP_LINK -# -# URL to a web site providing assistance in installing your application. -# -# .. variable:: CPACK_NSIS_URL_INFO_ABOUT -# -# URL to a web site providing more information about your application. -# -# .. variable:: CPACK_NSIS_CONTACT -# -# Contact information for questions and comments about the installation -# process. -# -# .. variable:: CPACK_NSIS__INSTALL_DIRECTORY -# -# Custom install directory for the specified component instead -# of $INSTDIR. -# -# .. variable:: CPACK_NSIS_CREATE_ICONS_EXTRA -# -# Additional NSIS commands for creating start menu shortcuts. -# -# .. variable:: CPACK_NSIS_DELETE_ICONS_EXTRA -# -# Additional NSIS commands to uninstall start menu shortcuts. -# -# .. variable:: CPACK_NSIS_EXECUTABLES_DIRECTORY -# -# Creating NSIS start menu links assumes that they are in 'bin' unless this -# variable is set. For example, you would set this to 'exec' if your -# executables are in an exec directory. -# -# .. variable:: CPACK_NSIS_MUI_FINISHPAGE_RUN -# -# Specify an executable to add an option to run on the finish page of the -# NSIS installer. -# -# .. variable:: CPACK_NSIS_MENU_LINKS -# -# Specify links in [application] menu. This should contain a list of pair -# "link" "link name". The link may be a URL or a path relative to -# installation prefix. Like:: -# -# set(CPACK_NSIS_MENU_LINKS -# "doc/cmake-@CMake_VERSION_MAJOR@.@CMake_VERSION_MINOR@/cmake.html" -# "CMake Help" "https://cmake.org" "CMake Web Site") -# - -#FIXME we should put NSIS specific code here -#FIXME but I'm not doing it because I'm not able to test it... diff --git a/Modules/CPackNuGet.cmake b/Modules/CPackNuGet.cmake deleted file mode 100644 index 05403bc..0000000 --- a/Modules/CPackNuGet.cmake +++ /dev/null @@ -1,556 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#[=======================================================================[.rst: -CPackNuGet ----------- - -When build a NuGet package there is no direct way to control an output -filename due a lack of the corresponding CLI option of NuGet, so there -is no ``CPACK_NUGET_PACKAGE_FILENAME`` variable. To form the output filename -NuGet uses the package name and the version according to its built-in rules. - -Also, be aware that including a top level directory -(``CPACK_INCLUDE_TOPLEVEL_DIRECTORY``) is ignored by this generator. - - -Variables specific to CPack NuGet generator -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -CPackNuGet may be used to create NuGet packages using :module:`CPack`. -CPackNuGet is a :module:`CPack` generator thus it uses the ``CPACK_XXX`` -variables used by :module:`CPack`. - -CPackNuGet has specific features which are controlled by the specifics -:code:`CPACK_NUGET_XXX` variables. In the "one per group" mode -(see :variable:`CPACK_COMPONENTS_GROUPING`), ```` placeholder -in the variables below would contain a group name (uppercased and turned into -a "C" identifier). - -List of CPackNuGet specific variables: - -.. variable:: CPACK_NUGET_COMPONENT_INSTALL - - Enable component packaging for CPackNuGet - - * Mandatory : NO - * Default : OFF - -.. variable:: CPACK_NUGET_PACKAGE_NAME - CPACK_NUGET__PACKAGE_NAME - - The NUGET package name. - - * Mandatory : YES - * Default : :variable:`CPACK_PACKAGE_NAME` - -.. variable:: CPACK_NUGET_PACKAGE_VERSION - CPACK_NUGET__PACKAGE_VERSION - - The NuGet package version. - - * Mandatory : YES - * Default : :variable:`CPACK_PACKAGE_VERSION` - -.. variable:: CPACK_NUGET_PACKAGE_DESCRIPTION - CPACK_NUGET__PACKAGE_DESCRIPTION - - A long description of the package for UI display. - - * Mandatory : YES - * Default : - - :variable:`CPACK_COMPONENT__DESCRIPTION`, - - ``CPACK_COMPONENT_GROUP__DESCRIPTION``, - - :variable:`CPACK_PACKAGE_DESCRIPTION` - -.. variable:: CPACK_NUGET_PACKAGE_AUTHORS - CPACK_NUGET__PACKAGE_AUTHORS - - A comma-separated list of packages authors, matching the profile names - on nuget.org_. These are displayed in the NuGet Gallery on - nuget.org_ and are used to cross-reference packages by the same - authors. - - * Mandatory : YES - * Default : :variable:`CPACK_PACKAGE_VENDOR` - -.. variable:: CPACK_NUGET_PACKAGE_TITLE - CPACK_NUGET__PACKAGE_TITLE - - A human-friendly title of the package, typically used in UI displays - as on nuget.org_ and the Package Manager in Visual Studio. If not - specified, the package ID is used. - - * Mandatory : NO - * Default : - - :variable:`CPACK_COMPONENT__DISPLAY_NAME`, - - ``CPACK_COMPONENT_GROUP__DISPLAY_NAME`` - -.. variable:: CPACK_NUGET_PACKAGE_OWNERS - CPACK_NUGET__PACKAGE_OWNERS - - A comma-separated list of the package creators using profile names - on nuget.org_. This is often the same list as in authors, - and is ignored when uploading the package to nuget.org_. - - * Mandatory : NO - * Default : - - -.. variable:: CPACK_NUGET_PACKAGE_HOMEPAGE_URL - CPACK_NUGET__PACKAGE_HOMEPAGE_URL - - A URL for the package's home page, often shown in UI displays as well - as nuget.org_. - - * Mandatory : NO - * Default : :variable:`CPACK_PACKAGE_HOMEPAGE_URL` - -.. variable:: CPACK_NUGET_PACKAGE_LICENSEURL - CPACK_NUGET__PACKAGE_LICENSEURL - - A URL for the package's license, often shown in UI displays as well - as nuget.org_. - - * Mandatory : NO - * Default : - - -.. variable:: CPACK_NUGET_PACKAGE_ICONURL - CPACK_NUGET__PACKAGE_ICONURL - - A URL for a 64x64 image with transparency background to use as the - icon for the package in UI display. - - * Mandatory : NO - * Default : - - -.. variable:: CPACK_NUGET_PACKAGE_DESCRIPTION_SUMMARY - CPACK_NUGET__PACKAGE_DESCRIPTION_SUMMARY - - A short description of the package for UI display. If omitted, a - truncated version of description is used. - - * Mandatory : NO - * Default : :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY` - -.. variable:: CPACK_NUGET_PACKAGE_RELEASE_NOTES - CPACK_NUGET__PACKAGE_RELEASE_NOTES - - A description of the changes made in this release of the package, - often used in UI like the Updates tab of the Visual Studio Package - Manager in place of the package description. - - * Mandatory : NO - * Default : - - -.. variable:: CPACK_NUGET_PACKAGE_COPYRIGHT - CPACK_NUGET__PACKAGE_COPYRIGHT - - Copyright details for the package. - - * Mandatory : NO - * Default : - - -.. variable:: CPACK_NUGET_PACKAGE_TAGS - CPACK_NUGET__PACKAGE_TAGS - - A space-delimited list of tags and keywords that describe the - package and aid discoverability of packages through search and - filtering. - - * Mandatory : NO - * Default : - - -.. variable:: CPACK_NUGET_PACKAGE_DEPENDENCIES - CPACK_NUGET__PACKAGE_DEPENDENCIES - - A list of package dependencies. - - * Mandatory : NO - * Default : - - -.. variable:: CPACK_NUGET_PACKAGE_DEPENDENCIES__VERSION - CPACK_NUGET__PACKAGE_DEPENDENCIES__VERSION - - A `version specification`_ for the particular dependency, where - ```` is an item of the dependency list (see above) - transformed with ``MAKE_C_IDENTIFIER`` function of :command:`string` - command. - - * Mandatory : NO - * Default : - - -.. variable:: CPACK_NUGET_PACKAGE_DEBUG - - Enable debug messages while executing ``CPackNuGet.cmake``. - - * Mandatory : NO - * Default : OFF - - -.. _nuget.org: http://nuget.org -.. _version specification: https://docs.microsoft.com/en-us/nuget/reference/package-versioning#version-ranges-and-wildcards - -.. NuGet spec docs https://docs.microsoft.com/en-us/nuget/reference/nuspec - -#]=======================================================================] - -# Author: Alex Turbov - -if(CMAKE_BINARY_DIR) - message(FATAL_ERROR "CPackNuGet.cmake may only be used by CPack internally.") -endif() - -function(_cpack_nuget_debug) - if(CPACK_NUGET_PACKAGE_DEBUG) - message("CPackNuGet:Debug: " ${ARGN}) - endif() -endfunction() - -function(_cpack_nuget_debug_var NAME) - if(CPACK_NUGET_PACKAGE_DEBUG) - message("CPackNuGet:Debug: ${NAME}=`${${NAME}}`") - endif() -endfunction() - -function(_cpack_nuget_variable_fallback OUTPUT_VAR_NAME NUGET_VAR_NAME) - if(ARGN) - list(JOIN ARGN "`, `" _va_args) - set(_va_args ", ARGN: `${_va_args}`") - endif() - _cpack_nuget_debug( - "_cpack_nuget_variable_fallback: " - "OUTPUT_VAR_NAME=`${OUTPUT_VAR_NAME}`, " - "NUGET_VAR_NAME=`${NUGET_VAR_NAME}`" - "${_va_args}" - ) - - set(_options USE_CDATA) - set(_one_value_args LIST_GLUE) - set(_multi_value_args FALLBACK_VARS) - cmake_parse_arguments(PARSE_ARGV 0 _args "${_options}" "${_one_value_args}" "${_multi_value_args}") - - if(CPACK_NUGET_PACKAGE_COMPONENT) - string( - TOUPPER "${CPACK_NUGET_PACKAGE_COMPONENT}" - CPACK_NUGET_PACKAGE_COMPONENT_UPPER - ) - endif() - - if(CPACK_NUGET_PACKAGE_COMPONENT - AND CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT}_PACKAGE_${NUGET_VAR_NAME} - ) - set( - _result - "${CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT}_PACKAGE_${NUGET_VAR_NAME}}" - ) - _cpack_nuget_debug( - " CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT}_PACKAGE_${NUGET_VAR_NAME}: " - "OUTPUT_VAR_NAME->${OUTPUT_VAR_NAME}=`${_result}`" - ) - - elseif(CPACK_NUGET_PACKAGE_COMPONENT_UPPER - AND CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_PACKAGE_${NUGET_VAR_NAME} - ) - set( - _result - "${CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_PACKAGE_${NUGET_VAR_NAME}}" - ) - _cpack_nuget_debug( - " CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_PACKAGE_${NUGET_VAR_NAME}: " - "OUTPUT_VAR_NAME->${OUTPUT_VAR_NAME}=`${_result}`" - ) - - elseif(CPACK_NUGET_PACKAGE_${NUGET_VAR_NAME}) - set(_result "${CPACK_NUGET_PACKAGE_${NUGET_VAR_NAME}}") - _cpack_nuget_debug( - " CPACK_NUGET_PACKAGE_${NUGET_VAR_NAME}: " - "OUTPUT_VAR_NAME->${OUTPUT_VAR_NAME}=`${_result}`" - ) - - else() - foreach(_var IN LISTS _args_FALLBACK_VARS) - _cpack_nuget_debug(" Fallback: ${_var} ...") - if(${_var}) - _cpack_nuget_debug(" ${_var}=`${${_var}}`") - set(_result "${${_var}}") - _cpack_nuget_debug( - " ${_var}: OUTPUT_VAR_NAME->${OUTPUT_VAR_NAME}=`${_result}`" - ) - break() - endif() - endforeach() - endif() - - if(_result) - if(_args_USE_CDATA) - set(_value_before "") - endif() - - list(LENGTH _result _result_len) - if(_result_len GREATER 1 AND _args_LIST_GLUE) - list(JOIN _result "${_args_LIST_GLUE}" _result) - endif() - - set(${OUTPUT_VAR_NAME} "${_value_before}${_result}${_value_after}" PARENT_SCOPE) - endif() - -endfunction() - -function(_cpack_nuget_variable_fallback_and_wrap_into_element ELEMENT NUGET_VAR_NAME) - set(_options) - set(_one_value_args) - set(_multi_value_args FALLBACK_VARS) - cmake_parse_arguments(PARSE_ARGV 0 _args "${_options}" "${_one_value_args}" "${_multi_value_args}") - - _cpack_nuget_variable_fallback(_value ${NUGET_VAR_NAME} ${ARGN} USE_CDATA) - - if(_value) - string(TOUPPER "${ELEMENT}" _ELEMENT_UP) - set( - _CPACK_NUGET_${_ELEMENT_UP}_TAG - "<${ELEMENT}>${_value}" - PARENT_SCOPE - ) - endif() -endfunction() - -# Print some debug info -_cpack_nuget_debug("---[CPack NuGet Input Variables]---") -_cpack_nuget_debug_var(CPACK_PACKAGE_NAME) -_cpack_nuget_debug_var(CPACK_PACKAGE_VERSION) -_cpack_nuget_debug_var(CPACK_TOPLEVEL_TAG) -_cpack_nuget_debug_var(CPACK_TOPLEVEL_DIRECTORY) -_cpack_nuget_debug_var(CPACK_TEMPORARY_DIRECTORY) -_cpack_nuget_debug_var(CPACK_NUGET_GROUPS) -if(CPACK_NUGET_GROUPS) - foreach(_group IN LISTS CPACK_NUGET_GROUPS) - string(MAKE_C_IDENTIFIER "${_group}" _group_up) - string(TOUPPER "${_group_up}" _group_up) - _cpack_nuget_debug_var(CPACK_NUGET_${_group_up}_GROUP_COMPONENTS) - endforeach() -endif() -_cpack_nuget_debug_var(CPACK_NUGET_COMPONENTS) -_cpack_nuget_debug_var(CPACK_NUGET_ALL_IN_ONE) -_cpack_nuget_debug_var(CPACK_NUGET_ORDINAL_MONOLITIC) -_cpack_nuget_debug("-----------------------------------") - -function(_cpack_nuget_render_spec) - # Make a variable w/ upper-cased component name - if(CPACK_NUGET_PACKAGE_COMPONENT) - string(TOUPPER "${CPACK_NUGET_PACKAGE_COMPONENT}" CPACK_NUGET_PACKAGE_COMPONENT_UPPER) - endif() - - # Set mandatory variables (not wrapped into XML elements) - # https://docs.microsoft.com/en-us/nuget/reference/nuspec#required-metadata-elements - if(CPACK_NUGET_PACKAGE_COMPONENT) - if(CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_PACKAGE_NAME) - set( - CPACK_NUGET_PACKAGE_NAME - "${CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_PACKAGE_NAME}" - ) - elseif(NOT CPACK_NUGET_PACKAGE_COMPONENT STREQUAL "Unspecified") - set( - CPACK_NUGET_PACKAGE_NAME - "${CPACK_PACKAGE_NAME}.${CPACK_NUGET_PACKAGE_COMPONENT}" - ) - else() - set(CPACK_NUGET_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") - endif() - elseif(NOT CPACK_NUGET_PACKAGE_NAME) - set(CPACK_NUGET_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") - endif() - - _cpack_nuget_variable_fallback( - CPACK_NUGET_PACKAGE_VERSION VERSION - FALLBACK_VARS - CPACK_PACKAGE_VERSION - ) - _cpack_nuget_variable_fallback( - CPACK_NUGET_PACKAGE_DESCRIPTION DESCRIPTION - FALLBACK_VARS - CPACK_COMPONENT_${CPACK_NUGET_PACKAGE_COMPONENT}_DESCRIPTION - CPACK_COMPONENT_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_DESCRIPTION - CPACK_COMPONENT_GROUP_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_DESCRIPTION - CPACK_PACKAGE_DESCRIPTION - USE_CDATA - ) - _cpack_nuget_variable_fallback( - CPACK_NUGET_PACKAGE_AUTHORS AUTHORS - FALLBACK_VARS - CPACK_PACKAGE_VENDOR - USE_CDATA - LIST_GLUE "," - ) - - # Set optional variables (wrapped into XML elements) - # https://docs.microsoft.com/en-us/nuget/reference/nuspec#optional-metadata-elements - _cpack_nuget_variable_fallback_and_wrap_into_element( - title - TITLE - FALLBACK_VARS - CPACK_COMPONENT_${CPACK_NUGET_PACKAGE_COMPONENT}_DISPLAY_NAME - CPACK_COMPONENT_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_DISPLAY_NAME - CPACK_COMPONENT_GROUP_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_DISPLAY_NAME - ) - _cpack_nuget_variable_fallback_and_wrap_into_element(owners OWNERS LIST_GLUE ",") - _cpack_nuget_variable_fallback_and_wrap_into_element( - projectUrl - HOMEPAGE_URL - FALLBACK_VARS - CPACK_PACKAGE_HOMEPAGE_URL - ) - _cpack_nuget_variable_fallback_and_wrap_into_element(licenseUrl LICENSEURL) - _cpack_nuget_variable_fallback_and_wrap_into_element(iconUrl ICONURL) - _cpack_nuget_variable_fallback_and_wrap_into_element( - summary DESCRIPTION_SUMMARY - FALLBACK_VARS - CPACK_PACKAGE_DESCRIPTION_SUMMARY - ) - if(CPACK_NUGET_PACKAGE_REQUIRE_LICENSE_ACCEPTANCE) - set( - _CPACK_NUGET_REQUIRELICENSEACCEPTANCE_TAG - "true" - ) - endif() - _cpack_nuget_variable_fallback_and_wrap_into_element(releaseNotes RELEASE_NOTES) - _cpack_nuget_variable_fallback_and_wrap_into_element(copyright COPYRIGHT) - _cpack_nuget_variable_fallback_and_wrap_into_element(tags TAGS LIST_GLUE " ") - - # Handle dependencies - _cpack_nuget_variable_fallback(_deps DEPENDENCIES) - set(_collected_deps) - foreach(_dep IN LISTS _deps) - _cpack_nuget_debug(" checking dependency `${_dep}`") - - string(MAKE_C_IDENTIFIER "${_dep}" _dep_id) - - _cpack_nuget_variable_fallback(_ver DEPENDENCIES_${_dep_id}_VERSION) - - if(NOT _ver) - string(TOUPPER "${_dep_id}" _dep_id) - _cpack_nuget_variable_fallback(_ver DEPENDENCIES_${_dep_id}_VERSION) - endif() - - if(_ver) - _cpack_nuget_debug(" got `${_dep}` dependency version ${_ver}") - list(APPEND _collected_deps "") - endif() - endforeach() - - # Render deps into the variable - if(_collected_deps) - set(_CPACK_NUGET_DEPENDENCIES_TAG "\n") - foreach(_line IN LISTS _collected_deps) - string( - APPEND _CPACK_NUGET_DEPENDENCIES_TAG - " ${_line}\n" - ) - endforeach() - string(APPEND _CPACK_NUGET_DEPENDENCIES_TAG " ") - endif() - - # Render the spec file - # NOTE The spec filename doesn't matter. Being included into a package, - # NuGet will name it properly. - _cpack_nuget_debug("Rendering `${CPACK_TEMPORARY_DIRECTORY}/CPack.NuGet.nuspec` file...") - configure_file( - "${CMAKE_CURRENT_LIST_DIR}/CPack.NuGet.nuspec.in" - "${CPACK_TEMPORARY_DIRECTORY}/CPack.NuGet.nuspec" - @ONLY - ) -endfunction() - -function(_cpack_nuget_make_files_tag) - set(_files) - foreach(_comp IN LISTS ARGN) - string(APPEND _files " \n") - endforeach() - set(_CPACK_NUGET_FILES_TAG "\n${_files} " PARENT_SCOPE) -endfunction() - -find_program(NUGET_EXECUTABLE NuGet) -_cpack_nuget_debug_var(NUGET_EXECUTABLE) -if(NOT NUGET_EXECUTABLE) - message(FATAL_ERROR "NuGet executable not found") -endif() - -# Add details for debug run -if(CPACK_NUGET_PACKAGE_DEBUG) - list(APPEND CPACK_NUGET_PACK_ADDITIONAL_OPTIONS "-Verbosity" "detailed") -endif() - -# Case one: ordinal all-in-one package -if(CPACK_NUGET_ORDINAL_MONOLITIC) - # This variable `CPACK_NUGET_ALL_IN_ONE` set by C++ code: - # Meaning to pack all installed files into a single package - _cpack_nuget_debug("---[Making an ordinal monolitic package]---") - _cpack_nuget_render_spec() - execute_process( - COMMAND "${NUGET_EXECUTABLE}" pack ${CPACK_NUGET_PACK_ADDITIONAL_OPTIONS} - WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" - ) - -elseif(CPACK_NUGET_ALL_IN_ONE) - # This variable `CPACK_NUGET_ALL_IN_ONE` set by C++ code: - # Meaning to pack all installed components into a single package - _cpack_nuget_debug("---[Making a monolitic package from installed components]---") - - # Prepare the `files` element which include files from several components - _cpack_nuget_make_files_tag(${CPACK_NUGET_COMPONENTS}) - _cpack_nuget_render_spec() - execute_process( - COMMAND "${NUGET_EXECUTABLE}" pack ${CPACK_NUGET_PACK_ADDITIONAL_OPTIONS} - WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" - ) - -else() - # Is there any grouped component? - if(CPACK_NUGET_GROUPS) - _cpack_nuget_debug("---[Making grouped component(s) package(s)]---") - foreach(_group IN LISTS CPACK_NUGET_GROUPS) - _cpack_nuget_debug("Starting to make the package for group `${_group}`") - string(MAKE_C_IDENTIFIER "${_group}" _group_up) - string(TOUPPER "${_group_up}" _group_up) - - # Render a spec file which includes all components in the current group - unset(_CPACK_NUGET_FILES_TAG) - _cpack_nuget_make_files_tag(${CPACK_NUGET_${_group_up}_GROUP_COMPONENTS}) - # Temporary set `CPACK_NUGET_PACKAGE_COMPONENT` to the group name - # to properly collect various per group settings - set(CPACK_NUGET_PACKAGE_COMPONENT ${_group}) - _cpack_nuget_render_spec() - unset(CPACK_NUGET_PACKAGE_COMPONENT) - execute_process( - COMMAND "${NUGET_EXECUTABLE}" pack ${CPACK_NUGET_PACK_ADDITIONAL_OPTIONS} - WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" - ) - endforeach() - endif() - # Is there any single component package needed? - if(CPACK_NUGET_COMPONENTS) - _cpack_nuget_debug("---[Making single-component(s) package(s)]---") - foreach(_comp IN LISTS CPACK_NUGET_COMPONENTS) - _cpack_nuget_debug("Starting to make the package for component `${_comp}`") - # Render a spec file which includes only given component - unset(_CPACK_NUGET_FILES_TAG) - _cpack_nuget_make_files_tag(${_comp}) - # Temporary set `CPACK_NUGET_PACKAGE_COMPONENT` to the current - # component name to properly collect various per group settings - set(CPACK_NUGET_PACKAGE_COMPONENT ${_comp}) - _cpack_nuget_render_spec() - unset(CPACK_NUGET_PACKAGE_COMPONENT) - execute_process( - COMMAND "${NUGET_EXECUTABLE}" pack ${CPACK_NUGET_PACK_ADDITIONAL_OPTIONS} - WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" - ) - endforeach() - endif() -endif() - -file(GLOB_RECURSE GEN_CPACK_OUTPUT_FILES "${CPACK_TEMPORARY_DIRECTORY}/*.nupkg") -if(NOT GEN_CPACK_OUTPUT_FILES) - message(FATAL_ERROR "NuGet package was not generated at `${CPACK_TEMPORARY_DIRECTORY}`!") -endif() - -_cpack_nuget_debug("Generated files: ${GEN_CPACK_OUTPUT_FILES}") diff --git a/Modules/CPackPackageMaker.cmake b/Modules/CPackPackageMaker.cmake deleted file mode 100644 index c2ca4c6..0000000 --- a/Modules/CPackPackageMaker.cmake +++ /dev/null @@ -1,27 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# CPackPackageMaker -# ----------------- -# -# PackageMaker CPack generator (Mac OS X). -# -# Variables specific to CPack PackageMaker generator -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# The following variable is specific to installers built on Mac -# OS X using PackageMaker: -# -# .. variable:: CPACK_OSX_PACKAGE_VERSION -# -# The version of Mac OS X that the resulting PackageMaker archive should be -# compatible with. Different versions of Mac OS X support different -# features. For example, CPack can only build component-based installers for -# Mac OS X 10.4 or newer, and can only build installers that download -# component son-the-fly for Mac OS X 10.5 or newer. If left blank, this value -# will be set to the minimum version of Mac OS X that supports the requested -# features. Set this variable to some value (e.g., 10.4) only if you want to -# guarantee that your installer will work on that version of Mac OS X, and -# don't mind missing extra features available in the installer shipping with -# later versions of Mac OS X. diff --git a/Modules/CPackProductBuild.cmake b/Modules/CPackProductBuild.cmake deleted file mode 100644 index ee78d8d..0000000 --- a/Modules/CPackProductBuild.cmake +++ /dev/null @@ -1,72 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# CPackProductBuild -# ----------------- -# -# productbuild CPack generator (Mac OS X). -# -# Variables specific to CPack productbuild generator -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# The following variable is specific to installers built on Mac -# OS X using productbuild: -# -# .. variable:: CPACK_COMMAND_PRODUCTBUILD -# -# Path to the productbuild(1) command used to generate a product archive for -# the OS X Installer or Mac App Store. This variable can be used to override -# the automatically detected command (or specify its location if the -# auto-detection fails to find it.) -# -# .. variable:: CPACK_PRODUCTBUILD_IDENTITY_NAME -# -# Adds a digital signature to the resulting package. -# -# -# .. variable:: CPACK_PRODUCTBUILD_KEYCHAIN_PATH -# -# Specify a specific keychain to search for the signing identity. -# -# -# .. variable:: CPACK_COMMAND_PKGBUILD -# -# Path to the pkgbuild(1) command used to generate an OS X component package -# on OS X. This variable can be used to override the automatically detected -# command (or specify its location if the auto-detection fails to find it.) -# -# -# .. variable:: CPACK_PKGBUILD_IDENTITY_NAME -# -# Adds a digital signature to the resulting package. -# -# -# .. variable:: CPACK_PKGBUILD_KEYCHAIN_PATH -# -# Specify a specific keychain to search for the signing identity. -# -# -# .. variable:: CPACK_PREFLIGHT__SCRIPT -# -# Full path to a file that will be used as the ``preinstall`` script for the -# named ```` component's package, where ```` is the uppercased -# component name. No ``preinstall`` script is added if this variable is not -# defined for a given component. -# -# -# .. variable:: CPACK_POSTFLIGHT__SCRIPT -# -# Full path to a file that will be used as the ``postinstall`` script for the -# named ```` component's package, where ```` is the uppercased -# component name. No ``postinstall`` script is added if this variable is not -# defined for a given component. -# -# -# .. variable:: CPACK_PRODUCTBUILD_RESOURCES_DIR -# -# If specified the productbuild generator copies files from this directory -# (including subdirectories) to the ``Resources`` directory. This is done -# before the :variable:`CPACK_RESOURCE_FILE_WELCOME`, -# :variable:`CPACK_RESOURCE_FILE_README`, and -# :variable:`CPACK_RESOURCE_FILE_LICENSE` files are copied. diff --git a/Modules/CPackRPM.cmake b/Modules/CPackRPM.cmake deleted file mode 100644 index 60b3abe..0000000 --- a/Modules/CPackRPM.cmake +++ /dev/null @@ -1,2824 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# CPackRPM -# -------- -# -# The built in (binary) CPack RPM generator (Unix only) -# -# Variables specific to CPack RPM generator -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# CPackRPM may be used to create RPM packages using :module:`CPack`. -# CPackRPM is a :module:`CPack` generator thus it uses the ``CPACK_XXX`` -# variables used by :module:`CPack`. -# -# CPackRPM has specific features which are controlled by the specifics -# :code:`CPACK_RPM_XXX` variables. -# -# :code:`CPACK_RPM__XXXX` variables may be used in order to have -# **component** specific values. Note however that ```` refers to the -# **grouping name** written in upper case. It may be either a component name or -# a component GROUP name. Usually those variables correspond to RPM spec file -# entities. One may find information about spec files here -# http://www.rpm.org/wiki/Docs -# -# .. note:: -# -# `` part of variables is preferred to be in upper case (for e.g. if -# component is named `foo` then use `CPACK_RPM_FOO_XXXX` variable name format) -# as is with other `CPACK__XXXX` variables. -# For the purposes of back compatibility (CMake/CPack version 3.5 and lower) -# support for same cased component (e.g. `fOo` would be used as -# `CPACK_RPM_fOo_XXXX`) is still supported for variables defined in older -# versions of CMake/CPack but is not guaranteed for variables that -# will be added in the future. For the sake of back compatibility same cased -# component variables also override upper cased versions where both are -# present. -# -# Here are some CPackRPM wiki resources that are here for historic reasons and -# are no longer maintained but may still prove useful: -# -# - https://gitlab.kitware.com/cmake/community/wikis/doc/cpack/Configuration -# - https://gitlab.kitware.com/cmake/community/wikis/doc/cpack/PackageGenerators#rpm-unix-only -# -# List of CPackRPM specific variables: -# -# .. variable:: CPACK_RPM_COMPONENT_INSTALL -# -# Enable component packaging for CPackRPM -# -# * Mandatory : NO -# * Default : OFF -# -# If enabled (ON) multiple packages are generated. By default a single package -# containing files of all components is generated. -# -# .. variable:: CPACK_RPM_PACKAGE_SUMMARY -# CPACK_RPM__PACKAGE_SUMMARY -# -# The RPM package summary. -# -# * Mandatory : YES -# * Default : :variable:`CPACK_PACKAGE_DESCRIPTION_SUMMARY` -# -# .. variable:: CPACK_RPM_PACKAGE_NAME -# CPACK_RPM__PACKAGE_NAME -# -# The RPM package name. -# -# * Mandatory : YES -# * Default : :variable:`CPACK_PACKAGE_NAME` -# -# .. variable:: CPACK_RPM_FILE_NAME -# CPACK_RPM__FILE_NAME -# -# Package file name. -# -# * Mandatory : YES -# * Default : ``[-].rpm`` with spaces -# replaced by '-' -# -# This may be set to ``RPM-DEFAULT`` to allow rpmbuild tool to generate package -# file name by itself. -# Alternatively provided package file name must end with ``.rpm`` suffix. -# -# .. note:: -# -# By using user provided spec file, rpm macro extensions such as for -# generating debuginfo packages or by simply using multiple components more -# than one rpm file may be generated, either from a single spec file or from -# multiple spec files (each component execution produces it's own spec file). -# In such cases duplicate file names may occur as a result of this variable -# setting or spec file content structure. Duplicate files get overwritten -# and it is up to the packager to set the variables in a manner that will -# prevent such errors. -# -# .. variable:: CPACK_RPM_MAIN_COMPONENT -# -# Main component that is packaged without component suffix. -# -# * Mandatory : NO -# * Default : - -# -# This variable can be set to any component or group name so that component or -# group rpm package is generated without component suffix in filename and -# package name. -# -# .. variable:: CPACK_RPM_PACKAGE_EPOCH -# -# The RPM package epoch -# -# * Mandatory : No -# * Default : - -# -# Optional number that should be incremented when changing versioning schemas -# or fixing mistakes in the version numbers of older packages. -# -# .. variable:: CPACK_RPM_PACKAGE_VERSION -# -# The RPM package version. -# -# * Mandatory : YES -# * Default : :variable:`CPACK_PACKAGE_VERSION` -# -# .. variable:: CPACK_RPM_PACKAGE_ARCHITECTURE -# CPACK_RPM__PACKAGE_ARCHITECTURE -# -# The RPM package architecture. -# -# * Mandatory : YES -# * Default : Native architecture output by ``uname -m`` -# -# This may be set to ``noarch`` if you know you are building a noarch package. -# -# .. variable:: CPACK_RPM_PACKAGE_RELEASE -# -# The RPM package release. -# -# * Mandatory : YES -# * Default : 1 -# -# This is the numbering of the RPM package itself, i.e. the version of the -# packaging and not the version of the content (see -# :variable:`CPACK_RPM_PACKAGE_VERSION`). One may change the default value if -# the previous packaging was buggy and/or you want to put here a fancy Linux -# distro specific numbering. -# -# .. note:: -# -# This is the string that goes into the RPM ``Release:`` field. Some distros -# (e.g. Fedora, CentOS) require ``1%{?dist}`` format and not just a number. -# ``%{?dist}`` part can be added by setting :variable:`CPACK_RPM_PACKAGE_RELEASE_DIST`. -# -# .. variable:: CPACK_RPM_PACKAGE_RELEASE_DIST -# -# The dist tag that is added RPM ``Release:`` field. -# -# * Mandatory : NO -# * Default : OFF -# -# This is the reported ``%{dist}`` tag from the current distribution or empty -# ``%{dist}`` if RPM macro is not set. If this variable is set then RPM -# ``Release:`` field value is set to ``${CPACK_RPM_PACKAGE_RELEASE}%{?dist}``. -# -# .. variable:: CPACK_RPM_PACKAGE_LICENSE -# -# The RPM package license policy. -# -# * Mandatory : YES -# * Default : "unknown" -# -# .. variable:: CPACK_RPM_PACKAGE_GROUP -# CPACK_RPM__PACKAGE_GROUP -# -# The RPM package group. -# -# * Mandatory : YES -# * Default : "unknown" -# -# .. variable:: CPACK_RPM_PACKAGE_VENDOR -# -# The RPM package vendor. -# -# * Mandatory : YES -# * Default : CPACK_PACKAGE_VENDOR if set or "unknown" -# -# .. variable:: CPACK_RPM_PACKAGE_URL -# CPACK_RPM__PACKAGE_URL -# -# The projects URL. -# -# * Mandatory : NO -# * Default : :variable:`CMAKE_PROJECT_HOMEPAGE_URL` -# -# .. variable:: CPACK_RPM_PACKAGE_DESCRIPTION -# CPACK_RPM__PACKAGE_DESCRIPTION -# -# RPM package description. -# -# * Mandatory : YES -# * Default : :variable:`CPACK_COMPONENT__DESCRIPTION` (component -# based installers only) if set, :variable:`CPACK_PACKAGE_DESCRIPTION_FILE` -# if set or "no package description available" -# -# .. variable:: CPACK_RPM_COMPRESSION_TYPE -# -# RPM compression type. -# -# * Mandatory : NO -# * Default : - -# -# May be used to override RPM compression type to be used to build the -# RPM. For example some Linux distribution now default to lzma or xz -# compression whereas older cannot use such RPM. Using this one can enforce -# compression type to be used. -# -# Possible values are: -# -# - lzma -# - xz -# - bzip2 -# - gzip -# -# .. variable:: CPACK_RPM_PACKAGE_AUTOREQ -# CPACK_RPM__PACKAGE_AUTOREQ -# -# RPM spec autoreq field. -# -# * Mandatory : NO -# * Default : - -# -# May be used to enable (1, yes) or disable (0, no) automatic shared libraries -# dependency detection. Dependencies are added to requires list. -# -# .. note:: -# -# By default automatic dependency detection is enabled by rpm generator. -# -# .. variable:: CPACK_RPM_PACKAGE_AUTOPROV -# CPACK_RPM__PACKAGE_AUTOPROV -# -# RPM spec autoprov field. -# -# * Mandatory : NO -# * Default : - -# -# May be used to enable (1, yes) or disable (0, no) automatic listing of shared -# libraries that are provided by the package. Shared libraries are added to -# provides list. -# -# .. note:: -# -# By default automatic provides detection is enabled by rpm generator. -# -# .. variable:: CPACK_RPM_PACKAGE_AUTOREQPROV -# CPACK_RPM__PACKAGE_AUTOREQPROV -# -# RPM spec autoreqprov field. -# -# * Mandatory : NO -# * Default : - -# -# Variable enables/disables autoreq and autoprov at the same time. -# See :variable:`CPACK_RPM_PACKAGE_AUTOREQ` and :variable:`CPACK_RPM_PACKAGE_AUTOPROV` -# for more details. -# -# .. note:: -# -# By default automatic detection feature is enabled by rpm. -# -# .. variable:: CPACK_RPM_PACKAGE_REQUIRES -# CPACK_RPM__PACKAGE_REQUIRES -# -# RPM spec requires field. -# -# * Mandatory : NO -# * Default : - -# -# May be used to set RPM dependencies (requires). Note that you must enclose -# the complete requires string between quotes, for example:: -# -# set(CPACK_RPM_PACKAGE_REQUIRES "python >= 2.5.0, cmake >= 2.8") -# -# The required package list of an RPM file could be printed with:: -# -# rpm -qp --requires file.rpm -# -# .. variable:: CPACK_RPM_PACKAGE_CONFLICTS -# CPACK_RPM__PACKAGE_CONFLICTS -# -# RPM spec conflicts field. -# -# * Mandatory : NO -# * Default : - -# -# May be used to set negative RPM dependencies (conflicts). Note that you must -# enclose the complete requires string between quotes, for example:: -# -# set(CPACK_RPM_PACKAGE_CONFLICTS "libxml2") -# -# The conflicting package list of an RPM file could be printed with:: -# -# rpm -qp --conflicts file.rpm -# -# .. variable:: CPACK_RPM_PACKAGE_REQUIRES_PRE -# CPACK_RPM__PACKAGE_REQUIRES_PRE -# -# RPM spec requires(pre) field. -# -# * Mandatory : NO -# * Default : - -# -# May be used to set RPM preinstall dependencies (requires(pre)). Note that -# you must enclose the complete requires string between quotes, for example:: -# -# set(CPACK_RPM_PACKAGE_REQUIRES_PRE "shadow-utils, initscripts") -# -# .. variable:: CPACK_RPM_PACKAGE_REQUIRES_POST -# CPACK_RPM__PACKAGE_REQUIRES_POST -# -# RPM spec requires(post) field. -# -# * Mandatory : NO -# * Default : - -# -# May be used to set RPM postinstall dependencies (requires(post)). Note that -# you must enclose the complete requires string between quotes, for example:: -# -# set(CPACK_RPM_PACKAGE_REQUIRES_POST "shadow-utils, initscripts") -# -# .. variable:: CPACK_RPM_PACKAGE_REQUIRES_POSTUN -# CPACK_RPM__PACKAGE_REQUIRES_POSTUN -# -# RPM spec requires(postun) field. -# -# * Mandatory : NO -# * Default : - -# -# May be used to set RPM postuninstall dependencies (requires(postun)). Note -# that you must enclose the complete requires string between quotes, for -# example:: -# -# set(CPACK_RPM_PACKAGE_REQUIRES_POSTUN "shadow-utils, initscripts") -# -# .. variable:: CPACK_RPM_PACKAGE_REQUIRES_PREUN -# CPACK_RPM__PACKAGE_REQUIRES_PREUN -# -# RPM spec requires(preun) field. -# -# * Mandatory : NO -# * Default : - -# -# May be used to set RPM preuninstall dependencies (requires(preun)). Note that -# you must enclose the complete requires string between quotes, for example:: -# -# set(CPACK_RPM_PACKAGE_REQUIRES_PREUN "shadow-utils, initscripts") -# -# .. variable:: CPACK_RPM_PACKAGE_SUGGESTS -# CPACK_RPM__PACKAGE_SUGGESTS -# -# RPM spec suggest field. -# -# * Mandatory : NO -# * Default : - -# -# May be used to set weak RPM dependencies (suggests). Note that you must -# enclose the complete requires string between quotes. -# -# .. variable:: CPACK_RPM_PACKAGE_PROVIDES -# CPACK_RPM__PACKAGE_PROVIDES -# -# RPM spec provides field. -# -# * Mandatory : NO -# * Default : - -# -# May be used to set RPM dependencies (provides). The provided package list -# of an RPM file could be printed with:: -# -# rpm -qp --provides file.rpm -# -# .. variable:: CPACK_RPM_PACKAGE_OBSOLETES -# CPACK_RPM__PACKAGE_OBSOLETES -# -# RPM spec obsoletes field. -# -# * Mandatory : NO -# * Default : - -# -# May be used to set RPM packages that are obsoleted by this one. -# -# .. variable:: CPACK_RPM_PACKAGE_RELOCATABLE -# -# build a relocatable RPM. -# -# * Mandatory : NO -# * Default : CPACK_PACKAGE_RELOCATABLE -# -# If this variable is set to TRUE or ON CPackRPM will try -# to build a relocatable RPM package. A relocatable RPM may -# be installed using:: -# -# rpm --prefix or --relocate -# -# in order to install it at an alternate place see rpm(8). Note that -# currently this may fail if :variable:`CPACK_SET_DESTDIR` is set to ``ON``. If -# :variable:`CPACK_SET_DESTDIR` is set then you will get a warning message but -# if there is file installed with absolute path you'll get unexpected behavior. -# -# .. variable:: CPACK_RPM_SPEC_INSTALL_POST -# -# Deprecated - use :variable:`CPACK_RPM_SPEC_MORE_DEFINE` instead. -# -# * Mandatory : NO -# * Default : - -# * Deprecated: YES -# -# May be used to override the ``__spec_install_post`` section within the -# generated spec file. This affects the install step during package creation, -# not during package installation. For adding operations to be performed -# during package installation, use -# :variable:`CPACK_RPM_POST_INSTALL_SCRIPT_FILE` instead. -# -# .. variable:: CPACK_RPM_SPEC_MORE_DEFINE -# -# RPM extended spec definitions lines. -# -# * Mandatory : NO -# * Default : - -# -# May be used to add any ``%define`` lines to the generated spec file. An -# example of its use is to prevent stripping of executables (but note that -# this may also disable other default post install processing):: -# -# set(CPACK_RPM_SPEC_MORE_DEFINE "%define __spec_install_post /bin/true") -# -# .. variable:: CPACK_RPM_PACKAGE_DEBUG -# -# Toggle CPackRPM debug output. -# -# * Mandatory : NO -# * Default : - -# -# May be set when invoking cpack in order to trace debug information -# during CPack RPM run. For example you may launch CPack like this:: -# -# cpack -D CPACK_RPM_PACKAGE_DEBUG=1 -G RPM -# -# .. variable:: CPACK_RPM_USER_BINARY_SPECFILE -# CPACK_RPM__USER_BINARY_SPECFILE -# -# A user provided spec file. -# -# * Mandatory : NO -# * Default : - -# -# May be set by the user in order to specify a USER binary spec file -# to be used by CPackRPM instead of generating the file. -# The specified file will be processed by configure_file( @ONLY). -# -# .. variable:: CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE -# -# Spec file template. -# -# * Mandatory : NO -# * Default : - -# -# If set CPack will generate a template for USER specified binary -# spec file and stop with an error. For example launch CPack like this:: -# -# cpack -D CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE=1 -G RPM -# -# The user may then use this file in order to hand-craft is own -# binary spec file which may be used with -# :variable:`CPACK_RPM_USER_BINARY_SPECFILE`. -# -# .. variable:: CPACK_RPM_PRE_INSTALL_SCRIPT_FILE -# CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE -# -# Path to file containing pre (un)install script. -# -# * Mandatory : NO -# * Default : - -# -# May be used to embed a pre (un)installation script in the spec file. -# The referred script file (or both) will be read and directly -# put after the ``%pre`` or ``%preun`` section -# If :variable:`CPACK_RPM_COMPONENT_INSTALL` is set to ON the (un)install -# script for each component can be overridden with -# ``CPACK_RPM__PRE_INSTALL_SCRIPT_FILE`` and -# ``CPACK_RPM__PRE_UNINSTALL_SCRIPT_FILE``. -# One may verify which scriptlet has been included with:: -# -# rpm -qp --scripts package.rpm -# -# .. variable:: CPACK_RPM_POST_INSTALL_SCRIPT_FILE -# CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE -# -# Path to file containing post (un)install script. -# -# * Mandatory : NO -# * Default : - -# -# May be used to embed a post (un)installation script in the spec file. -# The referred script file (or both) will be read and directly -# put after the ``%post`` or ``%postun`` section. -# If :variable:`CPACK_RPM_COMPONENT_INSTALL` is set to ON the (un)install -# script for each component can be overridden with -# ``CPACK_RPM__POST_INSTALL_SCRIPT_FILE`` and -# ``CPACK_RPM__POST_UNINSTALL_SCRIPT_FILE``. -# One may verify which scriptlet has been included with:: -# -# rpm -qp --scripts package.rpm -# -# .. variable:: CPACK_RPM_USER_FILELIST -# CPACK_RPM__USER_FILELIST -# -# * Mandatory : NO -# * Default : - -# -# May be used to explicitly specify ``%()`` file line -# in the spec file. Like ``%config(noreplace)`` or any other directive -# that be found in the ``%files`` section. You can have multiple directives -# per line, as in ``%attr(600,root,root) %config(noreplace)``. Since -# CPackRPM is generating the list of files (and directories) the user -# specified files of the ``CPACK_RPM__USER_FILELIST`` list will -# be removed from the generated list. If referring to directories do -# not add a trailing slash. -# -# .. variable:: CPACK_RPM_CHANGELOG_FILE -# -# RPM changelog file. -# -# * Mandatory : NO -# * Default : - -# -# May be used to embed a changelog in the spec file. -# The referred file will be read and directly put after the ``%changelog`` -# section. -# -# .. variable:: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST -# -# list of path to be excluded. -# -# * Mandatory : NO -# * Default : /etc /etc/init.d /usr /usr/bin /usr/include /usr/lib -# /usr/libx32 /usr/lib64 /usr/share /usr/share/aclocal -# /usr/share/doc -# -# May be used to exclude path (directories or files) from the auto-generated -# list of paths discovered by CPack RPM. The default value contains a -# reasonable set of values if the variable is not defined by the user. If the -# variable is defined by the user then CPackRPM will NOT any of the default -# path. If you want to add some path to the default list then you can use -# :variable:`CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION` variable. -# -# .. variable:: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION -# -# additional list of path to be excluded. -# -# * Mandatory : NO -# * Default : - -# -# May be used to add more exclude path (directories or files) from the initial -# default list of excluded paths. See -# :variable:`CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST`. -# -# .. variable:: CPACK_RPM_RELOCATION_PATHS -# -# Packages relocation paths list. -# -# * Mandatory : NO -# * Default : - -# -# May be used to specify more than one relocation path per relocatable RPM. -# Variable contains a list of relocation paths that if relative are prefixed -# by the value of :variable:`CPACK_RPM__PACKAGE_PREFIX` or by the -# value of :variable:`CPACK_PACKAGING_INSTALL_PREFIX` if the component version -# is not provided. -# Variable is not component based as its content can be used to set a different -# path prefix for e.g. binary dir and documentation dir at the same time. -# Only prefixes that are required by a certain component are added to that -# component - component must contain at least one file/directory/symbolic link -# with :variable:`CPACK_RPM_RELOCATION_PATHS` prefix for a certain relocation -# path to be added. Package will not contain any relocation paths if there are -# no files/directories/symbolic links on any of the provided prefix locations. -# Packages that either do not contain any relocation paths or contain -# files/directories/symbolic links that are outside relocation paths print -# out an ``AUTHOR_WARNING`` that RPM will be partially relocatable. -# -# .. variable:: CPACK_RPM__PACKAGE_PREFIX -# -# Per component relocation path install prefix. -# -# * Mandatory : NO -# * Default : CPACK_PACKAGING_INSTALL_PREFIX -# -# May be used to set per component :variable:`CPACK_PACKAGING_INSTALL_PREFIX` -# for relocatable RPM packages. -# -# .. variable:: CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION -# CPACK_RPM_NO__INSTALL_PREFIX_RELOCATION -# -# Removal of default install prefix from relocation paths list. -# -# * Mandatory : NO -# * Default : CPACK_PACKAGING_INSTALL_PREFIX or CPACK_RPM__PACKAGE_PREFIX -# are treated as one of relocation paths -# -# May be used to remove CPACK_PACKAGING_INSTALL_PREFIX and CPACK_RPM__PACKAGE_PREFIX -# from relocatable RPM prefix paths. -# -# .. variable:: CPACK_RPM_ADDITIONAL_MAN_DIRS -# -# * Mandatory : NO -# * Default : - -# -# May be used to set additional man dirs that could potentially be compressed -# by brp-compress RPM macro. Variable content must be a list of regular -# expressions that point to directories containing man files or to man files -# directly. Note that in order to compress man pages a path must also be -# present in brp-compress RPM script and that brp-compress script must be -# added to RPM configuration by the operating system. -# -# Regular expressions that are added by default were taken from brp-compress -# RPM macro: -# -# - /usr/man/man.* -# - /usr/man/.*/man.* -# - /usr/info.* -# - /usr/share/man/man.* -# - /usr/share/man/.*/man.* -# - /usr/share/info.* -# - /usr/kerberos/man.* -# - /usr/X11R6/man/man.* -# - /usr/lib/perl5/man/man.* -# - /usr/share/doc/.*/man/man.* -# - /usr/lib/.*/man/man.* -# -# .. variable:: CPACK_RPM_DEFAULT_USER -# CPACK_RPM__DEFAULT_USER -# -# default user ownership of RPM content -# -# * Mandatory : NO -# * Default : root -# -# Value should be user name and not UID. -# Note that must be in upper-case. -# -# .. variable:: CPACK_RPM_DEFAULT_GROUP -# CPACK_RPM__DEFAULT_GROUP -# -# default group ownership of RPM content -# -# * Mandatory : NO -# * Default : root -# -# Value should be group name and not GID. -# Note that must be in upper-case. -# -# .. variable:: CPACK_RPM_DEFAULT_FILE_PERMISSIONS -# CPACK_RPM__DEFAULT_FILE_PERMISSIONS -# -# default permissions used for packaged files -# -# * Mandatory : NO -# * Default : - (system default) -# -# Accepted values are lists with ``PERMISSIONS``. Valid permissions -# are: -# -# - OWNER_READ -# - OWNER_WRITE -# - OWNER_EXECUTE -# - GROUP_READ -# - GROUP_WRITE -# - GROUP_EXECUTE -# - WORLD_READ -# - WORLD_WRITE -# - WORLD_EXECUTE -# -# Note that must be in upper-case. -# -# .. variable:: CPACK_RPM_DEFAULT_DIR_PERMISSIONS -# CPACK_RPM__DEFAULT_DIR_PERMISSIONS -# -# default permissions used for packaged directories -# -# * Mandatory : NO -# * Default : - (system default) -# -# Accepted values are lists with PERMISSIONS. Valid permissions -# are the same as for :variable:`CPACK_RPM_DEFAULT_FILE_PERMISSIONS`. -# Note that must be in upper-case. -# -# .. variable:: CPACK_RPM_INSTALL_WITH_EXEC -# -# force execute permissions on programs and shared libraries -# -# * Mandatory : NO -# * Default : - (system default) -# -# Force set owner, group and world execute permissions on programs and shared -# libraries. This can be used for creating valid rpm packages on systems such -# as Debian where shared libraries do not have execute permissions set. -# -# .. note:: -# -# Programs and shared libraries without execute permissions are ignored during -# separation of debug symbols from the binary for debuginfo packages. -# -# Packaging of Symbolic Links -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# CPackRPM supports packaging of symbolic links:: -# -# execute_process(COMMAND ${CMAKE_COMMAND} -# -E create_symlink ) -# install(FILES ${CMAKE_CURRENT_BINARY_DIR}/ -# DESTINATION COMPONENT libraries) -# -# Symbolic links will be optimized (paths will be shortened if possible) -# before being added to the package or if multiple relocation paths are -# detected, a post install symlink relocation script will be generated. -# -# Symbolic links may point to locations that are not packaged by the same -# package (either a different component or even not packaged at all) but -# those locations will be treated as if they were a part of the package -# while determining if symlink should be either created or present in a -# post install script - depending on relocation paths. -# -# Symbolic links that point to locations outside packaging path produce a -# warning and are treated as non relocatable permanent symbolic links. -# -# Currently there are a few limitations though: -# -# * For component based packaging component interdependency is not checked -# when processing symbolic links. Symbolic links pointing to content of -# a different component are treated the same way as if pointing to location -# that will not be packaged. -# -# * Symbolic links pointing to a location through one or more intermediate -# symbolic links will not be handled differently - if the intermediate -# symbolic link(s) is also on a relocatable path, relocating it during -# package installation may cause initial symbolic link to point to an -# invalid location. -# -# Packaging of debug information -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# Debuginfo packages contain debug symbols and sources for debugging packaged -# binaries. -# -# Debuginfo RPM packaging has it's own set of variables: -# -# .. variable:: CPACK_RPM_DEBUGINFO_PACKAGE -# CPACK_RPM__DEBUGINFO_PACKAGE -# -# Enable generation of debuginfo RPM package(s). -# -# * Mandatory : NO -# * Default : OFF -# -# .. note:: -# -# Binaries must contain debug symbols before packaging so use either ``Debug`` -# or ``RelWithDebInfo`` for :variable:`CMAKE_BUILD_TYPE` variable value. -# -# .. note:: -# -# Packages generated from packages without binary files, with binary files but -# without execute permissions or without debug symbols will cause packaging -# termination. -# -# .. variable:: CPACK_BUILD_SOURCE_DIRS -# -# Provides locations of root directories of source files from which binaries -# were built. -# -# * Mandatory : YES if :variable:`CPACK_RPM_DEBUGINFO_PACKAGE` is set -# * Default : - -# -# .. note:: -# -# For CMake project :variable:`CPACK_BUILD_SOURCE_DIRS` is set by default to -# point to :variable:`CMAKE_SOURCE_DIR` and :variable:`CMAKE_BINARY_DIR` paths. -# -# .. note:: -# -# Sources with path prefixes that do not fall under any location provided with -# :variable:`CPACK_BUILD_SOURCE_DIRS` will not be present in debuginfo package. -# -# .. variable:: CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX -# CPACK_RPM__BUILD_SOURCE_DIRS_PREFIX -# -# Prefix of location where sources will be placed during package installation. -# -# * Mandatory : YES if :variable:`CPACK_RPM_DEBUGINFO_PACKAGE` is set -# * Default : "/usr/src/debug/" and -# for component packaging "/usr/src/debug/-" -# -# .. note:: -# -# Each source path prefix is additionally suffixed by ``src_`` where -# index is index of the path used from :variable:`CPACK_BUILD_SOURCE_DIRS` -# variable. This produces ``/src_`` -# replacement path. -# Limitation is that replaced path part must be shorter or of equal -# length than the length of its replacement. If that is not the case either -# :variable:`CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX` variable has to be set to -# a shorter path or source directories must be placed on a longer path. -# -# .. variable:: CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS -# -# Directories containing sources that should be excluded from debuginfo packages. -# -# * Mandatory : NO -# * Default : "/usr /usr/src /usr/src/debug" -# -# Listed paths are owned by other RPM packages and should therefore not be -# deleted on debuginfo package uninstallation. -# -# .. variable:: CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION -# -# Paths that should be appended to :variable:`CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS` -# for exclusion. -# -# * Mandatory : NO -# * Default : - -# -# .. variable:: CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE -# -# Create a single debuginfo package even if components packaging is set. -# -# * Mandatory : NO -# * Default : OFF -# -# When this variable is enabled it produces a single debuginfo package even if -# component packaging is enabled. -# -# When using this feature in combination with components packaging and there is -# more than one component this variable requires :variable:`CPACK_RPM_MAIN_COMPONENT` -# to be set. -# -# .. note:: -# -# If none of the :variable:`CPACK_RPM__DEBUGINFO_PACKAGE` variables -# is set then :variable:`CPACK_RPM_DEBUGINFO_PACKAGE` is automatically set to -# ``ON`` when :variable:`CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE` is set. -# -# .. variable:: CPACK_RPM_DEBUGINFO_FILE_NAME -# CPACK_RPM__DEBUGINFO_FILE_NAME -# -# Debuginfo package file name. -# -# * Mandatory : NO -# * Default : rpmbuild tool generated package file name -# -# Alternatively provided debuginfo package file name must end with ``.rpm`` -# suffix and should differ from file names of other generated packages. -# -# Variable may contain ``@cpack_component@`` placeholder which will be -# replaced by component name if component packaging is enabled otherwise it -# deletes the placeholder. -# -# Setting the variable to ``RPM-DEFAULT`` may be used to explicitly set -# filename generation to default. -# -# .. note:: -# -# :variable:`CPACK_RPM_FILE_NAME` also supports rpmbuild tool generated package -# file name - disabled by default but can be enabled by setting the variable to -# ``RPM-DEFAULT``. -# -# Packaging of sources (SRPM) -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# SRPM packaging is enabled by setting :variable:`CPACK_RPM_PACKAGE_SOURCES` -# variable while usually using :variable:`CPACK_INSTALLED_DIRECTORIES` variable -# to provide directory containing CMakeLists.txt and source files. -# -# For CMake projects SRPM package would be produced by executing:: -# -# cpack -G RPM --config ./CPackSourceConfig.cmake -# -# .. note:: -# -# Produced SRPM package is expected to be built with :manual:`cmake(1)` executable -# and packaged with :manual:`cpack(1)` executable so CMakeLists.txt has to be -# located in root source directory and must be able to generate binary rpm -# packages by executing ``cpack -G`` command. The two executables as well as -# rpmbuild must also be present when generating binary rpm packages from the -# produced SRPM package. -# -# Once the SRPM package is generated it can be used to generate binary packages -# by creating a directory structure for rpm generation and executing rpmbuild -# tool:: -# -# mkdir -p build_dir/{BUILD,BUILDROOT,RPMS,SOURCES,SPECS,SRPMS} -# rpmbuild --define "_topdir " --rebuild -# -# Generated packages will be located in build_dir/RPMS directory or its sub -# directories. -# -# .. note:: -# -# SRPM package internally uses CPack/RPM generator to generate binary packages -# so CMakeScripts.txt can decide during the SRPM to binary rpm generation step -# what content the package(s) should have as well as how they should be packaged -# (monolithic or components). CMake can decide this for e.g. by reading environment -# variables set by the package manager before starting the process of generating -# binary rpm packages. This way a single SRPM package can be used to produce -# different binary rpm packages on different platforms depending on the platform's -# packaging rules. -# -# Source RPM packaging has it's own set of variables: -# -# .. variable:: CPACK_RPM_PACKAGE_SOURCES -# -# Should the content be packaged as a source rpm (default is binary rpm). -# -# * Mandatory : NO -# * Default : OFF -# -# .. note:: -# -# For cmake projects :variable:`CPACK_RPM_PACKAGE_SOURCES` variable is set -# to ``OFF`` in CPackConfig.cmake and ``ON`` in CPackSourceConfig.cmake -# generated files. -# -# .. variable:: CPACK_RPM_SOURCE_PKG_BUILD_PARAMS -# -# Additional command-line parameters provided to :manual:`cmake(1)` executable. -# -# * Mandatory : NO -# * Default : - -# -# .. variable:: CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX -# -# Packaging install prefix that would be provided in :variable:`CPACK_PACKAGING_INSTALL_PREFIX` -# variable for producing binary RPM packages. -# -# * Mandatory : YES -# * Default : "/" -# -# .. VARIABLE:: CPACK_RPM_BUILDREQUIRES -# -# List of source rpm build dependencies. -# -# * Mandatory : NO -# * Default : - -# -# May be used to set source RPM build dependencies (BuildRequires). Note that -# you must enclose the complete build requirements string between quotes, for -# example:: -# -# set(CPACK_RPM_BUILDREQUIRES "python >= 2.5.0, cmake >= 2.8") - -# Author: Eric Noulard with the help of Alexander Neundorf. - -function(get_file_permissions FILE RETURN_VAR) - execute_process(COMMAND ls -l ${FILE} - OUTPUT_VARIABLE permissions_ - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - - string(REPLACE " " ";" permissions_ "${permissions_}") - list(GET permissions_ 0 permissions_) - - unset(text_notation_) - set(any_chars_ ".") - foreach(PERMISSION_TYPE "OWNER" "GROUP" "WORLD") - if(permissions_ MATCHES "${any_chars_}r.*") - list(APPEND text_notation_ "${PERMISSION_TYPE}_READ") - endif() - string(APPEND any_chars_ ".") - if(permissions_ MATCHES "${any_chars_}w.*") - list(APPEND text_notation_ "${PERMISSION_TYPE}_WRITE") - endif() - string(APPEND any_chars_ ".") - if(permissions_ MATCHES "${any_chars_}x.*") - list(APPEND text_notation_ "${PERMISSION_TYPE}_EXECUTE") - endif() - endforeach() - - set(${RETURN_VAR} "${text_notation_}" PARENT_SCOPE) -endfunction() - -function(get_unix_permissions_octal_notation PERMISSIONS_VAR RETURN_VAR) - set(PERMISSIONS ${${PERMISSIONS_VAR}}) - list(LENGTH PERMISSIONS PERM_LEN_PRE) - list(REMOVE_DUPLICATES PERMISSIONS) - list(LENGTH PERMISSIONS PERM_LEN_POST) - - if(NOT ${PERM_LEN_PRE} EQUAL ${PERM_LEN_POST}) - message(FATAL_ERROR "${PERMISSIONS_VAR} contains duplicate values.") - endif() - - foreach(PERMISSION_TYPE "OWNER" "GROUP" "WORLD") - set(${PERMISSION_TYPE}_PERMISSIONS 0) - - foreach(PERMISSION ${PERMISSIONS}) - if("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_READ") - math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 4") - elseif("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_WRITE") - math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 2") - elseif("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_EXECUTE") - math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 1") - elseif(PERMISSION MATCHES "${PERMISSION_TYPE}.*") - message(FATAL_ERROR "${PERMISSIONS_VAR} contains invalid values.") - endif() - endforeach() - endforeach() - - set(${RETURN_VAR} "${OWNER_PERMISSIONS}${GROUP_PERMISSIONS}${WORLD_PERMISSIONS}" PARENT_SCOPE) -endfunction() - -function(cpack_rpm_prepare_relocation_paths) - # set appropriate prefix, remove possible trailing slash and convert backslashes to slashes - if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_PREFIX) - file(TO_CMAKE_PATH "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_PREFIX}" PATH_PREFIX) - elseif(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_PREFIX) - file(TO_CMAKE_PATH "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_PREFIX}" PATH_PREFIX) - else() - file(TO_CMAKE_PATH "${CPACK_PACKAGING_INSTALL_PREFIX}" PATH_PREFIX) - endif() - - set(RPM_RELOCATION_PATHS "${CPACK_RPM_RELOCATION_PATHS}") - list(REMOVE_DUPLICATES RPM_RELOCATION_PATHS) - - # set base path prefix - if(EXISTS "${WDIR}/${PATH_PREFIX}") - if(NOT CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION AND - NOT CPACK_RPM_NO_${CPACK_RPM_PACKAGE_COMPONENT}_INSTALL_PREFIX_RELOCATION AND - NOT CPACK_RPM_NO_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_INSTALL_PREFIX_RELOCATION) - string(APPEND TMP_RPM_PREFIXES "Prefix: ${PATH_PREFIX}\n") - list(APPEND RPM_USED_PACKAGE_PREFIXES "${PATH_PREFIX}") - - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: removing '${PATH_PREFIX}' from relocation paths") - endif() - endif() - endif() - - # set other path prefixes - foreach(RELOCATION_PATH ${RPM_RELOCATION_PATHS}) - if(IS_ABSOLUTE "${RELOCATION_PATH}") - set(PREPARED_RELOCATION_PATH "${RELOCATION_PATH}") - elseif(PATH_PREFIX STREQUAL "/") - # don't prefix path with a second slash as "//" is treated as network path - # by get_filename_component() so it remains in path even inside rpm - # package where it may cause problems with relocation - set(PREPARED_RELOCATION_PATH "/${RELOCATION_PATH}") - else() - set(PREPARED_RELOCATION_PATH "${PATH_PREFIX}/${RELOCATION_PATH}") - endif() - - # handle cases where path contains extra slashes (e.g. /a//b/ instead of - # /a/b) - get_filename_component(PREPARED_RELOCATION_PATH - "${PREPARED_RELOCATION_PATH}" ABSOLUTE) - - if(EXISTS "${WDIR}/${PREPARED_RELOCATION_PATH}") - string(APPEND TMP_RPM_PREFIXES "Prefix: ${PREPARED_RELOCATION_PATH}\n") - list(APPEND RPM_USED_PACKAGE_PREFIXES "${PREPARED_RELOCATION_PATH}") - endif() - endforeach() - - # warn about all the paths that are not relocatable - file(GLOB_RECURSE FILE_PATHS_ "${WDIR}/*") - foreach(TMP_PATH ${FILE_PATHS_}) - string(LENGTH "${WDIR}" WDIR_LEN) - string(SUBSTRING "${TMP_PATH}" ${WDIR_LEN} -1 TMP_PATH) - unset(TMP_PATH_FOUND_) - - foreach(RELOCATION_PATH ${RPM_USED_PACKAGE_PREFIXES}) - file(RELATIVE_PATH REL_PATH_ "${RELOCATION_PATH}" "${TMP_PATH}") - string(SUBSTRING "${REL_PATH_}" 0 2 PREFIX_) - - if(NOT "${PREFIX_}" STREQUAL "..") - set(TPM_PATH_FOUND_ TRUE) - break() - endif() - endforeach() - - if(NOT TPM_PATH_FOUND_) - message(AUTHOR_WARNING "CPackRPM:Warning: Path ${TMP_PATH} is not on one of the relocatable paths! Package will be partially relocatable.") - endif() - endforeach() - - set(RPM_USED_PACKAGE_PREFIXES "${RPM_USED_PACKAGE_PREFIXES}" PARENT_SCOPE) - set(TMP_RPM_PREFIXES "${TMP_RPM_PREFIXES}" PARENT_SCOPE) -endfunction() - -function(cpack_rpm_prepare_content_list) - # get files list - file(GLOB_RECURSE CPACK_RPM_INSTALL_FILES LIST_DIRECTORIES true RELATIVE "${WDIR}" "${WDIR}/*") - set(CPACK_RPM_INSTALL_FILES "/${CPACK_RPM_INSTALL_FILES}") - string(REPLACE ";" ";/" CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}") - - # if we are creating a relocatable package, omit parent directories of - # CPACK_RPM_PACKAGE_PREFIX. This is achieved by building a "filter list" - # which is passed to the find command that generates the content-list - if(CPACK_RPM_PACKAGE_RELOCATABLE) - # get a list of the elements in CPACK_RPM_PACKAGE_PREFIXES that are - # destinct parent paths of other relocation paths and remove the - # final element (so the install-prefix dir itself is not omitted - # from the RPM's content-list) - list(SORT RPM_USED_PACKAGE_PREFIXES) - set(_DISTINCT_PATH "NOT_SET") - foreach(_RPM_RELOCATION_PREFIX ${RPM_USED_PACKAGE_PREFIXES}) - if(NOT "${_RPM_RELOCATION_PREFIX}" MATCHES "${_DISTINCT_PATH}/.*") - set(_DISTINCT_PATH "${_RPM_RELOCATION_PREFIX}") - - string(REPLACE "/" ";" _CPACK_RPM_PACKAGE_PREFIX_ELEMS " ${_RPM_RELOCATION_PREFIX}") - list(REMOVE_AT _CPACK_RPM_PACKAGE_PREFIX_ELEMS -1) - unset(_TMP_LIST) - # Now generate all of the parent dirs of the relocation path - foreach(_PREFIX_PATH_ELEM ${_CPACK_RPM_PACKAGE_PREFIX_ELEMS}) - list(APPEND _TMP_LIST "${_PREFIX_PATH_ELEM}") - string(REPLACE ";" "/" _OMIT_DIR "${_TMP_LIST}") - separate_arguments(_OMIT_DIR) - list(APPEND _RPM_DIRS_TO_OMIT ${_OMIT_DIR}) - endforeach() - endif() - endforeach() - endif() - - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: Initial list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}") - endif() - - if(NOT DEFINED CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST) - set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST /etc /etc/init.d /usr /usr/bin - /usr/include /usr/lib /usr/libx32 /usr/lib64 - /usr/share /usr/share/aclocal /usr/share/doc ) - if(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION) - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: Adding ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION} to builtin omit list.") - endif() - list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST "${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION}") - endif() - endif() - - if(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST) - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST= ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST}") - endif() - list(APPEND _RPM_DIRS_TO_OMIT ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST}) - endif() - - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: Final list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}") - endif() - - list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES ${_RPM_DIRS_TO_OMIT}) - - # add man paths that will be compressed - # (copied from /usr/lib/rpm/brp-compress - script that does the actual - # compressing) - list(APPEND MAN_LOCATIONS "/usr/man/man.*" "/usr/man/.*/man.*" "/usr/info.*" - "/usr/share/man/man.*" "/usr/share/man/.*/man.*" "/usr/share/info.*" - "/usr/kerberos/man.*" "/usr/X11R6/man/man.*" "/usr/lib/perl5/man/man.*" - "/usr/share/doc/.*/man/man.*" "/usr/lib/.*/man/man.*") - - if(CPACK_RPM_ADDITIONAL_MAN_DIRS) - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: CPACK_RPM_ADDITIONAL_MAN_DIRS= ${CPACK_RPM_ADDITIONAL_MAN_DIRS}") - endif() - list(APPEND MAN_LOCATIONS ${CPACK_RPM_ADDITIONAL_MAN_DIRS}) - endif() - - foreach(PACK_LOCATION IN LISTS CPACK_RPM_INSTALL_FILES) - foreach(MAN_LOCATION IN LISTS MAN_LOCATIONS) - # man pages are files inside a certain location - if(PACK_LOCATION MATCHES "${MAN_LOCATION}/" - AND NOT IS_DIRECTORY "${WDIR}${PACK_LOCATION}" - AND NOT IS_SYMLINK "${WDIR}${PACK_LOCATION}") - list(FIND CPACK_RPM_INSTALL_FILES "${PACK_LOCATION}" INDEX) - # insert file location that covers compressed man pages - # even if using a wildcard causes duplicates as those are - # handled by RPM and we still keep the same file list - # in spec file - wildcard only represents file type (e.g. .gz) - list(INSERT CPACK_RPM_INSTALL_FILES ${INDEX} "${PACK_LOCATION}*") - # remove file location that doesn't cover compressed man pages - math(EXPR INDEX ${INDEX}+1) - list(REMOVE_AT CPACK_RPM_INSTALL_FILES ${INDEX}) - - break() - endif() - endforeach() - endforeach() - - set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}" PARENT_SCOPE) -endfunction() - -function(cpack_rpm_symlink_get_relocation_prefixes LOCATION PACKAGE_PREFIXES RETURN_VARIABLE) - foreach(PKG_PREFIX IN LISTS PACKAGE_PREFIXES) - string(REGEX MATCH "^${PKG_PREFIX}/.*" FOUND_ "${LOCATION}") - if(FOUND_) - list(APPEND TMP_PREFIXES "${PKG_PREFIX}") - endif() - endforeach() - - set(${RETURN_VARIABLE} "${TMP_PREFIXES}" PARENT_SCOPE) -endfunction() - -function(cpack_rpm_symlink_create_relocation_script PACKAGE_PREFIXES) - list(LENGTH PACKAGE_PREFIXES LAST_INDEX) - set(SORTED_PACKAGE_PREFIXES "${PACKAGE_PREFIXES}") - list(SORT SORTED_PACKAGE_PREFIXES) - list(REVERSE SORTED_PACKAGE_PREFIXES) - math(EXPR LAST_INDEX ${LAST_INDEX}-1) - - foreach(SYMLINK_INDEX RANGE ${LAST_INDEX}) - list(GET SORTED_PACKAGE_PREFIXES ${SYMLINK_INDEX} SRC_PATH) - list(FIND PACKAGE_PREFIXES "${SRC_PATH}" SYMLINK_INDEX) # reverse magic - string(LENGTH "${SRC_PATH}" SRC_PATH_LEN) - - set(PARTS_CNT 0) - set(SCRIPT_PART "if [ \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}\" != \"${SRC_PATH}\" ]; then\n") - - # both paths relocated - foreach(POINT_INDEX RANGE ${LAST_INDEX}) - list(GET SORTED_PACKAGE_PREFIXES ${POINT_INDEX} POINT_PATH) - list(FIND PACKAGE_PREFIXES "${POINT_PATH}" POINT_INDEX) # reverse magic - string(LENGTH "${POINT_PATH}" POINT_PATH_LEN) - - if(_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX}) - if("${SYMLINK_INDEX}" EQUAL "${POINT_INDEX}") - set(INDENT "") - else() - string(APPEND SCRIPT_PART " if [ \"$RPM_INSTALL_PREFIX${POINT_INDEX}\" != \"${POINT_PATH}\" ]; then\n") - set(INDENT " ") - endif() - - foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX}) - math(EXPR PARTS_CNT ${PARTS_CNT}+1) - - math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1) - list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR) - string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX) - - math(EXPR SRC_PATH_END ${SPLIT_INDEX}-${SRC_PATH_LEN}) - string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${SRC_PATH_LEN} ${SRC_PATH_END} SYMLINK_) - - math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1+${POINT_PATH_LEN}) - string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_) - - string(APPEND SCRIPT_PART " ${INDENT}if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n") - string(APPEND SCRIPT_PART " ${INDENT}ln -s \"$RPM_INSTALL_PREFIX${POINT_INDEX}${POINT_}\" \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}${SYMLINK_}\"\n") - string(APPEND SCRIPT_PART " ${INDENT}CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n") - string(APPEND SCRIPT_PART " ${INDENT}fi\n") - endforeach() - - if(NOT "${SYMLINK_INDEX}" EQUAL "${POINT_INDEX}") - string(APPEND SCRIPT_PART " fi\n") - endif() - endif() - endforeach() - - # source path relocated - if(_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X) - foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X) - math(EXPR PARTS_CNT ${PARTS_CNT}+1) - - math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1) - list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR) - string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX) - - math(EXPR SRC_PATH_END ${SPLIT_INDEX}-${SRC_PATH_LEN}) - string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${SRC_PATH_LEN} ${SRC_PATH_END} SYMLINK_) - - math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1) - string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_) - - string(APPEND SCRIPT_PART " if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n") - string(APPEND SCRIPT_PART " ln -s \"${POINT_}\" \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}${SYMLINK_}\"\n") - string(APPEND SCRIPT_PART " CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n") - string(APPEND SCRIPT_PART " fi\n") - endforeach() - endif() - - if(PARTS_CNT) - set(SCRIPT "${SCRIPT_PART}") - string(APPEND SCRIPT "fi\n") - endif() - endforeach() - - # point path relocated - foreach(POINT_INDEX RANGE ${LAST_INDEX}) - list(GET SORTED_PACKAGE_PREFIXES ${POINT_INDEX} POINT_PATH) - list(FIND PACKAGE_PREFIXES "${POINT_PATH}" POINT_INDEX) # reverse magic - string(LENGTH "${POINT_PATH}" POINT_PATH_LEN) - - if(_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX}) - string(APPEND SCRIPT "if [ \"$RPM_INSTALL_PREFIX${POINT_INDEX}\" != \"${POINT_PATH}\" ]; then\n") - - foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX}) - math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1) - list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR) - string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX) - - string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} 0 ${SPLIT_INDEX} SYMLINK_) - - math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1+${POINT_PATH_LEN}) - string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_) - - string(APPEND SCRIPT " if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n") - string(APPEND SCRIPT " ln -s \"$RPM_INSTALL_PREFIX${POINT_INDEX}${POINT_}\" \"${SYMLINK_}\"\n") - string(APPEND SCRIPT " CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n") - string(APPEND SCRIPT " fi\n") - endforeach() - - string(APPEND SCRIPT "fi\n") - endif() - endforeach() - - # no path relocated - if(_RPM_RELOCATION_SCRIPT_X_X) - foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_X_X) - math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1) - list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR) - string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX) - - string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} 0 ${SPLIT_INDEX} SYMLINK_) - - math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1) - string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_) - - string(APPEND SCRIPT "if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n") - string(APPEND SCRIPT " ln -s \"${POINT_}\" \"${SYMLINK_}\"\n") - string(APPEND SCRIPT "fi\n") - endforeach() - endif() - - set(RPM_SYMLINK_POSTINSTALL "${SCRIPT}" PARENT_SCOPE) -endfunction() - -function(cpack_rpm_symlink_add_for_relocation_script PACKAGE_PREFIXES SYMLINK SYMLINK_RELOCATION_PATHS POINT POINT_RELOCATION_PATHS) - list(LENGTH SYMLINK_RELOCATION_PATHS SYMLINK_PATHS_COUTN) - list(LENGTH POINT_RELOCATION_PATHS POINT_PATHS_COUNT) - - list(APPEND _RPM_RELOCATION_SCRIPT_PAIRS "${SYMLINK}:${POINT}") - list(LENGTH _RPM_RELOCATION_SCRIPT_PAIRS PAIR_NO) - - if(SYMLINK_PATHS_COUTN) - foreach(SYMLINK_RELOC_PATH IN LISTS SYMLINK_RELOCATION_PATHS) - list(FIND PACKAGE_PREFIXES "${SYMLINK_RELOC_PATH}" SYMLINK_INDEX) - - # source path relocated - list(APPEND _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X "${PAIR_NO}") - list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X") - - foreach(POINT_RELOC_PATH IN LISTS POINT_RELOCATION_PATHS) - list(FIND PACKAGE_PREFIXES "${POINT_RELOC_PATH}" POINT_INDEX) - - # both paths relocated - list(APPEND _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX} "${PAIR_NO}") - list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX}") - - # point path relocated - list(APPEND _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX} "${PAIR_NO}") - list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX}") - endforeach() - endforeach() - elseif(POINT_PATHS_COUNT) - foreach(POINT_RELOC_PATH IN LISTS POINT_RELOCATION_PATHS) - list(FIND PACKAGE_PREFIXES "${POINT_RELOC_PATH}" POINT_INDEX) - - # point path relocated - list(APPEND _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX} "${PAIR_NO}") - list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX}") - endforeach() - endif() - - # no path relocated - list(APPEND _RPM_RELOCATION_SCRIPT_X_X "${PAIR_NO}") - list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_X") - - # place variables into parent scope - foreach(VAR IN LISTS RELOCATION_VARS) - set(${VAR} "${${VAR}}" PARENT_SCOPE) - endforeach() - set(_RPM_RELOCATION_SCRIPT_PAIRS "${_RPM_RELOCATION_SCRIPT_PAIRS}" PARENT_SCOPE) - set(REQUIRES_SYMLINK_RELOCATION_SCRIPT "true" PARENT_SCOPE) - set(DIRECTIVE "%ghost " PARENT_SCOPE) -endfunction() - -function(cpack_rpm_prepare_install_files INSTALL_FILES_LIST WDIR PACKAGE_PREFIXES IS_RELOCATABLE) - # Prepend directories in ${CPACK_RPM_INSTALL_FILES} with %dir - # This is necessary to avoid duplicate files since rpmbuild does - # recursion on its own when encountering a pathname which is a directory - # which is not flagged as %dir - string(STRIP "${INSTALL_FILES_LIST}" INSTALL_FILES_LIST) - string(REPLACE "\n" ";" INSTALL_FILES_LIST - "${INSTALL_FILES_LIST}") - string(REPLACE "\"" "" INSTALL_FILES_LIST - "${INSTALL_FILES_LIST}") - string(LENGTH "${WDIR}" WDR_LEN_) - - list(SORT INSTALL_FILES_LIST) # make file order consistent on all platforms - - foreach(F IN LISTS INSTALL_FILES_LIST) - unset(DIRECTIVE) - - if(IS_SYMLINK "${WDIR}/${F}") - if(IS_RELOCATABLE) - # check that symlink has relocatable format - get_filename_component(SYMLINK_LOCATION_ "${WDIR}/${F}" DIRECTORY) - execute_process(COMMAND ls -la "${WDIR}/${F}" - WORKING_DIRECTORY "${WDIR}" - OUTPUT_VARIABLE SYMLINK_POINT_ - OUTPUT_STRIP_TRAILING_WHITESPACE) - - string(FIND "${SYMLINK_POINT_}" "->" SYMLINK_POINT_INDEX_ REVERSE) - math(EXPR SYMLINK_POINT_INDEX_ ${SYMLINK_POINT_INDEX_}+3) - string(LENGTH "${SYMLINK_POINT_}" SYMLINK_POINT_LENGTH_) - - # get destination path - string(SUBSTRING "${SYMLINK_POINT_}" ${SYMLINK_POINT_INDEX_} ${SYMLINK_POINT_LENGTH_} SYMLINK_POINT_) - - # check if path is relative or absolute - string(SUBSTRING "${SYMLINK_POINT_}" 0 1 SYMLINK_IS_ABSOLUTE_) - - if(${SYMLINK_IS_ABSOLUTE_} STREQUAL "/") - # prevent absolute paths from having /../ or /./ section inside of them - get_filename_component(SYMLINK_POINT_ "${SYMLINK_POINT_}" ABSOLUTE) - else() - # handle relative path - get_filename_component(SYMLINK_POINT_ "${SYMLINK_LOCATION_}/${SYMLINK_POINT_}" ABSOLUTE) - endif() - - # recalculate path length after conversion to canonical form - string(LENGTH "${SYMLINK_POINT_}" SYMLINK_POINT_LENGTH_) - - if(SYMLINK_POINT_ MATCHES "${WDIR}/.*") - # only symlinks that are pointing inside the packaging structure should be checked for relocation - string(SUBSTRING "${SYMLINK_POINT_}" ${WDR_LEN_} -1 SYMLINK_POINT_WD_) - cpack_rpm_symlink_get_relocation_prefixes("${F}" "${PACKAGE_PREFIXES}" "SYMLINK_RELOCATIONS") - cpack_rpm_symlink_get_relocation_prefixes("${SYMLINK_POINT_WD_}" "${PACKAGE_PREFIXES}" "POINT_RELOCATIONS") - - list(LENGTH SYMLINK_RELOCATIONS SYMLINK_RELOCATIONS_COUNT) - list(LENGTH POINT_RELOCATIONS POINT_RELOCATIONS_COUNT) - else() - # location pointed to is ouside WDR so it should be treated as a permanent symlink - set(SYMLINK_POINT_WD_ "${SYMLINK_POINT_}") - - unset(SYMLINK_RELOCATIONS) - unset(POINT_RELOCATIONS) - unset(SYMLINK_RELOCATIONS_COUNT) - unset(POINT_RELOCATIONS_COUNT) - - message(AUTHOR_WARNING "CPackRPM:Warning: Symbolic link '${F}' points to location that is outside packaging path! Link will possibly not be relocatable.") - endif() - - if(SYMLINK_RELOCATIONS_COUNT AND POINT_RELOCATIONS_COUNT) - # find matching - foreach(SYMLINK_RELOCATION_PREFIX IN LISTS SYMLINK_RELOCATIONS) - list(FIND POINT_RELOCATIONS "${SYMLINK_RELOCATION_PREFIX}" FOUND_INDEX) - if(NOT ${FOUND_INDEX} EQUAL -1) - break() - endif() - endforeach() - - if(NOT ${FOUND_INDEX} EQUAL -1) - # symlinks have the same subpath - if(${SYMLINK_RELOCATIONS_COUNT} EQUAL 1 AND ${POINT_RELOCATIONS_COUNT} EQUAL 1) - # permanent symlink - get_filename_component(SYMLINK_LOCATION_ "${F}" DIRECTORY) - file(RELATIVE_PATH FINAL_PATH_ ${SYMLINK_LOCATION_} ${SYMLINK_POINT_WD_}) - execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${FINAL_PATH_}" "${WDIR}/${F}") - else() - # relocation subpaths - cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}" - "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}") - endif() - else() - # not on the same relocation path - cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}" - "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}") - endif() - elseif(POINT_RELOCATIONS_COUNT) - # point is relocatable - cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}" - "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}") - else() - # is not relocatable or points to non relocatable path - permanent symlink - execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${SYMLINK_POINT_WD_}" "${WDIR}/${F}") - endif() - endif() - elseif(IS_DIRECTORY "${WDIR}/${F}") - set(DIRECTIVE "%dir ") - endif() - - string(APPEND INSTALL_FILES "${DIRECTIVE}\"${F}\"\n") - endforeach() - - if(REQUIRES_SYMLINK_RELOCATION_SCRIPT) - cpack_rpm_symlink_create_relocation_script("${PACKAGE_PREFIXES}") - endif() - - set(RPM_SYMLINK_POSTINSTALL "${RPM_SYMLINK_POSTINSTALL}" PARENT_SCOPE) - set(CPACK_RPM_INSTALL_FILES "${INSTALL_FILES}" PARENT_SCOPE) -endfunction() - -if(CMAKE_BINARY_DIR) - message(FATAL_ERROR "CPackRPM.cmake may only be used by CPack internally.") -endif() - -if(NOT UNIX) - message(FATAL_ERROR "CPackRPM.cmake may only be used under UNIX.") -endif() - -# We need to check if the binaries were compiled with debug symbols -# because without them the package will be useless -function(cpack_rpm_debugsymbol_check INSTALL_FILES WORKING_DIR) - if(NOT CPACK_BUILD_SOURCE_DIRS) - message(FATAL_ERROR "CPackRPM: CPACK_BUILD_SOURCE_DIRS variable is not set!" - " Required for debuginfo packaging. See documentation of" - " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.") - endif() - - # With objdump we should check the debug symbols - find_program(OBJDUMP_EXECUTABLE objdump) - if(NOT OBJDUMP_EXECUTABLE) - message(FATAL_ERROR "CPackRPM: objdump binary could not be found!" - " Required for debuginfo packaging. See documentation of" - " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.") - endif() - - # With debugedit we prepare source files list - find_program(DEBUGEDIT_EXECUTABLE debugedit "/usr/lib/rpm/") - if(NOT DEBUGEDIT_EXECUTABLE) - message(FATAL_ERROR "CPackRPM: debugedit binary could not be found!" - " Required for debuginfo packaging. See documentation of" - " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.") - endif() - - unset(mkdir_list_) - unset(cp_list_) - unset(additional_sources_) - - foreach(F IN LISTS INSTALL_FILES) - if(IS_DIRECTORY "${WORKING_DIR}/${F}" OR IS_SYMLINK "${WORKING_DIR}/${F}") - continue() - endif() - - execute_process(COMMAND "${OBJDUMP_EXECUTABLE}" -h ${WORKING_DIR}/${F} - WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}" - RESULT_VARIABLE OBJDUMP_EXEC_RESULT - OUTPUT_VARIABLE OBJDUMP_OUT - ERROR_QUIET) - # Check if the given file is an executable or not - if(NOT OBJDUMP_EXEC_RESULT) - string(FIND "${OBJDUMP_OUT}" "debug" FIND_RESULT) - if(FIND_RESULT GREATER -1) - set(index_ 0) - foreach(source_dir_ IN LISTS CPACK_BUILD_SOURCE_DIRS) - string(LENGTH "${source_dir_}" source_dir_len_) - string(LENGTH "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}" debuginfo_dir_len) - if(source_dir_len_ LESS debuginfo_dir_len) - message(FATAL_ERROR "CPackRPM: source dir path '${source_dir_}' is" - " shorter than debuginfo sources dir path '${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}'!" - " Source dir path must be longer than debuginfo sources dir path." - " Set CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX variable to a shorter value" - " or make source dir path longer." - " Required for debuginfo packaging. See documentation of" - " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.") - endif() - - file(REMOVE "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}/debugsources_add.list") - execute_process(COMMAND "${DEBUGEDIT_EXECUTABLE}" -b "${source_dir_}" -d "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}" -i -l "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}/debugsources_add.list" "${WORKING_DIR}/${F}" - RESULT_VARIABLE res_ - OUTPUT_VARIABLE opt_ - ERROR_VARIABLE err_ - ) - - file(STRINGS - "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}/debugsources_add.list" - sources_) - list(REMOVE_DUPLICATES sources_) - - foreach(source_ IN LISTS sources_) - if(EXISTS "${source_dir_}/${source_}" AND NOT IS_DIRECTORY "${source_dir_}/${source_}") - get_filename_component(path_part_ "${source_}" DIRECTORY) - list(APPEND mkdir_list_ "%{buildroot}${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${path_part_}") - list(APPEND cp_list_ "cp \"${source_dir_}/${source_}\" \"%{buildroot}${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${path_part_}\"") - - list(APPEND additional_sources_ "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${source_}") - endif() - endforeach() - - math(EXPR index_ "${index_} + 1") - endforeach() - else() - message(WARNING "CPackRPM: File: ${F} does not contain debug symbols. They will possibly be missing from debuginfo package!") - endif() - - get_file_permissions("${WORKING_DIR}/${F}" permissions_) - if(NOT "USER_EXECUTE" IN_LIST permissions_ AND - NOT "GROUP_EXECUTE" IN_LIST permissions_ AND - NOT "WORLD_EXECUTE" IN_LIST permissions_) - if(CPACK_RPM_INSTALL_WITH_EXEC) - execute_process(COMMAND chmod a+x ${WORKING_DIR}/${F} - RESULT_VARIABLE res_ - ERROR_VARIABLE err_ - OUTPUT_QUIET) - - if(res_) - message(FATAL_ERROR "CPackRPM: could not apply execute permissions " - "requested by CPACK_RPM_INSTALL_WITH_EXEC variable on " - "'${WORKING_DIR}/${F}'! Reason: '${err_}'") - endif() - else() - message(AUTHOR_WARNING "CPackRPM: File: ${WORKING_DIR}/${F} does not " - "have execute permissions. Debuginfo symbols will not be extracted" - "! Missing debuginfo may cause packaging failure. Consider setting " - "execute permissions or setting 'CPACK_RPM_INSTALL_WITH_EXEC' " - "variable.") - endif() - endif() - endif() - endforeach() - - list(LENGTH mkdir_list_ len_) - if(len_) - list(REMOVE_DUPLICATES mkdir_list_) - unset(TMP_RPM_DEBUGINFO_INSTALL) - foreach(part_ IN LISTS mkdir_list_) - string(APPEND TMP_RPM_DEBUGINFO_INSTALL "mkdir -p \"${part_}\"\n") - endforeach() - endif() - - list(LENGTH cp_list_ len_) - if(len_) - list(REMOVE_DUPLICATES cp_list_) - foreach(part_ IN LISTS cp_list_) - string(APPEND TMP_RPM_DEBUGINFO_INSTALL "${part_}\n") - endforeach() - endif() - - if(NOT DEFINED CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS) - set(CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS /usr /usr/src /usr/src/debug) - if(CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION) - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: Adding ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION} to builtin omit list.") - endif() - list(APPEND CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS "${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION}") - endif() - endif() - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS= ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS}") - endif() - - list(LENGTH additional_sources_ len_) - if(len_) - list(REMOVE_DUPLICATES additional_sources_) - unset(additional_sources_all_) - foreach(source_ IN LISTS additional_sources_) - string(REPLACE "/" ";" split_source_ " ${source_}") - list(REMOVE_AT split_source_ 0) - unset(tmp_path_) - # Now generate all segments of the path - foreach(segment_ IN LISTS split_source_) - string(APPEND tmp_path_ "/${segment_}") - list(APPEND additional_sources_all_ "${tmp_path_}") - endforeach() - endforeach() - - list(REMOVE_DUPLICATES additional_sources_all_) - list(REMOVE_ITEM additional_sources_all_ - ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS}) - - unset(TMP_DEBUGINFO_ADDITIONAL_SOURCES) - foreach(source_ IN LISTS additional_sources_all_) - string(APPEND TMP_DEBUGINFO_ADDITIONAL_SOURCES "${source_}\n") - endforeach() - endif() - - set(TMP_RPM_DEBUGINFO_INSTALL "${TMP_RPM_DEBUGINFO_INSTALL}" PARENT_SCOPE) - set(TMP_DEBUGINFO_ADDITIONAL_SOURCES "${TMP_DEBUGINFO_ADDITIONAL_SOURCES}" - PARENT_SCOPE) -endfunction() - -function(cpack_rpm_variable_fallback OUTPUT_VAR_NAME) - set(FALLBACK_VAR_NAMES ${ARGN}) - - foreach(variable_name IN LISTS FALLBACK_VAR_NAMES) - if(${variable_name}) - set(${OUTPUT_VAR_NAME} "${${variable_name}}" PARENT_SCOPE) - break() - endif() - endforeach() -endfunction() - -function(cpack_rpm_generate_package) - # rpmbuild is the basic command for building RPM package - # it may be a simple (symbolic) link to rpm command. - find_program(RPMBUILD_EXECUTABLE rpmbuild) - - # Check version of the rpmbuild tool this would be easier to - # track bugs with users and CPackRPM debug mode. - # We may use RPM version in order to check for available version dependent features - if(RPMBUILD_EXECUTABLE) - execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --version - OUTPUT_VARIABLE _TMP_VERSION - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - string(REGEX REPLACE "^.* " "" - RPMBUILD_EXECUTABLE_VERSION - ${_TMP_VERSION}) - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>") - endif() - endif() - - if(NOT RPMBUILD_EXECUTABLE) - message(FATAL_ERROR "RPM package requires rpmbuild executable") - endif() - - # Display lsb_release output if DEBUG mode enable - # This will help to diagnose problem with CPackRPM - # because we will know on which kind of Linux we are - if(CPACK_RPM_PACKAGE_DEBUG) - find_program(LSB_RELEASE_EXECUTABLE lsb_release) - if(LSB_RELEASE_EXECUTABLE) - execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -a - OUTPUT_VARIABLE _TMP_LSB_RELEASE_OUTPUT - ERROR_QUIET - OUTPUT_STRIP_TRAILING_WHITESPACE) - string(REGEX REPLACE "\n" ", " - LSB_RELEASE_OUTPUT - ${_TMP_LSB_RELEASE_OUTPUT}) - else () - set(LSB_RELEASE_OUTPUT "lsb_release not installed/found!") - endif() - message("CPackRPM:Debug: LSB_RELEASE = ${LSB_RELEASE_OUTPUT}") - endif() - - # We may use RPM version in the future in order - # to shut down warning about space in buildtree - # some recent RPM version should support space in different places. - # not checked [yet]. - if(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*") - message(FATAL_ERROR "${RPMBUILD_EXECUTABLE} can't handle paths with spaces, use a build directory without spaces for building RPMs.") - endif() - - # If rpmbuild is found - # we try to discover alien since we may be on non RPM distro like Debian. - # In this case we may try to to use more advanced features - # like generating RPM directly from DEB using alien. - # FIXME feature not finished (yet) - find_program(ALIEN_EXECUTABLE alien) - if(ALIEN_EXECUTABLE) - message(STATUS "alien found, we may be on a Debian based distro.") - endif() - - # Are we packaging components ? - if(CPACK_RPM_PACKAGE_COMPONENT) - string(TOUPPER ${CPACK_RPM_PACKAGE_COMPONENT} CPACK_RPM_PACKAGE_COMPONENT_UPPER) - endif() - - set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}") - - # - # Use user-defined RPM specific variables value - # or generate reasonable default value from - # CPACK_xxx generic values. - # The variables comes from the needed (mandatory or not) - # values found in the RPM specification file aka ".spec" file. - # The variables which may/should be defined are: - # - - # CPACK_RPM_PACKAGE_SUMMARY (mandatory) - - if(CPACK_RPM_PACKAGE_COMPONENT) - cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_SUMMARY" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_SUMMARY" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_SUMMARY") - endif() - - if(NOT CPACK_RPM_PACKAGE_SUMMARY) - if(CPACK_PACKAGE_DESCRIPTION_SUMMARY) - set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}) - else() - # if neither var is defined lets use the name as summary - string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_SUMMARY) - endif() - endif() - - if(NOT CPACK_RPM_PACKAGE_URL AND CMAKE_PROJECT_HOMEPAGE_URL) - set(CPACK_RPM_PACKAGE_URL "${CMAKE_PROJECT_HOMEPAGE_URL}") - endif() - - # CPACK_RPM_PACKAGE_NAME (mandatory) - if(NOT CPACK_RPM_PACKAGE_NAME) - string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME) - endif() - - if(CPACK_RPM_PACKAGE_COMPONENT) - string(TOUPPER "${CPACK_RPM_MAIN_COMPONENT}" - CPACK_RPM_MAIN_COMPONENT_UPPER) - - if(NOT CPACK_RPM_MAIN_COMPONENT_UPPER STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER) - string(APPEND CPACK_RPM_PACKAGE_NAME "-${CPACK_RPM_PACKAGE_COMPONENT}") - - cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_NAME" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_NAME" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_NAME") - endif() - endif() - - # CPACK_RPM_PACKAGE_VERSION (mandatory) - if(NOT CPACK_RPM_PACKAGE_VERSION) - if(NOT CPACK_PACKAGE_VERSION) - message(FATAL_ERROR "RPM package requires a package version") - endif() - set(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}) - endif() - # Replace '-' in version with '_' - # '-' character is an Illegal RPM version character - # it is illegal because it is used to separate - # RPM "Version" from RPM "Release" - string(REPLACE "-" "_" CPACK_RPM_PACKAGE_VERSION ${CPACK_RPM_PACKAGE_VERSION}) - - # CPACK_RPM_PACKAGE_ARCHITECTURE (mandatory) - if(NOT CPACK_RPM_PACKAGE_ARCHITECTURE) - execute_process(COMMAND uname "-m" - OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE - OUTPUT_STRIP_TRAILING_WHITESPACE) - else() - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}") - endif() - endif() - - if(CPACK_RPM_PACKAGE_COMPONENT) - cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_ARCHITECTURE" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_ARCHITECTURE" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_ARCHITECTURE") - - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: using component build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}") - endif() - endif() - - if(${CPACK_RPM_PACKAGE_ARCHITECTURE} STREQUAL "noarch") - set(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE}") - else() - set(TMP_RPM_BUILDARCH "") - endif() - - # CPACK_RPM_PACKAGE_RELEASE - # The RPM release is the numbering of the RPM package ITSELF - # this is the version of the PACKAGING and NOT the version - # of the CONTENT of the package. - # You may well need to generate a new RPM package release - # without changing the version of the packaged software. - # This is the case when the packaging is buggy (not) the software :=) - # If not set, 1 is a good candidate - if(NOT CPACK_RPM_PACKAGE_RELEASE) - set(CPACK_RPM_PACKAGE_RELEASE "1") - endif() - - if(CPACK_RPM_PACKAGE_RELEASE_DIST) - string(APPEND CPACK_RPM_PACKAGE_RELEASE "%{?dist}") - endif() - - # CPACK_RPM_PACKAGE_LICENSE - if(NOT CPACK_RPM_PACKAGE_LICENSE) - set(CPACK_RPM_PACKAGE_LICENSE "unknown") - endif() - - # CPACK_RPM_PACKAGE_GROUP - if(CPACK_RPM_PACKAGE_COMPONENT) - cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_GROUP" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_GROUP" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_GROUP") - endif() - - if(NOT CPACK_RPM_PACKAGE_GROUP) - set(CPACK_RPM_PACKAGE_GROUP "unknown") - endif() - - # CPACK_RPM_PACKAGE_VENDOR - if(NOT CPACK_RPM_PACKAGE_VENDOR) - if(CPACK_PACKAGE_VENDOR) - set(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}") - else() - set(CPACK_RPM_PACKAGE_VENDOR "unknown") - endif() - endif() - - # CPACK_RPM_PACKAGE_SOURCE - # The name of the source tarball in case we generate a source RPM - - # CPACK_RPM_PACKAGE_DESCRIPTION - # The variable content may be either - # - explicitly given by the user or - # - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE - # if it is defined - # - set to a default value - # - - if(CPACK_RPM_PACKAGE_COMPONENT) - cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_DESCRIPTION" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_DESCRIPTION" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_DESCRIPTION" - "CPACK_COMPONENT_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DESCRIPTION") - endif() - - if(NOT CPACK_RPM_PACKAGE_DESCRIPTION) - if(CPACK_PACKAGE_DESCRIPTION_FILE) - file(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION) - else () - set(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available") - endif () - endif () - - # CPACK_RPM_COMPRESSION_TYPE - # - if (CPACK_RPM_COMPRESSION_TYPE) - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: User Specified RPM compression type: ${CPACK_RPM_COMPRESSION_TYPE}") - endif() - if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "lzma") - set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.lzdio") - endif() - if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "xz") - set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w7.xzdio") - endif() - if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "bzip2") - set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.bzdio") - endif() - if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "gzip") - set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.gzdio") - endif() - else() - set(CPACK_RPM_COMPRESSION_TYPE_TMP "") - endif() - - if(NOT CPACK_RPM_PACKAGE_SOURCES) - if(CPACK_PACKAGE_RELOCATABLE OR CPACK_RPM_PACKAGE_RELOCATABLE) - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: Trying to build a relocatable package") - endif() - if(CPACK_SET_DESTDIR AND (NOT CPACK_SET_DESTDIR STREQUAL "I_ON")) - message("CPackRPM:Warning: CPACK_SET_DESTDIR is set (=${CPACK_SET_DESTDIR}) while requesting a relocatable package (CPACK_RPM_PACKAGE_RELOCATABLE is set): this is not supported, the package won't be relocatable.") - set(CPACK_RPM_PACKAGE_RELOCATABLE FALSE) - else() - set(CPACK_RPM_PACKAGE_PREFIX ${CPACK_PACKAGING_INSTALL_PREFIX}) # kept for back compatibility (provided external RPM spec files) - cpack_rpm_prepare_relocation_paths() - set(CPACK_RPM_PACKAGE_RELOCATABLE TRUE) - endif() - endif() - else() - if(CPACK_RPM_PACKAGE_COMPONENT) - message(FATAL_ERROR "CPACK_RPM_PACKAGE_SOURCES parameter can not be used" - " in combination with CPACK_RPM_PACKAGE_COMPONENT parameter!") - endif() - - set(CPACK_RPM_PACKAGE_RELOCATABLE FALSE) # disable relocatable option if building source RPM - endif() - - execute_process( - COMMAND "${RPMBUILD_EXECUTABLE}" --querytags - OUTPUT_VARIABLE RPMBUILD_TAG_LIST - OUTPUT_STRIP_TRAILING_WHITESPACE) - string(REPLACE "\n" ";" RPMBUILD_TAG_LIST "${RPMBUILD_TAG_LIST}") - - if(CPACK_RPM_PACKAGE_EPOCH) - set(TMP_RPM_EPOCH "Epoch: ${CPACK_RPM_PACKAGE_EPOCH}") - endif() - - # Check if additional fields for RPM spec header are given - # There may be some COMPONENT specific variables as well - # If component specific var is not provided we use the global one - # for each component - foreach(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS PROVIDES OBSOLETES PREFIX CONFLICTS AUTOPROV AUTOREQ AUTOREQPROV REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN) - - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: processing ${_RPM_SPEC_HEADER}") - endif() - - if(CPACK_RPM_PACKAGE_COMPONENT) - cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER}" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_${_RPM_SPEC_HEADER}") - endif() - - if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}) - # Prefix can be replaced by Prefixes but the old version still works so we'll ignore it for now - # Requires* is a special case because it gets transformed to Requires(pre/post/preun/postun) - # Auto* is a special case because the tags can not be queried by querytags rpmbuild flag - set(special_case_tags_ PREFIX REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN AUTOPROV AUTOREQ AUTOREQPROV) - if(NOT _RPM_SPEC_HEADER IN_LIST RPMBUILD_TAG_LIST AND NOT _RPM_SPEC_HEADER IN_LIST special_case_tags_) - message(AUTHOR_WARNING "CPackRPM:Warning: ${_RPM_SPEC_HEADER} not " - "supported in provided rpmbuild. Tag will not be used.") - continue() - endif() - - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: using CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}") - endif() - - set(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}}) - endif() - - # Treat the RPM Spec keyword iff it has been properly defined - if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP) - # Transform NAME --> Name e.g. PROVIDES --> Provides - # The Upper-case first letter and lowercase tail is the - # appropriate value required in the final RPM spec file. - string(SUBSTRING ${_RPM_SPEC_HEADER} 1 -1 _PACKAGE_HEADER_TAIL) - string(TOLOWER "${_PACKAGE_HEADER_TAIL}" _PACKAGE_HEADER_TAIL) - string(SUBSTRING ${_RPM_SPEC_HEADER} 0 1 _PACKAGE_HEADER_NAME) - string(APPEND _PACKAGE_HEADER_NAME "${_PACKAGE_HEADER_TAIL}") - # The following keywords require parentheses around the "pre" or "post" suffix in the final RPM spec file. - set(SCRIPTS_REQUIREMENTS_LIST REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN) - list(FIND SCRIPTS_REQUIREMENTS_LIST ${_RPM_SPEC_HEADER} IS_SCRIPTS_REQUIREMENT_FOUND) - if(NOT ${IS_SCRIPTS_REQUIREMENT_FOUND} EQUAL -1) - string(REPLACE "_" "(" _PACKAGE_HEADER_NAME "${_PACKAGE_HEADER_NAME}") - string(APPEND _PACKAGE_HEADER_NAME ")") - endif() - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: User defined ${_PACKAGE_HEADER_NAME}:\n ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}") - endif() - set(TMP_RPM_${_RPM_SPEC_HEADER} "${_PACKAGE_HEADER_NAME}: ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}") - unset(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP) - endif() - endforeach() - - # CPACK_RPM_SPEC_INSTALL_POST - # May be used to define a RPM post intallation script - # for example setting it to "/bin/true" may prevent - # rpmbuild from stripping binaries. - if(CPACK_RPM_SPEC_INSTALL_POST) - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}") - endif() - set(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}") - endif() - - # CPACK_RPM_POST_INSTALL_SCRIPT_FILE (or CPACK_RPM__POST_INSTALL_SCRIPT_FILE) - # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE (or CPACK_RPM__POST_UNINSTALL_SCRIPT_FILE) - # May be used to embed a post (un)installation script in the spec file. - # The referred script file(s) will be read and directly - # put after the %post or %postun section - # ---------------------------------------------------------------- - # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE (or CPACK_RPM__PRE_INSTALL_SCRIPT_FILE) - # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE (or CPACK_RPM__PRE_UNINSTALL_SCRIPT_FILE) - # May be used to embed a pre (un)installation script in the spec file. - # The referred script file(s) will be read and directly - # put after the %pre or %preun section - foreach(RPM_SCRIPT_FILE_TYPE_ "INSTALL" "UNINSTALL") - foreach(RPM_SCRIPT_FILE_TIME_ "PRE" "POST") - set("CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE" - "${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE}") - - if(CPACK_RPM_PACKAGE_COMPONENT) - cpack_rpm_variable_fallback("CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE") - endif() - - # Handle file if it has been specified - if(CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE) - if(EXISTS ${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE}) - file(READ ${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE} - "CPACK_RPM_SPEC_${RPM_SCRIPT_FILE_TIME_}${RPM_SCRIPT_FILE_TYPE_}") - else() - message("CPackRPM:Warning: CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE <${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE}> does not exists - ignoring") - endif() - else() - # reset SPEC var value if no file has been specified - # (either globally or component-wise) - set("CPACK_RPM_SPEC_${RPM_SCRIPT_FILE_TIME_}${RPM_SCRIPT_FILE_TYPE_}" "") - endif() - endforeach() - endforeach() - - # CPACK_RPM_CHANGELOG_FILE - # May be used to embed a changelog in the spec file. - # The referred file will be read and directly put after the %changelog section - if(CPACK_RPM_CHANGELOG_FILE) - if(EXISTS ${CPACK_RPM_CHANGELOG_FILE}) - file(READ ${CPACK_RPM_CHANGELOG_FILE} CPACK_RPM_SPEC_CHANGELOG) - else() - message(SEND_ERROR "CPackRPM:Warning: CPACK_RPM_CHANGELOG_FILE <${CPACK_RPM_CHANGELOG_FILE}> does not exists - ignoring") - endif() - else() - set(CPACK_RPM_SPEC_CHANGELOG "* Sun Jul 4 2010 Eric Noulard - ${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}\n Generated by CPack RPM (no Changelog file were provided)") - endif() - - # CPACK_RPM_SPEC_MORE_DEFINE - # This is a generated spec rpm file spaceholder - if(CPACK_RPM_SPEC_MORE_DEFINE) - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: User defined more define spec line specified:\n ${CPACK_RPM_SPEC_MORE_DEFINE}") - endif() - endif() - - # Now we may create the RPM build tree structure - set(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}") - message(STATUS "CPackRPM:Debug: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}") - # Prepare RPM build tree - file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}) - file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp) - file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD) - file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS) - file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES) - file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS) - file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS) - - # it seems rpmbuild can't handle spaces in the path - # neither escaping (as below) nor putting quotes around the path seem to help - #string(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}") - set(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}") - - cpack_rpm_prepare_content_list() - - # In component case, put CPACK_ABSOLUTE_DESTINATION_FILES_ - # into CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL - # otherwise, put CPACK_ABSOLUTE_DESTINATION_FILES - # This must be done BEFORE the CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL handling - if(CPACK_RPM_PACKAGE_COMPONENT) - if(CPACK_ABSOLUTE_DESTINATION_FILES) - cpack_rpm_variable_fallback("COMPONENT_FILES_TAG" - "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT}" - "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}") - set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${${COMPONENT_FILES_TAG}}") - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: Handling Absolute Destination Files: <${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}>") - message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}") - endif() - endif() - else() - if(CPACK_ABSOLUTE_DESTINATION_FILES) - set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${CPACK_ABSOLUTE_DESTINATION_FILES}") - endif() - endif() - - # In component case, set CPACK_RPM_USER_FILELIST_INTERNAL with CPACK_RPM__USER_FILELIST. - set(CPACK_RPM_USER_FILELIST_INTERNAL "") - if(CPACK_RPM_PACKAGE_COMPONENT) - cpack_rpm_variable_fallback("CPACK_RPM_USER_FILELIST_INTERNAL" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_USER_FILELIST") - - if(CPACK_RPM_PACKAGE_DEBUG AND CPACK_RPM_USER_FILELIST_INTERNAL) - message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>") - message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}") - endif() - elseif(CPACK_RPM_USER_FILELIST) - set(CPACK_RPM_USER_FILELIST_INTERNAL "${CPACK_RPM_USER_FILELIST}") - endif() - - # Handle user specified file line list in CPACK_RPM_USER_FILELIST_INTERNAL - # Remove those files from CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL - # or CPACK_RPM_INSTALL_FILES, - # hence it must be done before these auto-generated lists are processed. - if(CPACK_RPM_USER_FILELIST_INTERNAL) - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>") - endif() - - # Create CMake list from CPACK_RPM_INSTALL_FILES - string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST) - string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST - "${CPACK_RPM_INSTALL_FILES_LIST}") - string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST - "${CPACK_RPM_INSTALL_FILES_LIST}") - - set(CPACK_RPM_USER_INSTALL_FILES "") - foreach(F IN LISTS CPACK_RPM_USER_FILELIST_INTERNAL) - string(REGEX REPLACE "%[A-Za-z]+(\\([^()]*\\))? " "" F_PATH ${F}) - string(REGEX MATCH "(%[A-Za-z]+(\\([^()]*\\))? )*" F_PREFIX ${F}) - string(STRIP ${F_PREFIX} F_PREFIX) - - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: F_PREFIX=<${F_PREFIX}>, F_PATH=<${F_PATH}>") - endif() - if(F_PREFIX) - string(APPEND F_PREFIX " ") - endif() - # Rebuild the user list file - string(APPEND CPACK_RPM_USER_INSTALL_FILES "${F_PREFIX}\"${F_PATH}\"\n") - - # Remove from CPACK_RPM_INSTALL_FILES and CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL - list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${F_PATH}) - # ABSOLUTE destination files list may not exists at all - if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL) - list(REMOVE_ITEM CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL ${F_PATH}) - endif() - endforeach() - - # Rebuild CPACK_RPM_INSTALL_FILES - set(CPACK_RPM_INSTALL_FILES "") - foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST) - string(APPEND CPACK_RPM_INSTALL_FILES "\"${F}\"\n") - endforeach() - else() - set(CPACK_RPM_USER_INSTALL_FILES "") - endif() - - if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL) - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: Handling Absolute Destination Files: ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}") - endif() - # Remove trailing space - string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST) - # Transform endline separated - string into CMake List - string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}") - # Remove unnecessary quotes - string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}") - # Remove ABSOLUTE install file from INSTALL FILE LIST - list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}) - # Rebuild INSTALL_FILES - set(CPACK_RPM_INSTALL_FILES "") - foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST) - string(APPEND CPACK_RPM_INSTALL_FILES "\"${F}\"\n") - endforeach() - # Build ABSOLUTE_INSTALL_FILES - set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "") - foreach(F IN LISTS CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL) - string(APPEND CPACK_RPM_ABSOLUTE_INSTALL_FILES "%config \"${F}\"\n") - endforeach() - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: CPACK_RPM_ABSOLUTE_INSTALL_FILES=${CPACK_RPM_ABSOLUTE_INSTALL_FILES}") - message("CPackRPM:Debug: CPACK_RPM_INSTALL_FILES=${CPACK_RPM_INSTALL_FILES}") - endif() - else() - # reset vars in order to avoid leakage of value(s) from one component to another - set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "") - endif() - - cpack_rpm_variable_fallback("CPACK_RPM_DEBUGINFO_PACKAGE" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_DEBUGINFO_PACKAGE" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEBUGINFO_PACKAGE" - "CPACK_RPM_DEBUGINFO_PACKAGE") - if(CPACK_RPM_DEBUGINFO_PACKAGE OR (CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND NOT GENERATE_SPEC_PARTS)) - cpack_rpm_variable_fallback("CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_BUILD_SOURCE_DIRS_PREFIX" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_BUILD_SOURCE_DIRS_PREFIX" - "CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX") - if(NOT CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX) - set(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX "/usr/src/debug/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}") - endif() - - # handle cases where path contains extra slashes (e.g. /a//b/ instead of - # /a/b) - get_filename_component(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX - "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}" ABSOLUTE) - - if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND GENERATE_SPEC_PARTS) - file(WRITE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_COMPONENT}.files" - "${CPACK_RPM_INSTALL_FILES}") - else() - if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND CPACK_RPM_PACKAGE_COMPONENT) - # this part is only required by components packaging - with monolithic - # packages we can be certain that there are no other components present - # so CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE is a noop - if(CPACK_RPM_DEBUGINFO_PACKAGE) - # only add current package files to debuginfo list if debuginfo - # generation is enabled for current package - string(STRIP "${CPACK_RPM_INSTALL_FILES}" install_files_) - string(REPLACE "\n" ";" install_files_ "${install_files_}") - string(REPLACE "\"" "" install_files_ "${install_files_}") - else() - unset(install_files_) - endif() - - file(GLOB files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.files") - - foreach(f_ IN LISTS files_) - file(READ "${f_}" tmp_) - string(APPEND install_files_ ";${tmp_}") - endforeach() - - # if there were other components/groups so we need to move files from them - # to current component otherwise those files won't be found - file(GLOB components_ LIST_DIRECTORIES true RELATIVE - "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}" - "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/*") - foreach(component_ IN LISTS components_) - string(TOUPPER "${component_}" component_dir_upper_) - if(component_dir_upper_ STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER) - # skip current component - continue() - endif() - - file(GLOB_RECURSE files_for_move_ LIST_DIRECTORIES false RELATIVE - "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}" - "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}/*") - - foreach(f_ IN LISTS files_for_move_) - get_filename_component(dir_path_ "${f_}" DIRECTORY) - set(src_file_ - "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}/${f_}") - - # check that we are not overriding an existing file that doesn't - # match the file that we want to copy - if(EXISTS "${src_file_}" AND EXISTS "${WDIR}/${f_}") - execute_process( - COMMAND ${CMAKE_COMMAND} -E compare_files "${src_file_}" "${WDIR}/${f_}" - RESULT_VARIABLE res_ - ) - if(res_) - message(FATAL_ERROR "CPackRPM:Error: File on path '${WDIR}/${f_}'" - " already exists but is a different than the one in component" - " '${component_}'! Packages will not be generated.") - endif() - endif() - - file(MAKE_DIRECTORY "${WDIR}/${dir_path_}") - file(RENAME "${src_file_}" - "${WDIR}/${f_}") - endforeach() - endforeach() - - cpack_rpm_debugsymbol_check("${install_files_}" "${WDIR}") - else() - string(STRIP "${CPACK_RPM_INSTALL_FILES}" install_files_) - string(REPLACE "\n" ";" install_files_ "${install_files_}") - string(REPLACE "\"" "" install_files_ "${install_files_}") - - cpack_rpm_debugsymbol_check("${install_files_}" "${WDIR}") - endif() - - if(TMP_DEBUGINFO_ADDITIONAL_SOURCES) - set(TMP_RPM_DEBUGINFO " -# Modified version of %%debug_package macro -# defined in /usr/lib/rpm/macros as that one -# can't handle injection of extra source files. -%ifnarch noarch -%global __debug_package 1 -%package debuginfo -Summary: Debug information for package %{name} -Group: Development/Debug -AutoReqProv: 0 -%description debuginfo -This package provides debug information for package %{name}. -Debug information is useful when developing applications that use this -package or when debugging this package. -%files debuginfo -f debugfiles.list -%defattr(-,root,root) -${TMP_DEBUGINFO_ADDITIONAL_SOURCES} -%endif -") - elseif(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE) - message(AUTHOR_WARNING "CPackRPM:Warning: debuginfo package was requested" - " but will not be generated as no source files were found!") - else() - message(AUTHOR_WARNING "CPackRPM:Warning: debuginfo package was requested" - " but will not be generated as no source files were found! Component: '" - "${CPACK_RPM_PACKAGE_COMPONENT}'.") - endif() - endif() - endif() - - # Prepare install files - cpack_rpm_prepare_install_files( - "${CPACK_RPM_INSTALL_FILES}" - "${WDIR}" - "${RPM_USED_PACKAGE_PREFIXES}" - "${CPACK_RPM_PACKAGE_RELOCATABLE}" - ) - - # set default user and group - foreach(_PERM_TYPE "USER" "GROUP") - if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}) - set(TMP_DEFAULT_${_PERM_TYPE} "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}}") - elseif(CPACK_RPM_DEFAULT_${_PERM_TYPE}) - set(TMP_DEFAULT_${_PERM_TYPE} "${CPACK_RPM_DEFAULT_${_PERM_TYPE}}") - else() - set(TMP_DEFAULT_${_PERM_TYPE} "root") - endif() - endforeach() - - # set default file and dir permissions - foreach(_PERM_TYPE "FILE" "DIR") - if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS) - get_unix_permissions_octal_notation("CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS" "TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS") - set(_PERMISSIONS_VAR "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS") - elseif(CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS) - get_unix_permissions_octal_notation("CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS" "TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS") - set(_PERMISSIONS_VAR "CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS") - else() - set(TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS "-") - endif() - endforeach() - - # The name of the final spec file to be used by rpmbuild - set(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}.spec") - - # Print out some debug information if we were asked for that - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}") - message("CPackRPM:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}") - message("CPackRPM:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}") - message("CPackRPM:Debug: CPACK_OUTPUT_FILE_NAME = ${CPACK_OUTPUT_FILE_NAME}") - message("CPackRPM:Debug: CPACK_OUTPUT_FILE_PATH = ${CPACK_OUTPUT_FILE_PATH}") - message("CPackRPM:Debug: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}") - message("CPackRPM:Debug: CPACK_RPM_BINARY_SPECFILE = ${CPACK_RPM_BINARY_SPECFILE}") - message("CPackRPM:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}") - message("CPackRPM:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}") - endif() - - # - # USER generated/provided spec file handling. - # - - # We can have a component specific spec file. - if(CPACK_RPM_PACKAGE_COMPONENT) - cpack_rpm_variable_fallback("CPACK_RPM_USER_BINARY_SPECFILE" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_BINARY_SPECFILE" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_USER_BINARY_SPECFILE") - endif() - - cpack_rpm_variable_fallback("CPACK_RPM_FILE_NAME" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_FILE_NAME" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_FILE_NAME" - "CPACK_RPM_FILE_NAME") - if(NOT CPACK_RPM_FILE_NAME STREQUAL "RPM-DEFAULT") - if(CPACK_RPM_FILE_NAME) - if(NOT CPACK_RPM_FILE_NAME MATCHES ".*\\.rpm") - message(FATAL_ERROR "'${CPACK_RPM_FILE_NAME}' is not a valid RPM package file name as it must end with '.rpm'!") - endif() - else() - # old file name format for back compatibility - string(TOUPPER "${CPACK_RPM_MAIN_COMPONENT}" - CPACK_RPM_MAIN_COMPONENT_UPPER) - - if(CPACK_RPM_MAIN_COMPONENT_UPPER STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER) - # this is the main component so ignore the component filename part - set(CPACK_RPM_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}.rpm") - else() - set(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}") - endif() - endif() - # else example: - #set(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm") - - if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND GENERATE_SPEC_PARTS) - string(TOLOWER "${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.*\\.rpm" expected_filename_) - - file(WRITE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_COMPONENT}.rpm_name" - "${expected_filename_};${CPACK_RPM_FILE_NAME}") - elseif(NOT CPACK_RPM_DEBUGINFO_PACKAGE) - set(FILE_NAME_DEFINE "%define _rpmfilename ${CPACK_RPM_FILE_NAME}") - endif() - endif() - - if(CPACK_RPM_PACKAGE_SOURCES) # source rpm - set(archive_name_ "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}") - - execute_process( - COMMAND ${CMAKE_COMMAND} -E tar "cfvz" "${CPACK_RPM_DIRECTORY}/SOURCES/${archive_name_}.tar.gz" "${CPACK_PACKAGE_FILE_NAME}" - WORKING_DIRECTORY ${CPACK_RPM_DIRECTORY} - ) - set(TMP_RPM_SOURCE "Source: ${archive_name_}.tar.gz") - - if(CPACK_RPM_BUILDREQUIRES) - set(TMP_RPM_BUILD_REQUIRES "BuildRequires: ${CPACK_RPM_BUILDREQUIRES}") - endif() - - # Disable debuginfo packages - srpm generates invalid packages due to - # releasing control to cpack to generate binary packages. - # Note however that this doesn't prevent cpack to generate debuginfo - # packages when run from srpm with --rebuild. - set(TMP_RPM_DISABLE_DEBUGINFO "%define debug_package %{nil}") - - if(NOT CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX) - set(CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX "/") - endif() - - set(TMP_RPM_BUILD - " -%build -mkdir cpack_rpm_build_dir -cd cpack_rpm_build_dir -cmake ${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DCPACK_PACKAGING_INSTALL_PREFIX=${CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX} ../${CPACK_PACKAGE_FILE_NAME} -make %{?_smp_mflags}" # %{?_smp_mflags} -> -j option - ) - set(TMP_RPM_INSTALL - " -cd cpack_rpm_build_dir -cpack -G RPM -mv *.rpm %_rpmdir" - ) - set(TMP_RPM_PREP "%setup -c") - - set(RPMBUILD_FLAGS "-bs") - - file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in - "# Restore old style debuginfo creation for rpm >= 4.14. -%undefine _debugsource_packages -%undefine _debuginfo_subpackages - -# -*- rpm-spec -*- -BuildRoot: %_topdir/\@CPACK_PACKAGE_FILE_NAME\@ -Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@ -Name: \@CPACK_RPM_PACKAGE_NAME\@ -Version: \@CPACK_RPM_PACKAGE_VERSION\@ -Release: \@CPACK_RPM_PACKAGE_RELEASE\@ -License: \@CPACK_RPM_PACKAGE_LICENSE\@ -Group: \@CPACK_RPM_PACKAGE_GROUP\@ -Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@ - -\@TMP_RPM_SOURCE\@ -\@TMP_RPM_BUILD_REQUIRES\@ -\@TMP_RPM_BUILDARCH\@ -\@TMP_RPM_PREFIXES\@ - -\@TMP_RPM_DISABLE_DEBUGINFO\@ - -%define _rpmdir %_topdir/RPMS -%define _srcrpmdir %_topdir/SRPMS -\@FILE_NAME_DEFINE\@ -%define _unpackaged_files_terminate_build 0 -\@TMP_RPM_SPEC_INSTALL_POST\@ -\@CPACK_RPM_SPEC_MORE_DEFINE\@ -\@CPACK_RPM_COMPRESSION_TYPE_TMP\@ - -%description -\@CPACK_RPM_PACKAGE_DESCRIPTION\@ - -# This is a shortcutted spec file generated by CMake RPM generator -# we skip _install step because CPack does that for us. -# We do only save CPack installed tree in _prepr -# and then restore it in build. -%prep -\@TMP_RPM_PREP\@ - -\@TMP_RPM_BUILD\@ - -#p build - -%install -\@TMP_RPM_INSTALL\@ - -%clean - -%changelog -\@CPACK_RPM_SPEC_CHANGELOG\@ -" - ) - - elseif(GENERATE_SPEC_PARTS) # binary rpm with single debuginfo package - file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in - "# -*- rpm-spec -*- -%package -n \@CPACK_RPM_PACKAGE_NAME\@ -Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@ -Version: \@CPACK_RPM_PACKAGE_VERSION\@ -Release: \@CPACK_RPM_PACKAGE_RELEASE\@ -License: \@CPACK_RPM_PACKAGE_LICENSE\@ -Group: \@CPACK_RPM_PACKAGE_GROUP\@ -Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@ - -\@TMP_RPM_URL\@ -\@TMP_RPM_REQUIRES\@ -\@TMP_RPM_REQUIRES_PRE\@ -\@TMP_RPM_REQUIRES_POST\@ -\@TMP_RPM_REQUIRES_PREUN\@ -\@TMP_RPM_REQUIRES_POSTUN\@ -\@TMP_RPM_PROVIDES\@ -\@TMP_RPM_OBSOLETES\@ -\@TMP_RPM_CONFLICTS\@ -\@TMP_RPM_SUGGESTS\@ -\@TMP_RPM_AUTOPROV\@ -\@TMP_RPM_AUTOREQ\@ -\@TMP_RPM_AUTOREQPROV\@ -\@TMP_RPM_BUILDARCH\@ -\@TMP_RPM_PREFIXES\@ -\@TMP_RPM_EPOCH\@ - -%description -n \@CPACK_RPM_PACKAGE_NAME\@ -\@CPACK_RPM_PACKAGE_DESCRIPTION\@ - -%files -n \@CPACK_RPM_PACKAGE_NAME\@ -%defattr(\@TMP_DEFAULT_FILE_PERMISSIONS\@,\@TMP_DEFAULT_USER\@,\@TMP_DEFAULT_GROUP\@,\@TMP_DEFAULT_DIR_PERMISSIONS\@) -\@CPACK_RPM_INSTALL_FILES\@ -\@CPACK_RPM_ABSOLUTE_INSTALL_FILES\@ -\@CPACK_RPM_USER_INSTALL_FILES\@ -" - ) - - else() # binary rpm - if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE) - # find generated spec file and take its name - file(GLOB spec_files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.spec") - - foreach(f_ IN LISTS spec_files_) - file(READ "${f_}" tmp_) - string(APPEND TMP_OTHER_COMPONENTS "\n${tmp_}\n") - endforeach() - endif() - - # We should generate a USER spec file template: - # - either because the user asked for it : CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE - # - or the user did not provide one : NOT CPACK_RPM_USER_BINARY_SPECFILE - set(RPMBUILD_FLAGS "-bb") - if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE) - - file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in - "# Restore old style debuginfo creation for rpm >= 4.14. -%undefine _debugsource_packages -%undefine _debuginfo_subpackages - -# -*- rpm-spec -*- -BuildRoot: %_topdir/\@CPACK_PACKAGE_FILE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH\@ -Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@ -Name: \@CPACK_RPM_PACKAGE_NAME\@ -Version: \@CPACK_RPM_PACKAGE_VERSION\@ -Release: \@CPACK_RPM_PACKAGE_RELEASE\@ -License: \@CPACK_RPM_PACKAGE_LICENSE\@ -Group: \@CPACK_RPM_PACKAGE_GROUP\@ -Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@ - -\@TMP_RPM_URL\@ -\@TMP_RPM_REQUIRES\@ -\@TMP_RPM_REQUIRES_PRE\@ -\@TMP_RPM_REQUIRES_POST\@ -\@TMP_RPM_REQUIRES_PREUN\@ -\@TMP_RPM_REQUIRES_POSTUN\@ -\@TMP_RPM_PROVIDES\@ -\@TMP_RPM_OBSOLETES\@ -\@TMP_RPM_CONFLICTS\@ -\@TMP_RPM_SUGGESTS\@ -\@TMP_RPM_AUTOPROV\@ -\@TMP_RPM_AUTOREQ\@ -\@TMP_RPM_AUTOREQPROV\@ -\@TMP_RPM_BUILDARCH\@ -\@TMP_RPM_PREFIXES\@ -\@TMP_RPM_EPOCH\@ - -\@TMP_RPM_DEBUGINFO\@ - -%define _rpmdir %_topdir/RPMS -%define _srcrpmdir %_topdir/SRPMS -\@FILE_NAME_DEFINE\@ -%define _unpackaged_files_terminate_build 0 -\@TMP_RPM_SPEC_INSTALL_POST\@ -\@CPACK_RPM_SPEC_MORE_DEFINE\@ -\@CPACK_RPM_COMPRESSION_TYPE_TMP\@ - -%description -\@CPACK_RPM_PACKAGE_DESCRIPTION\@ - -# This is a shortcutted spec file generated by CMake RPM generator -# we skip _install step because CPack does that for us. -# We do only save CPack installed tree in _prepr -# and then restore it in build. -%prep -mv $RPM_BUILD_ROOT %_topdir/tmpBBroot - -%install -if [ -e $RPM_BUILD_ROOT ]; -then - rm -rf $RPM_BUILD_ROOT -fi -mv %_topdir/tmpBBroot $RPM_BUILD_ROOT - -\@TMP_RPM_DEBUGINFO_INSTALL\@ - -%clean - -%post -\@RPM_SYMLINK_POSTINSTALL\@ -\@CPACK_RPM_SPEC_POSTINSTALL\@ - -%postun -\@CPACK_RPM_SPEC_POSTUNINSTALL\@ - -%pre -\@CPACK_RPM_SPEC_PREINSTALL\@ - -%preun -\@CPACK_RPM_SPEC_PREUNINSTALL\@ - -%files -%defattr(\@TMP_DEFAULT_FILE_PERMISSIONS\@,\@TMP_DEFAULT_USER\@,\@TMP_DEFAULT_GROUP\@,\@TMP_DEFAULT_DIR_PERMISSIONS\@) -\@CPACK_RPM_INSTALL_FILES\@ -\@CPACK_RPM_ABSOLUTE_INSTALL_FILES\@ -\@CPACK_RPM_USER_INSTALL_FILES\@ - -%changelog -\@CPACK_RPM_SPEC_CHANGELOG\@ - -\@TMP_OTHER_COMPONENTS\@ -" - ) - endif() - - # Stop here if we were asked to only generate a template USER spec file - # The generated file may then be used as a template by user who wants - # to customize their own spec file. - if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE) - message(FATAL_ERROR "CPackRPM: STOP here Generated USER binary spec file template is: ${CPACK_RPM_BINARY_SPECFILE}.in") - endif() - endif() - - # After that we may either use a user provided spec file - # or generate one using appropriate variables value. - if(CPACK_RPM_USER_BINARY_SPECFILE) - # User may have specified SPECFILE just use it - message("CPackRPM: Will use USER specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}") - # The user provided file is processed for @var replacement - configure_file(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY) - else() - # No User specified spec file, will use the generated spec file - message("CPackRPM: Will use GENERATED spec file: ${CPACK_RPM_BINARY_SPECFILE}") - # Note the just created file is processed for @var replacement - configure_file(${CPACK_RPM_BINARY_SPECFILE}.in ${CPACK_RPM_BINARY_SPECFILE} @ONLY) - endif() - - if(NOT GENERATE_SPEC_PARTS) # generate package - if(RPMBUILD_EXECUTABLE) - # Now call rpmbuild using the SPECFILE - execute_process( - COMMAND "${RPMBUILD_EXECUTABLE}" ${RPMBUILD_FLAGS} - --define "_topdir ${CPACK_RPM_DIRECTORY}" - --buildroot "%_topdir/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}" - --target "${CPACK_RPM_PACKAGE_ARCHITECTURE}" - "${CPACK_RPM_BINARY_SPECFILE}" - WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}" - RESULT_VARIABLE CPACK_RPMBUILD_EXEC_RESULT - ERROR_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err" - OUTPUT_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out") - if(CPACK_RPM_PACKAGE_DEBUG OR CPACK_RPMBUILD_EXEC_RESULT) - file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err RPMBUILDERR) - file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out RPMBUILDOUT) - message("CPackRPM:Debug: You may consult rpmbuild logs in: ") - message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err") - message("CPackRPM:Debug: *** ${RPMBUILDERR} ***") - message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out") - message("CPackRPM:Debug: *** ${RPMBUILDOUT} ***") - endif() - else() - if(ALIEN_EXECUTABLE) - message(FATAL_ERROR "RPM packaging through alien not done (yet)") - endif() - endif() - - # find generated rpm files and take their names - file(GLOB_RECURSE GENERATED_FILES "${CPACK_RPM_DIRECTORY}/RPMS/*.rpm" - "${CPACK_RPM_DIRECTORY}/SRPMS/*.rpm") - - if(NOT GENERATED_FILES) - message(FATAL_ERROR "RPM package was not generated! ${CPACK_RPM_DIRECTORY}") - endif() - - unset(expected_filenames_) - unset(filenames_) - if(CPACK_RPM_DEBUGINFO_PACKAGE AND NOT CPACK_RPM_FILE_NAME STREQUAL "RPM-DEFAULT") - list(APPEND expected_filenames_ - "${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.*\\.rpm") - list(APPEND filenames_ "${CPACK_RPM_FILE_NAME}") - endif() - - if(CPACK_RPM_DEBUGINFO_PACKAGE) - cpack_rpm_variable_fallback("CPACK_RPM_DEBUGINFO_FILE_NAME" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_DEBUGINFO_FILE_NAME" - "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEBUGINFO_FILE_NAME" - "CPACK_RPM_DEBUGINFO_FILE_NAME") - - if(CPACK_RPM_DEBUGINFO_FILE_NAME AND - NOT CPACK_RPM_DEBUGINFO_FILE_NAME STREQUAL "RPM-DEFAULT") - list(APPEND expected_filenames_ - "${CPACK_RPM_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}.*\\.rpm") - string(REPLACE "@cpack_component@" "${CPACK_RPM_PACKAGE_COMPONENT}" - CPACK_RPM_DEBUGINFO_FILE_NAME "${CPACK_RPM_DEBUGINFO_FILE_NAME}") - list(APPEND filenames_ "${CPACK_RPM_DEBUGINFO_FILE_NAME}") - endif() - endif() - - # check if other files have to be renamed - file(GLOB rename_files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.rpm_name") - if(rename_files_) - foreach(f_ IN LISTS rename_files_) - file(READ "${f_}" tmp_) - list(GET tmp_ 0 efn_) - list(APPEND expected_filenames_ "${efn_}") - list(GET tmp_ 1 fn_) - list(APPEND filenames_ "${fn_}") - endforeach() - endif() - - if(expected_filenames_) - foreach(F IN LISTS GENERATED_FILES) - unset(matched_) - foreach(expected_ IN LISTS expected_filenames_) - if(F MATCHES ".*/${expected_}") - list(FIND expected_filenames_ "${expected_}" idx_) - list(GET filenames_ ${idx_} filename_) - get_filename_component(FILE_PATH "${F}" DIRECTORY) - file(RENAME "${F}" "${FILE_PATH}/${filename_}") - list(APPEND new_files_list_ "${FILE_PATH}/${filename_}") - set(matched_ "YES") - - break() - endif() - endforeach() - - if(NOT matched_) - list(APPEND new_files_list_ "${F}") - endif() - endforeach() - - set(GENERATED_FILES "${new_files_list_}") - endif() - endif() - - set(GEN_CPACK_OUTPUT_FILES "${GENERATED_FILES}" PARENT_SCOPE) - - if(CPACK_RPM_PACKAGE_DEBUG) - message("CPackRPM:Debug: GEN_CPACK_OUTPUT_FILES = ${GENERATED_FILES}") - endif() -endfunction() - -cpack_rpm_generate_package() diff --git a/Modules/CPackWIX.cmake b/Modules/CPackWIX.cmake deleted file mode 100644 index 27737e5..0000000 --- a/Modules/CPackWIX.cmake +++ /dev/null @@ -1,307 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - -#.rst: -# CPackWIX -# -------- -# -# CPack WiX generator specific options -# -# Variables specific to CPack WiX generator -# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -# -# The following variables are specific to the installers built on -# Windows using WiX. -# -# .. variable:: CPACK_WIX_UPGRADE_GUID -# -# Upgrade GUID (``Product/@UpgradeCode``) -# -# Will be automatically generated unless explicitly provided. -# -# It should be explicitly set to a constant generated globally unique -# identifier (GUID) to allow your installers to replace existing -# installations that use the same GUID. -# -# You may for example explicitly set this variable in your -# CMakeLists.txt to the value that has been generated per default. You -# should not use GUIDs that you did not generate yourself or which may -# belong to other projects. -# -# A GUID shall have the following fixed length syntax:: -# -# XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX -# -# (each X represents an uppercase hexadecimal digit) -# -# .. variable:: CPACK_WIX_PRODUCT_GUID -# -# Product GUID (``Product/@Id``) -# -# Will be automatically generated unless explicitly provided. -# -# If explicitly provided this will set the Product Id of your installer. -# -# The installer will abort if it detects a pre-existing installation that -# uses the same GUID. -# -# The GUID shall use the syntax described for CPACK_WIX_UPGRADE_GUID. -# -# .. variable:: CPACK_WIX_LICENSE_RTF -# -# RTF License File -# -# If CPACK_RESOURCE_FILE_LICENSE has an .rtf extension it is used as-is. -# -# If CPACK_RESOURCE_FILE_LICENSE has an .txt extension it is implicitly -# converted to RTF by the WiX Generator. -# The expected encoding of the .txt file is UTF-8. -# -# With CPACK_WIX_LICENSE_RTF you can override the license file used by the -# WiX Generator in case CPACK_RESOURCE_FILE_LICENSE is in an unsupported -# format or the .txt -> .rtf conversion does not work as expected. -# -# .. variable:: CPACK_WIX_PRODUCT_ICON -# -# The Icon shown next to the program name in Add/Remove programs. -# -# If set, this icon is used in place of the default icon. -# -# .. variable:: CPACK_WIX_UI_REF -# -# This variable allows you to override the Id of the ```` element -# in the WiX template. -# -# The default is ``WixUI_InstallDir`` in case no CPack components have -# been defined and ``WixUI_FeatureTree`` otherwise. -# -# .. variable:: CPACK_WIX_UI_BANNER -# -# The bitmap will appear at the top of all installer pages other than the -# welcome and completion dialogs. -# -# If set, this image will replace the default banner image. -# -# This image must be 493 by 58 pixels. -# -# .. variable:: CPACK_WIX_UI_DIALOG -# -# Background bitmap used on the welcome and completion dialogs. -# -# If this variable is set, the installer will replace the default dialog -# image. -# -# This image must be 493 by 312 pixels. -# -# .. variable:: CPACK_WIX_PROGRAM_MENU_FOLDER -# -# Start menu folder name for launcher. -# -# If this variable is not set, it will be initialized with CPACK_PACKAGE_NAME -# -# .. variable:: CPACK_WIX_CULTURES -# -# Language(s) of the installer -# -# Languages are compiled into the WixUI extension library. To use them, -# simply provide the name of the culture. If you specify more than one -# culture identifier in a comma or semicolon delimited list, the first one -# that is found will be used. You can find a list of supported languages at: -# http://wix.sourceforge.net/manual-wix3/WixUI_localization.htm -# -# .. variable:: CPACK_WIX_TEMPLATE -# -# Template file for WiX generation -# -# If this variable is set, the specified template will be used to generate -# the WiX wxs file. This should be used if further customization of the -# output is required. -# -# If this variable is not set, the default MSI template included with CMake -# will be used. -# -# .. variable:: CPACK_WIX_PATCH_FILE -# -# Optional list of XML files with fragments to be inserted into -# generated WiX sources -# -# This optional variable can be used to specify an XML file that the -# WiX generator will use to inject fragments into its generated -# source files. -# -# Patch files understood by the CPack WiX generator -# roughly follow this RELAX NG compact schema: -# -# .. code-block:: none -# -# start = CPackWiXPatch -# -# CPackWiXPatch = element CPackWiXPatch { CPackWiXFragment* } -# -# CPackWiXFragment = element CPackWiXFragment -# { -# attribute Id { string }, -# fragmentContent* -# } -# -# fragmentContent = element * - CPackWiXFragment -# { -# (attribute * { text } | text | fragmentContent)* -# } -# -# Currently fragments can be injected into most -# Component, File, Directory and Feature elements. -# -# The following additional special Ids can be used: -# -# * ``#PRODUCT`` for the ```` element. -# * ``#PRODUCTFEATURE`` for the root ```` element. -# -# The following example illustrates how this works. -# -# Given that the WiX generator creates the following XML element: -# -# .. code-block:: xml -# -# -# -# The following XML patch file may be used to inject an Environment element -# into it: -# -# .. code-block:: xml -# -# -# -# -# -# -# -# .. variable:: CPACK_WIX_EXTRA_SOURCES -# -# Extra WiX source files -# -# This variable provides an optional list of extra WiX source files (.wxs) -# that should be compiled and linked. The full path to source files is -# required. -# -# .. variable:: CPACK_WIX_EXTRA_OBJECTS -# -# Extra WiX object files or libraries -# -# This variable provides an optional list of extra WiX object (.wixobj) -# and/or WiX library (.wixlib) files. The full path to objects and libraries -# is required. -# -# .. variable:: CPACK_WIX_EXTENSIONS -# -# This variable provides a list of additional extensions for the WiX -# tools light and candle. -# -# .. variable:: CPACK_WIX__EXTENSIONS -# -# This is the tool specific version of CPACK_WIX_EXTENSIONS. -# ```` can be either LIGHT or CANDLE. -# -# .. variable:: CPACK_WIX__EXTRA_FLAGS -# -# This list variable allows you to pass additional -# flags to the WiX tool ````. -# -# Use it at your own risk. -# Future versions of CPack may generate flags which may be in conflict -# with your own flags. -# -# ```` can be either LIGHT or CANDLE. -# -# .. variable:: CPACK_WIX_CMAKE_PACKAGE_REGISTRY -# -# If this variable is set the generated installer will create -# an entry in the windows registry key -# ``HKEY_LOCAL_MACHINE\Software\Kitware\CMake\Packages\`` -# The value for ```` is provided by this variable. -# -# Assuming you also install a CMake configuration file this will -# allow other CMake projects to find your package with -# the :command:`find_package` command. -# -# .. variable:: CPACK_WIX_PROPERTY_ -# -# This variable can be used to provide a value for -# the Windows Installer property ```` -# -# The following list contains some example properties that can be used to -# customize information under -# "Programs and Features" (also known as "Add or Remove Programs") -# -# * ARPCOMMENTS - Comments -# * ARPHELPLINK - Help and support information URL -# * ARPURLINFOABOUT - General information URL -# * ARPURLUPDATEINFO - Update information URL -# * ARPHELPTELEPHONE - Help and support telephone number -# * ARPSIZE - Size (in kilobytes) of the application -# -# .. variable:: CPACK_WIX_ROOT_FEATURE_TITLE -# -# Sets the name of the root install feature in the WIX installer. Same as -# CPACK_COMPONENT__DISPLAY_NAME for components. -# -# .. variable:: CPACK_WIX_ROOT_FEATURE_DESCRIPTION -# -# Sets the description of the root install feature in the WIX installer. Same as -# CPACK_COMPONENT__DESCRIPTION for components. -# -# .. variable:: CPACK_WIX_SKIP_PROGRAM_FOLDER -# -# If this variable is set to true, the default install location -# of the generated package will be CPACK_PACKAGE_INSTALL_DIRECTORY directly. -# The install location will not be located relatively below -# ProgramFiles or ProgramFiles64. -# -# .. note:: -# Installers created with this feature do not take differences -# between the system on which the installer is created -# and the system on which the installer might be used into account. -# -# It is therefore possible that the installer e.g. might try to install -# onto a drive that is unavailable or unintended or a path that does not -# follow the localization or convention of the system on which the -# installation is performed. -# -# .. variable:: CPACK_WIX_ROOT_FOLDER_ID -# -# This variable allows specification of a custom root folder ID. -# The generator specific ``<64>`` token can be used for -# folder IDs that come in 32-bit and 64-bit variants. -# In 32-bit builds the token will expand empty while in 64-bit builds -# it will expand to ``64``. -# -# When unset generated installers will default installing to -# ``ProgramFiles<64>Folder``. -# -# .. variable:: CPACK_WIX_ROOT -# -# This variable can optionally be set to the root directory -# of a custom WiX Toolset installation. -# -# When unspecified CPack will try to locate a WiX Toolset -# installation via the ``WIX`` environment variable instead. -# - -if(NOT CPACK_WIX_ROOT) - string(REPLACE "\\" "/" CPACK_WIX_ROOT "$ENV{WIX}") -endif() - -find_program(CPACK_WIX_CANDLE_EXECUTABLE candle - PATHS "${CPACK_WIX_ROOT}" PATH_SUFFIXES "bin") - -if(NOT CPACK_WIX_CANDLE_EXECUTABLE) - message(FATAL_ERROR "Could not find the WiX candle executable.") -endif() - -find_program(CPACK_WIX_LIGHT_EXECUTABLE light - PATHS "${CPACK_WIX_ROOT}" PATH_SUFFIXES "bin") - -if(NOT CPACK_WIX_LIGHT_EXECUTABLE) - message(FATAL_ERROR "Could not find the WiX light executable.") -endif() diff --git a/Modules/CPackZIP.cmake b/Modules/CPackZIP.cmake deleted file mode 100644 index 376520c..0000000 --- a/Modules/CPackZIP.cmake +++ /dev/null @@ -1,31 +0,0 @@ -# Distributed under the OSI-approved BSD 3-Clause License. See accompanying -# file Copyright.txt or https://cmake.org/licensing for details. - - -if(CMAKE_BINARY_DIR) - message(FATAL_ERROR "CPackZIP.cmake may only be used by CPack internally.") -endif() - -find_program(ZIP_EXECUTABLE wzzip PATHS "$ENV{ProgramFiles}/WinZip") -if(ZIP_EXECUTABLE) - set(CPACK_ZIP_COMMAND "\"${ZIP_EXECUTABLE}\" -P \"\" @") - set(CPACK_ZIP_NEED_QUOTES TRUE) -endif() - -if(NOT ZIP_EXECUTABLE) - find_program(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip") - if(ZIP_EXECUTABLE) - set(CPACK_ZIP_COMMAND "\"${ZIP_EXECUTABLE}\" a -tzip \"\" @") - set(CPACK_ZIP_NEED_QUOTES TRUE) - endif() -endif() - -if(NOT ZIP_EXECUTABLE) - find_package(Cygwin) - find_program(ZIP_EXECUTABLE zip PATHS "${CYGWIN_INSTALL_PATH}/bin") - if(ZIP_EXECUTABLE) - set(CPACK_ZIP_COMMAND "\"${ZIP_EXECUTABLE}\" -r \"\" . -i@") - set(CPACK_ZIP_NEED_QUOTES FALSE) - endif() -endif() - diff --git a/Modules/Internal/CPack/CPackDeb.cmake b/Modules/Internal/CPack/CPackDeb.cmake new file mode 100644 index 0000000..4ef4539 --- /dev/null +++ b/Modules/Internal/CPack/CPackDeb.cmake @@ -0,0 +1,581 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# CPack script for creating Debian package +# Author: Mathieu Malaterre +# +# http://wiki.debian.org/HowToPackageForDebian + +if(CMAKE_BINARY_DIR) + message(FATAL_ERROR "CPackDeb.cmake may only be used by CPack internally.") +endif() + +function(cpack_deb_variable_fallback OUTPUT_VAR_NAME) + set(FALLBACK_VAR_NAMES ${ARGN}) + + foreach(variable_name IN LISTS FALLBACK_VAR_NAMES) + if(${variable_name}) + set(${OUTPUT_VAR_NAME} "${${variable_name}}" PARENT_SCOPE) + break() + endif() + endforeach() +endfunction() + +function(get_component_package_name var component) + string(TOUPPER "${component}" component_upcase) + if(CPACK_DEBIAN_${component_upcase}_PACKAGE_NAME) + string(TOLOWER "${CPACK_DEBIAN_${component_upcase}_PACKAGE_NAME}" package_name) + else() + string(TOLOWER "${CPACK_DEBIAN_PACKAGE_NAME}-${component}" package_name) + endif() + + set("${var}" "${package_name}" PARENT_SCOPE) +endfunction() + +#extract library name and version for given shared object +function(extract_so_info shared_object libname version) + if(READELF_EXECUTABLE) + execute_process(COMMAND "${READELF_EXECUTABLE}" -d "${shared_object}" + WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" + RESULT_VARIABLE result + OUTPUT_VARIABLE output + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(result EQUAL 0) + string(REGEX MATCH "\\(SONAME\\)[^\n]*\\[([^\n]+)\\.so\\.([^\n]*)\\]" soname "${output}") + set(${libname} "${CMAKE_MATCH_1}" PARENT_SCOPE) + set(${version} "${CMAKE_MATCH_2}" PARENT_SCOPE) + else() + message(WARNING "Error running readelf for \"${shared_object}\"") + endif() + else() + message(FATAL_ERROR "Readelf utility is not available.") + endif() +endfunction() + +function(cpack_deb_prepare_package_vars) + # CPACK_DEBIAN_PACKAGE_SHLIBDEPS + # If specify OFF, only user depends are used + if(NOT DEFINED CPACK_DEBIAN_PACKAGE_SHLIBDEPS) + set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OFF) + endif() + + set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_DEB_PACKAGE_COMPONENT_PART_PATH}") + + # per component automatic discover: some of the component might not have + # binaries. + if(CPACK_DEB_PACKAGE_COMPONENT) + string(TOUPPER "${CPACK_DEB_PACKAGE_COMPONENT}" _local_component_name) + set(_component_shlibdeps_var "CPACK_DEBIAN_${_local_component_name}_PACKAGE_SHLIBDEPS") + + # if set, overrides the global configuration + if(DEFINED ${_component_shlibdeps_var}) + set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS "${${_component_shlibdeps_var}}") + if(CPACK_DEBIAN_PACKAGE_DEBUG) + message("CPackDeb Debug: component '${CPACK_DEB_PACKAGE_COMPONENT}' dpkg-shlibdeps set to ${CPACK_DEBIAN_PACKAGE_SHLIBDEPS}") + endif() + endif() + endif() + + if(CPACK_DEBIAN_PACKAGE_SHLIBDEPS OR CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS) + # Generating binary list - Get type of all install files + file(GLOB_RECURSE FILE_PATHS_ LIST_DIRECTORIES false RELATIVE "${WDIR}" "${WDIR}/*") + + find_program(FILE_EXECUTABLE file) + if(NOT FILE_EXECUTABLE) + message(FATAL_ERROR "CPackDeb: file utility is not available. CPACK_DEBIAN_PACKAGE_SHLIBDEPS and CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS options are not available.") + endif() + + # get file info so that we can determine if file is executable or not + unset(CPACK_DEB_INSTALL_FILES) + foreach(FILE_ IN LISTS FILE_PATHS_) + execute_process(COMMAND env LC_ALL=C ${FILE_EXECUTABLE} "./${FILE_}" + WORKING_DIRECTORY "${WDIR}" + RESULT_VARIABLE FILE_RESULT_ + OUTPUT_VARIABLE INSTALL_FILE_) + if(NOT FILE_RESULT_ EQUAL 0) + message (FATAL_ERROR "CPackDeb: execution of command: '${FILE_EXECUTABLE} ./${FILE_}' failed with exit code: ${FILE_RESULT_}") + endif() + list(APPEND CPACK_DEB_INSTALL_FILES "${INSTALL_FILE_}") + endforeach() + + # Only dynamically linked ELF files are included + # Extract only file name infront of ":" + foreach(_FILE IN LISTS CPACK_DEB_INSTALL_FILES) + if(_FILE MATCHES "ELF.*dynamically linked") + string(REGEX MATCH "(^.*):" _FILE_NAME "${_FILE}") + list(APPEND CPACK_DEB_BINARY_FILES "${CMAKE_MATCH_1}") + set(CONTAINS_EXECUTABLE_FILES_ TRUE) + endif() + if(_FILE MATCHES "ELF.*shared object") + string(REGEX MATCH "(^.*):" _FILE_NAME "${_FILE}") + list(APPEND CPACK_DEB_SHARED_OBJECT_FILES "${CMAKE_MATCH_1}") + endif() + endforeach() + endif() + + if(CPACK_DEBIAN_PACKAGE_SHLIBDEPS) + # dpkg-shlibdeps is a Debian utility for generating dependency list + find_program(SHLIBDEPS_EXECUTABLE dpkg-shlibdeps) + + if(SHLIBDEPS_EXECUTABLE) + # Check version of the dpkg-shlibdeps tool using CPackDEB method + execute_process(COMMAND env LC_ALL=C ${SHLIBDEPS_EXECUTABLE} --version + OUTPUT_VARIABLE _TMP_VERSION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(_TMP_VERSION MATCHES "dpkg-shlibdeps version ([0-9]+\\.[0-9]+\\.[0-9]+)") + set(SHLIBDEPS_EXECUTABLE_VERSION "${CMAKE_MATCH_1}") + else() + set(SHLIBDEPS_EXECUTABLE_VERSION "") + endif() + + if(CPACK_DEBIAN_PACKAGE_DEBUG) + message("CPackDeb Debug: dpkg-shlibdeps --version output is '${_TMP_VERSION}'") + message("CPackDeb Debug: dpkg-shlibdeps version is <${SHLIBDEPS_EXECUTABLE_VERSION}>") + endif() + + if(CONTAINS_EXECUTABLE_FILES_) + message("CPackDeb: - Generating dependency list") + + # Create blank control file for running dpkg-shlibdeps + # There might be some other way to invoke dpkg-shlibdeps without creating this file + # but standard debian package should not have anything that can collide with this file or directory + file(MAKE_DIRECTORY ${CPACK_TEMPORARY_DIRECTORY}/debian) + file(WRITE ${CPACK_TEMPORARY_DIRECTORY}/debian/control "") + + # Create a DEBIAN directory so that dpkg-shlibdeps can find the package dir when resolving $ORIGIN. + file(MAKE_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}/DEBIAN") + + # Add --ignore-missing-info if the tool supports it + execute_process(COMMAND env LC_ALL=C ${SHLIBDEPS_EXECUTABLE} --help + OUTPUT_VARIABLE _TMP_HELP + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + if(_TMP_HELP MATCHES "--ignore-missing-info") + set(IGNORE_MISSING_INFO_FLAG "--ignore-missing-info") + endif() + + # Execute dpkg-shlibdeps + # --ignore-missing-info : allow dpkg-shlibdeps to run even if some libs do not belong to a package + # -O : print to STDOUT + execute_process(COMMAND ${SHLIBDEPS_EXECUTABLE} ${IGNORE_MISSING_INFO_FLAG} -O ${CPACK_DEB_BINARY_FILES} + WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" + OUTPUT_VARIABLE SHLIBDEPS_OUTPUT + RESULT_VARIABLE SHLIBDEPS_RESULT + ERROR_VARIABLE SHLIBDEPS_ERROR + OUTPUT_STRIP_TRAILING_WHITESPACE ) + if(CPACK_DEBIAN_PACKAGE_DEBUG) + # dpkg-shlibdeps will throw some warnings if some input files are not binary + message( "CPackDeb Debug: dpkg-shlibdeps warnings \n${SHLIBDEPS_ERROR}") + endif() + if(NOT SHLIBDEPS_RESULT EQUAL 0) + message (FATAL_ERROR "CPackDeb: dpkg-shlibdeps: '${SHLIBDEPS_ERROR}';\n" + "executed command: '${SHLIBDEPS_EXECUTABLE} ${IGNORE_MISSING_INFO_FLAG} -O ${CPACK_DEB_BINARY_FILES}';\n" + "found files: '${INSTALL_FILE_}';\n" + "files info: '${CPACK_DEB_INSTALL_FILES}';\n" + "binary files: '${CPACK_DEB_BINARY_FILES}'") + endif() + + #Get rid of prefix generated by dpkg-shlibdeps + string(REGEX REPLACE "^.*Depends=" "" CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS "${SHLIBDEPS_OUTPUT}") + + if(CPACK_DEBIAN_PACKAGE_DEBUG) + message("CPackDeb Debug: Found dependency: ${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS} from output ${SHLIBDEPS_OUTPUT}") + endif() + + # Remove blank control file + # Might not be safe if package actual contain file or directory named debian + file(REMOVE_RECURSE "${CPACK_TEMPORARY_DIRECTORY}/debian") + + # remove temporary directory that was created only for dpkg-shlibdeps execution + file(REMOVE_RECURSE "${CPACK_TEMPORARY_DIRECTORY}/DEBIAN") + else() + if(CPACK_DEBIAN_PACKAGE_DEBUG) + message(AUTHOR_WARNING "CPackDeb Debug: Using only user-provided depends because package does not contain executable files that link to shared libraries.") + endif() + endif() + else() + message("CPackDeb: Using only user-provided dependencies because dpkg-shlibdeps is not found.") + endif() + + else() + if(CPACK_DEBIAN_PACKAGE_DEBUG) + message("CPackDeb Debug: Using only user-provided dependencies") + endif() + endif() + + # Let's define the control file found in debian package: + + # Binary package: + # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles + + # DEBIAN/control + # debian policy enforce lower case for package name + # Package: (mandatory) + if(NOT CPACK_DEBIAN_PACKAGE_NAME) + string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME) + endif() + + # Version: (mandatory) + if(NOT CPACK_DEBIAN_PACKAGE_VERSION) + if(NOT CPACK_PACKAGE_VERSION) + message(FATAL_ERROR "CPackDeb: Debian package requires a package version") + endif() + set(CPACK_DEBIAN_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}) + endif() + + if(DEFINED CPACK_DEBIAN_PACKAGE_RELEASE OR DEFINED CPACK_DEBIAN_PACKAGE_EPOCH) + # only test the version format if CPACK_DEBIAN_PACKAGE_RELEASE or + # CPACK_DEBIAN_PACKAGE_EPOCH is set + if(NOT CPACK_DEBIAN_PACKAGE_VERSION MATCHES "^[0-9][A-Za-z0-9.+~-]*$") + message(FATAL_ERROR + "CPackDeb: Debian package version must confirm to \"^[0-9][A-Za-z0-9.+~-]*$\" regex!") + endif() + else() + # before CMake 3.10 version format was not tested so only warn to preserve + # backward compatibility + if(NOT CPACK_DEBIAN_PACKAGE_VERSION MATCHES "^([0-9]+:)?[0-9][A-Za-z0-9.+~-]*$") + message(AUTHOR_WARNING + "CPackDeb: Debian package versioning ([:][-])" + " should confirm to \"^([0-9]+:)?[0-9][A-Za-z0-9.+~-]*$\" regex in" + " order to satisfy Debian packaging rules.") + endif() + endif() + + if(CPACK_DEBIAN_PACKAGE_RELEASE) + if(NOT CPACK_DEBIAN_PACKAGE_RELEASE MATCHES "^[A-Za-z0-9.+~]+$") + message(FATAL_ERROR + "CPackDeb: Debian package release must confirm to \"^[A-Za-z0-9.+~]+$\" regex!") + endif() + string(APPEND CPACK_DEBIAN_PACKAGE_VERSION + "-${CPACK_DEBIAN_PACKAGE_RELEASE}") + elseif(DEFINED CPACK_DEBIAN_PACKAGE_EPOCH) + # only test the version format if CPACK_DEBIAN_PACKAGE_RELEASE or + # CPACK_DEBIAN_PACKAGE_EPOCH is set - versions CPack/Deb generator before + # CMake 3.10 did not check for version format so we have to preserve + # backward compatibility + if(CPACK_DEBIAN_PACKAGE_VERSION MATCHES ".*-.*") + message(FATAL_ERROR + "CPackDeb: Debian package version must not contain hyphens when CPACK_DEBIAN_PACKAGE_RELEASE is not provided!") + endif() + endif() + + if(CPACK_DEBIAN_PACKAGE_EPOCH) + if(NOT CPACK_DEBIAN_PACKAGE_EPOCH MATCHES "^[0-9]+$") + message(FATAL_ERROR + "CPackDeb: Debian package epoch must confirm to \"^[0-9]+$\" regex!") + endif() + set(CPACK_DEBIAN_PACKAGE_VERSION + "${CPACK_DEBIAN_PACKAGE_EPOCH}:${CPACK_DEBIAN_PACKAGE_VERSION}") + endif() + + # Architecture: (mandatory) + if(CPACK_DEB_PACKAGE_COMPONENT AND CPACK_DEBIAN_${_local_component_name}_PACKAGE_ARCHITECTURE) + set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CPACK_DEBIAN_${_local_component_name}_PACKAGE_ARCHITECTURE}") + elseif(NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE) + # There is no such thing as i686 architecture on debian, you should use i386 instead + # $ dpkg --print-architecture + find_program(DPKG_CMD dpkg) + if(NOT DPKG_CMD) + message(STATUS "CPackDeb: Can not find dpkg in your path, default to i386.") + set(CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386) + endif() + execute_process(COMMAND "${DPKG_CMD}" --print-architecture + OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE + OUTPUT_STRIP_TRAILING_WHITESPACE + ) + endif() + + # Source: (optional) + # in case several packages are constructed from a unique source + # (multipackaging), the source may be indicated as well. + # The source might contain a version if the generated package + # version is different from the source version + if(NOT CPACK_DEBIAN_PACKAGE_SOURCE) + set(CPACK_DEBIAN_PACKAGE_SOURCE "") + endif() + + # have a look at get_property(result GLOBAL PROPERTY ENABLED_FEATURES), + # this returns the successful find_package() calls, maybe this can help + # Depends: + # You should set: DEBIAN_PACKAGE_DEPENDS + # TODO: automate 'objdump -p | grep NEEDED' + + # if per-component variable, overrides the global CPACK_DEBIAN_PACKAGE_${variable_type_} + # automatic dependency discovery will be performed afterwards. + if(CPACK_DEB_PACKAGE_COMPONENT) + foreach(value_type_ DEPENDS RECOMMENDS SUGGESTS PREDEPENDS ENHANCES BREAKS CONFLICTS PROVIDES REPLACES SOURCE SECTION PRIORITY NAME) + set(_component_var "CPACK_DEBIAN_${_local_component_name}_PACKAGE_${value_type_}") + + # if set, overrides the global variable + if(DEFINED ${_component_var}) + set(CPACK_DEBIAN_PACKAGE_${value_type_} "${${_component_var}}") + if(CPACK_DEBIAN_PACKAGE_DEBUG) + message("CPackDeb Debug: component '${_local_component_name}' ${value_type_} " + "value set to '${CPACK_DEBIAN_PACKAGE_${value_type_}}'") + endif() + endif() + endforeach() + + if(CPACK_DEBIAN_ENABLE_COMPONENT_DEPENDS) + set(COMPONENT_DEPENDS "") + foreach (_PACK ${CPACK_COMPONENT_${_local_component_name}_DEPENDS}) + get_component_package_name(_PACK_NAME "${_PACK}") + if(COMPONENT_DEPENDS) + set(COMPONENT_DEPENDS "${_PACK_NAME} (= ${CPACK_DEBIAN_PACKAGE_VERSION}), ${COMPONENT_DEPENDS}") + else() + set(COMPONENT_DEPENDS "${_PACK_NAME} (= ${CPACK_DEBIAN_PACKAGE_VERSION})") + endif() + endforeach() + if(COMPONENT_DEPENDS) + if(CPACK_DEBIAN_PACKAGE_DEPENDS) + set(CPACK_DEBIAN_PACKAGE_DEPENDS "${COMPONENT_DEPENDS}, ${CPACK_DEBIAN_PACKAGE_DEPENDS}") + else() + set(CPACK_DEBIAN_PACKAGE_DEPENDS "${COMPONENT_DEPENDS}") + endif() + endif() + endif() + endif() + + # at this point, the CPACK_DEBIAN_PACKAGE_DEPENDS is properly set + # to the minimal dependency of the package + # Append automatically discovered dependencies . + if(NOT "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}" STREQUAL "") + if (CPACK_DEBIAN_PACKAGE_DEPENDS) + set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}, ${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}") + else () + set (CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}") + endif () + endif() + + if(NOT CPACK_DEBIAN_PACKAGE_DEPENDS) + message(STATUS "CPACK_DEBIAN_PACKAGE_DEPENDS not set, the package will have no dependencies.") + endif() + + # Maintainer: (mandatory) + if(NOT CPACK_DEBIAN_PACKAGE_MAINTAINER) + if(NOT CPACK_PACKAGE_CONTACT) + message(FATAL_ERROR "CPackDeb: Debian package requires a maintainer for a package, set CPACK_PACKAGE_CONTACT or CPACK_DEBIAN_PACKAGE_MAINTAINER") + endif() + set(CPACK_DEBIAN_PACKAGE_MAINTAINER ${CPACK_PACKAGE_CONTACT}) + endif() + + # Description: (mandatory) + if(NOT CPACK_DEB_PACKAGE_COMPONENT) + if(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION) + if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY) + message(FATAL_ERROR "CPackDeb: Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION") + endif() + set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}) + endif() + else() + set(component_description_var CPACK_COMPONENT_${_local_component_name}_DESCRIPTION) + + # component description overrides package description + if(${component_description_var}) + set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${${component_description_var}}) + elseif(NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION) + if(NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY) + message(FATAL_ERROR "CPackDeb: Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION or ${component_description_var}") + endif() + set(CPACK_DEBIAN_PACKAGE_DESCRIPTION ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}) + endif() + endif() + + # Homepage: (optional) + if(NOT CPACK_DEBIAN_PACKAGE_HOMEPAGE AND CMAKE_PROJECT_HOMEPAGE_URL) + set(CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CMAKE_PROJECT_HOMEPAGE_URL}") + endif() + + # Section: (recommended) + if(NOT CPACK_DEBIAN_PACKAGE_SECTION) + set(CPACK_DEBIAN_PACKAGE_SECTION "devel") + endif() + + # Priority: (recommended) + if(NOT CPACK_DEBIAN_PACKAGE_PRIORITY) + set(CPACK_DEBIAN_PACKAGE_PRIORITY "optional") + endif() + + if(CPACK_DEBIAN_ARCHIVE_TYPE) + set(archive_types_ "paxr;gnutar") + if(NOT CPACK_DEBIAN_ARCHIVE_TYPE IN_LIST archive_types_) + message(FATAL_ERROR "CPACK_DEBIAN_ARCHIVE_TYPE set to unsupported" + "type ${CPACK_DEBIAN_ARCHIVE_TYPE}") + endif() + else() + set(CPACK_DEBIAN_ARCHIVE_TYPE "paxr") + endif() + + # Compression: (recommended) + if(NOT CPACK_DEBIAN_COMPRESSION_TYPE) + set(CPACK_DEBIAN_COMPRESSION_TYPE "gzip") + endif() + + # Recommends: + # You should set: CPACK_DEBIAN_PACKAGE_RECOMMENDS + + # Suggests: + # You should set: CPACK_DEBIAN_PACKAGE_SUGGESTS + + # CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA + # This variable allow advanced user to add custom script to the control.tar.gz (inside the .deb archive) + # Typical examples are: + # - conffiles + # - postinst + # - postrm + # - prerm + # Usage: + # set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA + # "${CMAKE_CURRENT_SOURCE_DIR}/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm") + + # Are we packaging components ? + if(CPACK_DEB_PACKAGE_COMPONENT) + # override values with per component version if set + foreach(VAR_NAME_ "PACKAGE_CONTROL_EXTRA" "PACKAGE_CONTROL_STRICT_PERMISSION") + if(CPACK_DEBIAN_${_local_component_name}_${VAR_NAME_}) + set(CPACK_DEBIAN_${VAR_NAME_} "${CPACK_DEBIAN_${_local_component_name}_${VAR_NAME_}}") + endif() + endforeach() + get_component_package_name(CPACK_DEBIAN_PACKAGE_NAME ${_local_component_name}) + endif() + + set(CPACK_DEBIAN_PACKAGE_SHLIBS_LIST "") + + if (NOT CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY) + set(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY "=") + endif() + + find_program(READELF_EXECUTABLE NAMES readelf) + + if(CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS) + if(READELF_EXECUTABLE) + foreach(_FILE IN LISTS CPACK_DEB_SHARED_OBJECT_FILES) + extract_so_info("${_FILE}" libname soversion) + if(libname AND DEFINED soversion) + list(APPEND CPACK_DEBIAN_PACKAGE_SHLIBS_LIST + "${libname} ${soversion} ${CPACK_DEBIAN_PACKAGE_NAME} (${CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS_POLICY} ${CPACK_DEBIAN_PACKAGE_VERSION})") + else() + message(AUTHOR_WARNING "Shared library '${_FILE}' is missing soname or soversion. Library will not be added to DEBIAN/shlibs control file.") + endif() + endforeach() + if (CPACK_DEBIAN_PACKAGE_SHLIBS_LIST) + string(REPLACE ";" "\n" CPACK_DEBIAN_PACKAGE_SHLIBS_LIST "${CPACK_DEBIAN_PACKAGE_SHLIBS_LIST}") + endif() + else() + message(FATAL_ERROR "Readelf utility is not available. CPACK_DEBIAN_PACKAGE_GENERATE_SHLIBS option is not available.") + endif() + endif() + + # add ldconfig call in default postrm and postint + set(CPACK_ADD_LDCONFIG_CALL 0) + foreach(_FILE ${CPACK_DEB_SHARED_OBJECT_FILES}) + get_filename_component(_DIR ${_FILE} DIRECTORY) + # all files in CPACK_DEB_SHARED_OBJECT_FILES have dot at the beginning + if(_DIR STREQUAL "./lib" OR _DIR STREQUAL "./usr/lib") + set(CPACK_ADD_LDCONFIG_CALL 1) + endif() + endforeach() + + if(CPACK_ADD_LDCONFIG_CALL) + set(CPACK_DEBIAN_GENERATE_POSTINST 1) + set(CPACK_DEBIAN_GENERATE_POSTRM 1) + foreach(f ${PACKAGE_CONTROL_EXTRA}) + get_filename_component(n "${f}" NAME) + if("${n}" STREQUAL "postinst") + set(CPACK_DEBIAN_GENERATE_POSTINST 0) + endif() + if("${n}" STREQUAL "postrm") + set(CPACK_DEBIAN_GENERATE_POSTRM 0) + endif() + endforeach() + else() + set(CPACK_DEBIAN_GENERATE_POSTINST 0) + set(CPACK_DEBIAN_GENERATE_POSTRM 0) + endif() + + cpack_deb_variable_fallback("CPACK_DEBIAN_FILE_NAME" + "CPACK_DEBIAN_${_local_component_name}_FILE_NAME" + "CPACK_DEBIAN_FILE_NAME") + if(CPACK_DEBIAN_FILE_NAME) + if(CPACK_DEBIAN_FILE_NAME STREQUAL "DEB-DEFAULT") + # Patch package file name to be in correct debian format: + # _-_.deb + set(CPACK_OUTPUT_FILE_NAME + "${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}.deb") + else() + if(NOT CPACK_DEBIAN_FILE_NAME MATCHES ".*\\.(deb|ipk)") + message(FATAL_ERROR "'${CPACK_DEBIAN_FILE_NAME}' is not a valid DEB package file name as it must end with '.deb' or '.ipk'!") + endif() + + set(CPACK_OUTPUT_FILE_NAME "${CPACK_DEBIAN_FILE_NAME}") + endif() + + set(CPACK_TEMPORARY_PACKAGE_FILE_NAME "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_OUTPUT_FILE_NAME}") + get_filename_component(BINARY_DIR "${CPACK_OUTPUT_FILE_PATH}" DIRECTORY) + set(CPACK_OUTPUT_FILE_PATH "${BINARY_DIR}/${CPACK_OUTPUT_FILE_NAME}") + endif() # else() back compatibility - don't change the name + + # Print out some debug information if we were asked for that + if(CPACK_DEBIAN_PACKAGE_DEBUG) + message("CPackDeb:Debug: CPACK_TOPLEVEL_DIRECTORY = '${CPACK_TOPLEVEL_DIRECTORY}'") + message("CPackDeb:Debug: CPACK_TOPLEVEL_TAG = '${CPACK_TOPLEVEL_TAG}'") + message("CPackDeb:Debug: CPACK_TEMPORARY_DIRECTORY = '${CPACK_TEMPORARY_DIRECTORY}'") + message("CPackDeb:Debug: CPACK_OUTPUT_FILE_NAME = '${CPACK_OUTPUT_FILE_NAME}'") + message("CPackDeb:Debug: CPACK_OUTPUT_FILE_PATH = '${CPACK_OUTPUT_FILE_PATH}'") + message("CPackDeb:Debug: CPACK_PACKAGE_FILE_NAME = '${CPACK_PACKAGE_FILE_NAME}'") + message("CPackDeb:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = '${CPACK_PACKAGE_INSTALL_DIRECTORY}'") + message("CPackDeb:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = '${CPACK_TEMPORARY_PACKAGE_FILE_NAME}'") + message("CPackDeb:Debug: CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION = '${CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION}'") + message("CPackDeb:Debug: CPACK_DEBIAN_PACKAGE_SOURCE = '${CPACK_DEBIAN_PACKAGE_SOURCE}'") + endif() + + # For debian source packages: + # debian/control + # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-sourcecontrolfiles + + # .dsc + # http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-debiansourcecontrolfiles + + # Builds-Depends: + #if(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS) + # set(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS + # "debhelper (>> 5.0.0), libncurses5-dev, tcl8.4" + # ) + #endif() + + # move variables to parent scope so that they may be used to create debian package + set(GEN_CPACK_OUTPUT_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}" PARENT_SCOPE) + set(GEN_CPACK_TEMPORARY_PACKAGE_FILE_NAME "${CPACK_TEMPORARY_PACKAGE_FILE_NAME}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_NAME "${CPACK_DEBIAN_PACKAGE_NAME}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_VERSION "${CPACK_DEBIAN_PACKAGE_VERSION}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_SECTION "${CPACK_DEBIAN_PACKAGE_SECTION}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_PRIORITY "${CPACK_DEBIAN_PACKAGE_PRIORITY}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_ARCHITECTURE "${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_MAINTAINER "${CPACK_DEBIAN_PACKAGE_MAINTAINER}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_DESCRIPTION "${CPACK_DEBIAN_PACKAGE_DESCRIPTION}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_DEPENDS}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_ARCHIVE_TYPE "${CPACK_DEBIAN_ARCHIVE_TYPE}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_COMPRESSION_TYPE "${CPACK_DEBIAN_COMPRESSION_TYPE}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_RECOMMENDS "${CPACK_DEBIAN_PACKAGE_RECOMMENDS}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_SUGGESTS "${CPACK_DEBIAN_PACKAGE_SUGGESTS}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_HOMEPAGE "${CPACK_DEBIAN_PACKAGE_HOMEPAGE}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_PREDEPENDS "${CPACK_DEBIAN_PACKAGE_PREDEPENDS}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_ENHANCES "${CPACK_DEBIAN_PACKAGE_ENHANCES}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_BREAKS "${CPACK_DEBIAN_PACKAGE_BREAKS}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_CONFLICTS "${CPACK_DEBIAN_PACKAGE_CONFLICTS}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_PROVIDES "${CPACK_DEBIAN_PACKAGE_PROVIDES}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_REPLACES "${CPACK_DEBIAN_PACKAGE_REPLACES}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_SHLIBS "${CPACK_DEBIAN_PACKAGE_SHLIBS_LIST}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "${CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION + "${CPACK_DEBIAN_PACKAGE_CONTROL_STRICT_PERMISSION}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_PACKAGE_SOURCE + "${CPACK_DEBIAN_PACKAGE_SOURCE}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_GENERATE_POSTINST "${CPACK_DEBIAN_GENERATE_POSTINST}" PARENT_SCOPE) + set(GEN_CPACK_DEBIAN_GENERATE_POSTRM "${CPACK_DEBIAN_GENERATE_POSTRM}" PARENT_SCOPE) + set(GEN_WDIR "${WDIR}" PARENT_SCOPE) +endfunction() + +cpack_deb_prepare_package_vars() diff --git a/Modules/Internal/CPack/CPackFreeBSD.cmake b/Modules/Internal/CPack/CPackFreeBSD.cmake new file mode 100644 index 0000000..16f906c --- /dev/null +++ b/Modules/Internal/CPack/CPackFreeBSD.cmake @@ -0,0 +1,107 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + + +if(CMAKE_BINARY_DIR) + message(FATAL_ERROR "CPackFreeBSD.cmake may only be used by CPack internally.") +endif() + +if(NOT UNIX) + message(FATAL_ERROR "CPackFreeBSD.cmake may only be used under UNIX.") +endif() + + +### +# +# These bits are copied from the Debian packaging file; slightly modified. +# They are used for filling in FreeBSD-packaging variables that can take +# on values from elsewhere -- e.g. the package description may as well be +# copied from Debian. +# +function(_cpack_freebsd_fallback_var OUTPUT_VAR_NAME) + set(FALLBACK_VAR_NAMES ${ARGN}) + + set(VALUE "${${OUTPUT_VAR_NAME}}") + if(VALUE) + return() + endif() + + foreach(variable_name IN LISTS FALLBACK_VAR_NAMES) + if(${variable_name}) + set(${OUTPUT_VAR_NAME} "${${variable_name}}" PARENT_SCOPE) + set(VALUE "${${variable_name}}") + break() + endif() + endforeach() + if(NOT VALUE) + message(WARNING "Variable ${OUTPUT_VAR_NAME} could not be given a fallback value from any variable ${FALLBACK_VAR_NAMES}.") + endif() +endfunction() + +function(check_required_var VAR_NAME) + if(NOT ${VAR_NAME}) + message(FATAL_ERROR "Variable ${VAR_NAME} is not set.") + endif() +endfunction() + +set(_cpack_freebsd_fallback_origin "misc/bogus") + +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_NAME" + "CPACK_PACKAGE_NAME" + "CMAKE_PROJECT_NAME" + ) + +set(_cpack_freebsd_fallback_www "http://example.com/?pkg=${CPACK_FREEBSD_PACKAGE_NAME}") + +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_COMMENT" + "CPACK_PACKAGE_DESCRIPTION_SUMMARY" + ) + +# TODO: maybe read the PACKAGE_DESCRIPTION file for the longer +# FreeBSD pkg-descr? +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_DESCRIPTION" + "CPACK_DEBIAN_PACKAGE_DESCRIPTION" + "CPACK_PACKAGE_DESCRIPTION_SUMMARY" + "PACKAGE_DESCRIPTION" + ) + +# There's really only one homepage for a project, so +# re-use the Debian setting if it's there. +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_WWW" + "CMAKE_PROJECT_HOMEPAGE_URL" + "CPACK_DEBIAN_PACKAGE_HOMEPAGE" + "_cpack_freebsd_fallback_www" + ) + +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_VERSION" + "CMAKE_PROJECT_VERSION" + "${CMAKE_PROJECT_NAME}_VERSION" + "PROJECT_VERSION" + "CPACK_PACKAGE_VERSION" + "CPACK_PACKAGE_VERSION" + ) + +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_MAINTAINER" + "CPACK_PACKAGE_CONTACT" + ) + +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_LICENSE" + "CPACK_RPM_PACKAGE_LICENSE" + ) + +_cpack_freebsd_fallback_var("CPACK_FREEBSD_PACKAGE_ORIGIN" + "_cpack_freebsd_fallback_origin" + ) + +if(NOT CPACK_FREEBSD_PACKAGE_CATEGORIES) + string(REGEX REPLACE "/.*" "" CPACK_FREEBSD_PACKAGE_CATEGORIES ${CPACK_FREEBSD_PACKAGE_ORIGIN}) +endif() + +check_required_var("CPACK_FREEBSD_PACKAGE_NAME") +check_required_var("CPACK_FREEBSD_PACKAGE_ORIGIN") +check_required_var("CPACK_FREEBSD_PACKAGE_VERSION") +check_required_var("CPACK_FREEBSD_PACKAGE_MAINTAINER") +check_required_var("CPACK_FREEBSD_PACKAGE_COMMENT") +check_required_var("CPACK_FREEBSD_PACKAGE_DESCRIPTION") +check_required_var("CPACK_FREEBSD_PACKAGE_WWW") +check_required_var("CPACK_FREEBSD_PACKAGE_LICENSE") diff --git a/Modules/Internal/CPack/CPackNuGet.cmake b/Modules/Internal/CPack/CPackNuGet.cmake new file mode 100644 index 0000000..198ccad --- /dev/null +++ b/Modules/Internal/CPack/CPackNuGet.cmake @@ -0,0 +1,363 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# Author: Alex Turbov + +if(CMAKE_BINARY_DIR) + message(FATAL_ERROR "CPackNuGet.cmake may only be used by CPack internally.") +endif() + +function(_cpack_nuget_debug) + if(CPACK_NUGET_PACKAGE_DEBUG) + message("CPackNuGet:Debug: " ${ARGN}) + endif() +endfunction() + +function(_cpack_nuget_debug_var NAME) + if(CPACK_NUGET_PACKAGE_DEBUG) + message("CPackNuGet:Debug: ${NAME}=`${${NAME}}`") + endif() +endfunction() + +function(_cpack_nuget_variable_fallback OUTPUT_VAR_NAME NUGET_VAR_NAME) + if(ARGN) + list(JOIN ARGN "`, `" _va_args) + set(_va_args ", ARGN: `${_va_args}`") + endif() + _cpack_nuget_debug( + "_cpack_nuget_variable_fallback: " + "OUTPUT_VAR_NAME=`${OUTPUT_VAR_NAME}`, " + "NUGET_VAR_NAME=`${NUGET_VAR_NAME}`" + "${_va_args}" + ) + + set(_options USE_CDATA) + set(_one_value_args LIST_GLUE) + set(_multi_value_args FALLBACK_VARS) + cmake_parse_arguments(PARSE_ARGV 0 _args "${_options}" "${_one_value_args}" "${_multi_value_args}") + + if(CPACK_NUGET_PACKAGE_COMPONENT) + string( + TOUPPER "${CPACK_NUGET_PACKAGE_COMPONENT}" + CPACK_NUGET_PACKAGE_COMPONENT_UPPER + ) + endif() + + if(CPACK_NUGET_PACKAGE_COMPONENT + AND CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT}_PACKAGE_${NUGET_VAR_NAME} + ) + set( + _result + "${CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT}_PACKAGE_${NUGET_VAR_NAME}}" + ) + _cpack_nuget_debug( + " CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT}_PACKAGE_${NUGET_VAR_NAME}: " + "OUTPUT_VAR_NAME->${OUTPUT_VAR_NAME}=`${_result}`" + ) + + elseif(CPACK_NUGET_PACKAGE_COMPONENT_UPPER + AND CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_PACKAGE_${NUGET_VAR_NAME} + ) + set( + _result + "${CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_PACKAGE_${NUGET_VAR_NAME}}" + ) + _cpack_nuget_debug( + " CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_PACKAGE_${NUGET_VAR_NAME}: " + "OUTPUT_VAR_NAME->${OUTPUT_VAR_NAME}=`${_result}`" + ) + + elseif(CPACK_NUGET_PACKAGE_${NUGET_VAR_NAME}) + set(_result "${CPACK_NUGET_PACKAGE_${NUGET_VAR_NAME}}") + _cpack_nuget_debug( + " CPACK_NUGET_PACKAGE_${NUGET_VAR_NAME}: " + "OUTPUT_VAR_NAME->${OUTPUT_VAR_NAME}=`${_result}`" + ) + + else() + foreach(_var IN LISTS _args_FALLBACK_VARS) + _cpack_nuget_debug(" Fallback: ${_var} ...") + if(${_var}) + _cpack_nuget_debug(" ${_var}=`${${_var}}`") + set(_result "${${_var}}") + _cpack_nuget_debug( + " ${_var}: OUTPUT_VAR_NAME->${OUTPUT_VAR_NAME}=`${_result}`" + ) + break() + endif() + endforeach() + endif() + + if(_result) + if(_args_USE_CDATA) + set(_value_before "") + endif() + + list(LENGTH _result _result_len) + if(_result_len GREATER 1 AND _args_LIST_GLUE) + list(JOIN _result "${_args_LIST_GLUE}" _result) + endif() + + set(${OUTPUT_VAR_NAME} "${_value_before}${_result}${_value_after}" PARENT_SCOPE) + endif() + +endfunction() + +function(_cpack_nuget_variable_fallback_and_wrap_into_element ELEMENT NUGET_VAR_NAME) + set(_options) + set(_one_value_args) + set(_multi_value_args FALLBACK_VARS) + cmake_parse_arguments(PARSE_ARGV 0 _args "${_options}" "${_one_value_args}" "${_multi_value_args}") + + _cpack_nuget_variable_fallback(_value ${NUGET_VAR_NAME} ${ARGN} USE_CDATA) + + if(_value) + string(TOUPPER "${ELEMENT}" _ELEMENT_UP) + set( + _CPACK_NUGET_${_ELEMENT_UP}_TAG + "<${ELEMENT}>${_value}" + PARENT_SCOPE + ) + endif() +endfunction() + +# Print some debug info +_cpack_nuget_debug("---[CPack NuGet Input Variables]---") +_cpack_nuget_debug_var(CPACK_PACKAGE_NAME) +_cpack_nuget_debug_var(CPACK_PACKAGE_VERSION) +_cpack_nuget_debug_var(CPACK_TOPLEVEL_TAG) +_cpack_nuget_debug_var(CPACK_TOPLEVEL_DIRECTORY) +_cpack_nuget_debug_var(CPACK_TEMPORARY_DIRECTORY) +_cpack_nuget_debug_var(CPACK_NUGET_GROUPS) +if(CPACK_NUGET_GROUPS) + foreach(_group IN LISTS CPACK_NUGET_GROUPS) + string(MAKE_C_IDENTIFIER "${_group}" _group_up) + string(TOUPPER "${_group_up}" _group_up) + _cpack_nuget_debug_var(CPACK_NUGET_${_group_up}_GROUP_COMPONENTS) + endforeach() +endif() +_cpack_nuget_debug_var(CPACK_NUGET_COMPONENTS) +_cpack_nuget_debug_var(CPACK_NUGET_ALL_IN_ONE) +_cpack_nuget_debug_var(CPACK_NUGET_ORDINAL_MONOLITIC) +_cpack_nuget_debug("-----------------------------------") + +function(_cpack_nuget_render_spec) + # Make a variable w/ upper-cased component name + if(CPACK_NUGET_PACKAGE_COMPONENT) + string(TOUPPER "${CPACK_NUGET_PACKAGE_COMPONENT}" CPACK_NUGET_PACKAGE_COMPONENT_UPPER) + endif() + + # Set mandatory variables (not wrapped into XML elements) + # https://docs.microsoft.com/en-us/nuget/reference/nuspec#required-metadata-elements + if(CPACK_NUGET_PACKAGE_COMPONENT) + if(CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_PACKAGE_NAME) + set( + CPACK_NUGET_PACKAGE_NAME + "${CPACK_NUGET_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_PACKAGE_NAME}" + ) + elseif(NOT CPACK_NUGET_PACKAGE_COMPONENT STREQUAL "Unspecified") + set( + CPACK_NUGET_PACKAGE_NAME + "${CPACK_PACKAGE_NAME}.${CPACK_NUGET_PACKAGE_COMPONENT}" + ) + else() + set(CPACK_NUGET_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") + endif() + elseif(NOT CPACK_NUGET_PACKAGE_NAME) + set(CPACK_NUGET_PACKAGE_NAME "${CPACK_PACKAGE_NAME}") + endif() + + _cpack_nuget_variable_fallback( + CPACK_NUGET_PACKAGE_VERSION VERSION + FALLBACK_VARS + CPACK_PACKAGE_VERSION + ) + _cpack_nuget_variable_fallback( + CPACK_NUGET_PACKAGE_DESCRIPTION DESCRIPTION + FALLBACK_VARS + CPACK_COMPONENT_${CPACK_NUGET_PACKAGE_COMPONENT}_DESCRIPTION + CPACK_COMPONENT_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_DESCRIPTION + CPACK_COMPONENT_GROUP_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_DESCRIPTION + CPACK_PACKAGE_DESCRIPTION + USE_CDATA + ) + _cpack_nuget_variable_fallback( + CPACK_NUGET_PACKAGE_AUTHORS AUTHORS + FALLBACK_VARS + CPACK_PACKAGE_VENDOR + USE_CDATA + LIST_GLUE "," + ) + + # Set optional variables (wrapped into XML elements) + # https://docs.microsoft.com/en-us/nuget/reference/nuspec#optional-metadata-elements + _cpack_nuget_variable_fallback_and_wrap_into_element( + title + TITLE + FALLBACK_VARS + CPACK_COMPONENT_${CPACK_NUGET_PACKAGE_COMPONENT}_DISPLAY_NAME + CPACK_COMPONENT_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_DISPLAY_NAME + CPACK_COMPONENT_GROUP_${CPACK_NUGET_PACKAGE_COMPONENT_UPPER}_DISPLAY_NAME + ) + _cpack_nuget_variable_fallback_and_wrap_into_element(owners OWNERS LIST_GLUE ",") + _cpack_nuget_variable_fallback_and_wrap_into_element( + projectUrl + HOMEPAGE_URL + FALLBACK_VARS + CPACK_PACKAGE_HOMEPAGE_URL + ) + _cpack_nuget_variable_fallback_and_wrap_into_element(licenseUrl LICENSEURL) + _cpack_nuget_variable_fallback_and_wrap_into_element(iconUrl ICONURL) + _cpack_nuget_variable_fallback_and_wrap_into_element( + summary DESCRIPTION_SUMMARY + FALLBACK_VARS + CPACK_PACKAGE_DESCRIPTION_SUMMARY + ) + if(CPACK_NUGET_PACKAGE_REQUIRE_LICENSE_ACCEPTANCE) + set( + _CPACK_NUGET_REQUIRELICENSEACCEPTANCE_TAG + "true" + ) + endif() + _cpack_nuget_variable_fallback_and_wrap_into_element(releaseNotes RELEASE_NOTES) + _cpack_nuget_variable_fallback_and_wrap_into_element(copyright COPYRIGHT) + _cpack_nuget_variable_fallback_and_wrap_into_element(tags TAGS LIST_GLUE " ") + + # Handle dependencies + _cpack_nuget_variable_fallback(_deps DEPENDENCIES) + set(_collected_deps) + foreach(_dep IN LISTS _deps) + _cpack_nuget_debug(" checking dependency `${_dep}`") + + string(MAKE_C_IDENTIFIER "${_dep}" _dep_id) + + _cpack_nuget_variable_fallback(_ver DEPENDENCIES_${_dep_id}_VERSION) + + if(NOT _ver) + string(TOUPPER "${_dep_id}" _dep_id) + _cpack_nuget_variable_fallback(_ver DEPENDENCIES_${_dep_id}_VERSION) + endif() + + if(_ver) + _cpack_nuget_debug(" got `${_dep}` dependency version ${_ver}") + list(APPEND _collected_deps "") + endif() + endforeach() + + # Render deps into the variable + if(_collected_deps) + set(_CPACK_NUGET_DEPENDENCIES_TAG "\n") + foreach(_line IN LISTS _collected_deps) + string( + APPEND _CPACK_NUGET_DEPENDENCIES_TAG + " ${_line}\n" + ) + endforeach() + string(APPEND _CPACK_NUGET_DEPENDENCIES_TAG " ") + endif() + + # Render the spec file + # NOTE The spec filename doesn't matter. Being included into a package, + # NuGet will name it properly. + _cpack_nuget_debug("Rendering `${CPACK_TEMPORARY_DIRECTORY}/CPack.NuGet.nuspec` file...") + configure_file( + "${CMAKE_ROOT}/Modules/CPack.NuGet.nuspec.in" + "${CPACK_TEMPORARY_DIRECTORY}/CPack.NuGet.nuspec" + @ONLY + ) +endfunction() + +function(_cpack_nuget_make_files_tag) + set(_files) + foreach(_comp IN LISTS ARGN) + string(APPEND _files " \n") + endforeach() + set(_CPACK_NUGET_FILES_TAG "\n${_files} " PARENT_SCOPE) +endfunction() + +find_program(NUGET_EXECUTABLE NuGet) +_cpack_nuget_debug_var(NUGET_EXECUTABLE) +if(NOT NUGET_EXECUTABLE) + message(FATAL_ERROR "NuGet executable not found") +endif() + +# Add details for debug run +if(CPACK_NUGET_PACKAGE_DEBUG) + list(APPEND CPACK_NUGET_PACK_ADDITIONAL_OPTIONS "-Verbosity" "detailed") +endif() + +# Case one: ordinal all-in-one package +if(CPACK_NUGET_ORDINAL_MONOLITIC) + # This variable `CPACK_NUGET_ALL_IN_ONE` set by C++ code: + # Meaning to pack all installed files into a single package + _cpack_nuget_debug("---[Making an ordinal monolitic package]---") + _cpack_nuget_render_spec() + execute_process( + COMMAND "${NUGET_EXECUTABLE}" pack ${CPACK_NUGET_PACK_ADDITIONAL_OPTIONS} + WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" + ) + +elseif(CPACK_NUGET_ALL_IN_ONE) + # This variable `CPACK_NUGET_ALL_IN_ONE` set by C++ code: + # Meaning to pack all installed components into a single package + _cpack_nuget_debug("---[Making a monolitic package from installed components]---") + + # Prepare the `files` element which include files from several components + _cpack_nuget_make_files_tag(${CPACK_NUGET_COMPONENTS}) + _cpack_nuget_render_spec() + execute_process( + COMMAND "${NUGET_EXECUTABLE}" pack ${CPACK_NUGET_PACK_ADDITIONAL_OPTIONS} + WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" + ) + +else() + # Is there any grouped component? + if(CPACK_NUGET_GROUPS) + _cpack_nuget_debug("---[Making grouped component(s) package(s)]---") + foreach(_group IN LISTS CPACK_NUGET_GROUPS) + _cpack_nuget_debug("Starting to make the package for group `${_group}`") + string(MAKE_C_IDENTIFIER "${_group}" _group_up) + string(TOUPPER "${_group_up}" _group_up) + + # Render a spec file which includes all components in the current group + unset(_CPACK_NUGET_FILES_TAG) + _cpack_nuget_make_files_tag(${CPACK_NUGET_${_group_up}_GROUP_COMPONENTS}) + # Temporary set `CPACK_NUGET_PACKAGE_COMPONENT` to the group name + # to properly collect various per group settings + set(CPACK_NUGET_PACKAGE_COMPONENT ${_group}) + _cpack_nuget_render_spec() + unset(CPACK_NUGET_PACKAGE_COMPONENT) + execute_process( + COMMAND "${NUGET_EXECUTABLE}" pack ${CPACK_NUGET_PACK_ADDITIONAL_OPTIONS} + WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" + ) + endforeach() + endif() + # Is there any single component package needed? + if(CPACK_NUGET_COMPONENTS) + _cpack_nuget_debug("---[Making single-component(s) package(s)]---") + foreach(_comp IN LISTS CPACK_NUGET_COMPONENTS) + _cpack_nuget_debug("Starting to make the package for component `${_comp}`") + # Render a spec file which includes only given component + unset(_CPACK_NUGET_FILES_TAG) + _cpack_nuget_make_files_tag(${_comp}) + # Temporary set `CPACK_NUGET_PACKAGE_COMPONENT` to the current + # component name to properly collect various per group settings + set(CPACK_NUGET_PACKAGE_COMPONENT ${_comp}) + _cpack_nuget_render_spec() + unset(CPACK_NUGET_PACKAGE_COMPONENT) + execute_process( + COMMAND "${NUGET_EXECUTABLE}" pack ${CPACK_NUGET_PACK_ADDITIONAL_OPTIONS} + WORKING_DIRECTORY "${CPACK_TEMPORARY_DIRECTORY}" + ) + endforeach() + endif() +endif() + +file(GLOB_RECURSE GEN_CPACK_OUTPUT_FILES "${CPACK_TEMPORARY_DIRECTORY}/*.nupkg") +if(NOT GEN_CPACK_OUTPUT_FILES) + message(FATAL_ERROR "NuGet package was not generated at `${CPACK_TEMPORARY_DIRECTORY}`!") +endif() + +_cpack_nuget_debug("Generated files: ${GEN_CPACK_OUTPUT_FILES}") diff --git a/Modules/Internal/CPack/CPackRPM.cmake b/Modules/Internal/CPack/CPackRPM.cmake new file mode 100644 index 0000000..d044f05 --- /dev/null +++ b/Modules/Internal/CPack/CPackRPM.cmake @@ -0,0 +1,1867 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +# Author: Eric Noulard with the help of Alexander Neundorf. + +function(get_file_permissions FILE RETURN_VAR) + execute_process(COMMAND ls -l ${FILE} + OUTPUT_VARIABLE permissions_ + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + + string(REPLACE " " ";" permissions_ "${permissions_}") + list(GET permissions_ 0 permissions_) + + unset(text_notation_) + set(any_chars_ ".") + foreach(PERMISSION_TYPE "OWNER" "GROUP" "WORLD") + if(permissions_ MATCHES "${any_chars_}r.*") + list(APPEND text_notation_ "${PERMISSION_TYPE}_READ") + endif() + string(APPEND any_chars_ ".") + if(permissions_ MATCHES "${any_chars_}w.*") + list(APPEND text_notation_ "${PERMISSION_TYPE}_WRITE") + endif() + string(APPEND any_chars_ ".") + if(permissions_ MATCHES "${any_chars_}x.*") + list(APPEND text_notation_ "${PERMISSION_TYPE}_EXECUTE") + endif() + endforeach() + + set(${RETURN_VAR} "${text_notation_}" PARENT_SCOPE) +endfunction() + +function(get_unix_permissions_octal_notation PERMISSIONS_VAR RETURN_VAR) + set(PERMISSIONS ${${PERMISSIONS_VAR}}) + list(LENGTH PERMISSIONS PERM_LEN_PRE) + list(REMOVE_DUPLICATES PERMISSIONS) + list(LENGTH PERMISSIONS PERM_LEN_POST) + + if(NOT ${PERM_LEN_PRE} EQUAL ${PERM_LEN_POST}) + message(FATAL_ERROR "${PERMISSIONS_VAR} contains duplicate values.") + endif() + + foreach(PERMISSION_TYPE "OWNER" "GROUP" "WORLD") + set(${PERMISSION_TYPE}_PERMISSIONS 0) + + foreach(PERMISSION ${PERMISSIONS}) + if("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_READ") + math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 4") + elseif("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_WRITE") + math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 2") + elseif("${PERMISSION}" STREQUAL "${PERMISSION_TYPE}_EXECUTE") + math(EXPR ${PERMISSION_TYPE}_PERMISSIONS "${${PERMISSION_TYPE}_PERMISSIONS} + 1") + elseif(PERMISSION MATCHES "${PERMISSION_TYPE}.*") + message(FATAL_ERROR "${PERMISSIONS_VAR} contains invalid values.") + endif() + endforeach() + endforeach() + + set(${RETURN_VAR} "${OWNER_PERMISSIONS}${GROUP_PERMISSIONS}${WORLD_PERMISSIONS}" PARENT_SCOPE) +endfunction() + +function(cpack_rpm_prepare_relocation_paths) + # set appropriate prefix, remove possible trailing slash and convert backslashes to slashes + if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_PREFIX) + file(TO_CMAKE_PATH "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_PREFIX}" PATH_PREFIX) + elseif(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_PREFIX) + file(TO_CMAKE_PATH "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_PREFIX}" PATH_PREFIX) + else() + file(TO_CMAKE_PATH "${CPACK_PACKAGING_INSTALL_PREFIX}" PATH_PREFIX) + endif() + + set(RPM_RELOCATION_PATHS "${CPACK_RPM_RELOCATION_PATHS}") + list(REMOVE_DUPLICATES RPM_RELOCATION_PATHS) + + # set base path prefix + if(EXISTS "${WDIR}/${PATH_PREFIX}") + if(NOT CPACK_RPM_NO_INSTALL_PREFIX_RELOCATION AND + NOT CPACK_RPM_NO_${CPACK_RPM_PACKAGE_COMPONENT}_INSTALL_PREFIX_RELOCATION AND + NOT CPACK_RPM_NO_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_INSTALL_PREFIX_RELOCATION) + string(APPEND TMP_RPM_PREFIXES "Prefix: ${PATH_PREFIX}\n") + list(APPEND RPM_USED_PACKAGE_PREFIXES "${PATH_PREFIX}") + + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: removing '${PATH_PREFIX}' from relocation paths") + endif() + endif() + endif() + + # set other path prefixes + foreach(RELOCATION_PATH ${RPM_RELOCATION_PATHS}) + if(IS_ABSOLUTE "${RELOCATION_PATH}") + set(PREPARED_RELOCATION_PATH "${RELOCATION_PATH}") + elseif(PATH_PREFIX STREQUAL "/") + # don't prefix path with a second slash as "//" is treated as network path + # by get_filename_component() so it remains in path even inside rpm + # package where it may cause problems with relocation + set(PREPARED_RELOCATION_PATH "/${RELOCATION_PATH}") + else() + set(PREPARED_RELOCATION_PATH "${PATH_PREFIX}/${RELOCATION_PATH}") + endif() + + # handle cases where path contains extra slashes (e.g. /a//b/ instead of + # /a/b) + get_filename_component(PREPARED_RELOCATION_PATH + "${PREPARED_RELOCATION_PATH}" ABSOLUTE) + + if(EXISTS "${WDIR}/${PREPARED_RELOCATION_PATH}") + string(APPEND TMP_RPM_PREFIXES "Prefix: ${PREPARED_RELOCATION_PATH}\n") + list(APPEND RPM_USED_PACKAGE_PREFIXES "${PREPARED_RELOCATION_PATH}") + endif() + endforeach() + + # warn about all the paths that are not relocatable + file(GLOB_RECURSE FILE_PATHS_ "${WDIR}/*") + foreach(TMP_PATH ${FILE_PATHS_}) + string(LENGTH "${WDIR}" WDIR_LEN) + string(SUBSTRING "${TMP_PATH}" ${WDIR_LEN} -1 TMP_PATH) + unset(TMP_PATH_FOUND_) + + foreach(RELOCATION_PATH ${RPM_USED_PACKAGE_PREFIXES}) + file(RELATIVE_PATH REL_PATH_ "${RELOCATION_PATH}" "${TMP_PATH}") + string(SUBSTRING "${REL_PATH_}" 0 2 PREFIX_) + + if(NOT "${PREFIX_}" STREQUAL "..") + set(TPM_PATH_FOUND_ TRUE) + break() + endif() + endforeach() + + if(NOT TPM_PATH_FOUND_) + message(AUTHOR_WARNING "CPackRPM:Warning: Path ${TMP_PATH} is not on one of the relocatable paths! Package will be partially relocatable.") + endif() + endforeach() + + set(RPM_USED_PACKAGE_PREFIXES "${RPM_USED_PACKAGE_PREFIXES}" PARENT_SCOPE) + set(TMP_RPM_PREFIXES "${TMP_RPM_PREFIXES}" PARENT_SCOPE) +endfunction() + +function(cpack_rpm_prepare_content_list) + # get files list + file(GLOB_RECURSE CPACK_RPM_INSTALL_FILES LIST_DIRECTORIES true RELATIVE "${WDIR}" "${WDIR}/*") + set(CPACK_RPM_INSTALL_FILES "/${CPACK_RPM_INSTALL_FILES}") + string(REPLACE ";" ";/" CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}") + + # if we are creating a relocatable package, omit parent directories of + # CPACK_RPM_PACKAGE_PREFIX. This is achieved by building a "filter list" + # which is passed to the find command that generates the content-list + if(CPACK_RPM_PACKAGE_RELOCATABLE) + # get a list of the elements in CPACK_RPM_PACKAGE_PREFIXES that are + # destinct parent paths of other relocation paths and remove the + # final element (so the install-prefix dir itself is not omitted + # from the RPM's content-list) + list(SORT RPM_USED_PACKAGE_PREFIXES) + set(_DISTINCT_PATH "NOT_SET") + foreach(_RPM_RELOCATION_PREFIX ${RPM_USED_PACKAGE_PREFIXES}) + if(NOT "${_RPM_RELOCATION_PREFIX}" MATCHES "${_DISTINCT_PATH}/.*") + set(_DISTINCT_PATH "${_RPM_RELOCATION_PREFIX}") + + string(REPLACE "/" ";" _CPACK_RPM_PACKAGE_PREFIX_ELEMS " ${_RPM_RELOCATION_PREFIX}") + list(REMOVE_AT _CPACK_RPM_PACKAGE_PREFIX_ELEMS -1) + unset(_TMP_LIST) + # Now generate all of the parent dirs of the relocation path + foreach(_PREFIX_PATH_ELEM ${_CPACK_RPM_PACKAGE_PREFIX_ELEMS}) + list(APPEND _TMP_LIST "${_PREFIX_PATH_ELEM}") + string(REPLACE ";" "/" _OMIT_DIR "${_TMP_LIST}") + separate_arguments(_OMIT_DIR) + list(APPEND _RPM_DIRS_TO_OMIT ${_OMIT_DIR}) + endforeach() + endif() + endforeach() + endif() + + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: Initial list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}") + endif() + + if(NOT DEFINED CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST) + set(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST /etc /etc/init.d /usr /usr/bin + /usr/include /usr/lib /usr/libx32 /usr/lib64 + /usr/share /usr/share/aclocal /usr/share/doc ) + if(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION) + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: Adding ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION} to builtin omit list.") + endif() + list(APPEND CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST "${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION}") + endif() + endif() + + if(CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST) + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST= ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST}") + endif() + list(APPEND _RPM_DIRS_TO_OMIT ${CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST}) + endif() + + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: Final list of path to OMIT in RPM: ${_RPM_DIRS_TO_OMIT}") + endif() + + list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES ${_RPM_DIRS_TO_OMIT}) + + # add man paths that will be compressed + # (copied from /usr/lib/rpm/brp-compress - script that does the actual + # compressing) + list(APPEND MAN_LOCATIONS "/usr/man/man.*" "/usr/man/.*/man.*" "/usr/info.*" + "/usr/share/man/man.*" "/usr/share/man/.*/man.*" "/usr/share/info.*" + "/usr/kerberos/man.*" "/usr/X11R6/man/man.*" "/usr/lib/perl5/man/man.*" + "/usr/share/doc/.*/man/man.*" "/usr/lib/.*/man/man.*") + + if(CPACK_RPM_ADDITIONAL_MAN_DIRS) + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: CPACK_RPM_ADDITIONAL_MAN_DIRS= ${CPACK_RPM_ADDITIONAL_MAN_DIRS}") + endif() + list(APPEND MAN_LOCATIONS ${CPACK_RPM_ADDITIONAL_MAN_DIRS}) + endif() + + foreach(PACK_LOCATION IN LISTS CPACK_RPM_INSTALL_FILES) + foreach(MAN_LOCATION IN LISTS MAN_LOCATIONS) + # man pages are files inside a certain location + if(PACK_LOCATION MATCHES "${MAN_LOCATION}/" + AND NOT IS_DIRECTORY "${WDIR}${PACK_LOCATION}" + AND NOT IS_SYMLINK "${WDIR}${PACK_LOCATION}") + list(FIND CPACK_RPM_INSTALL_FILES "${PACK_LOCATION}" INDEX) + # insert file location that covers compressed man pages + # even if using a wildcard causes duplicates as those are + # handled by RPM and we still keep the same file list + # in spec file - wildcard only represents file type (e.g. .gz) + list(INSERT CPACK_RPM_INSTALL_FILES ${INDEX} "${PACK_LOCATION}*") + # remove file location that doesn't cover compressed man pages + math(EXPR INDEX ${INDEX}+1) + list(REMOVE_AT CPACK_RPM_INSTALL_FILES ${INDEX}) + + break() + endif() + endforeach() + endforeach() + + set(CPACK_RPM_INSTALL_FILES "${CPACK_RPM_INSTALL_FILES}" PARENT_SCOPE) +endfunction() + +function(cpack_rpm_symlink_get_relocation_prefixes LOCATION PACKAGE_PREFIXES RETURN_VARIABLE) + foreach(PKG_PREFIX IN LISTS PACKAGE_PREFIXES) + string(REGEX MATCH "^${PKG_PREFIX}/.*" FOUND_ "${LOCATION}") + if(FOUND_) + list(APPEND TMP_PREFIXES "${PKG_PREFIX}") + endif() + endforeach() + + set(${RETURN_VARIABLE} "${TMP_PREFIXES}" PARENT_SCOPE) +endfunction() + +function(cpack_rpm_symlink_create_relocation_script PACKAGE_PREFIXES) + list(LENGTH PACKAGE_PREFIXES LAST_INDEX) + set(SORTED_PACKAGE_PREFIXES "${PACKAGE_PREFIXES}") + list(SORT SORTED_PACKAGE_PREFIXES) + list(REVERSE SORTED_PACKAGE_PREFIXES) + math(EXPR LAST_INDEX ${LAST_INDEX}-1) + + foreach(SYMLINK_INDEX RANGE ${LAST_INDEX}) + list(GET SORTED_PACKAGE_PREFIXES ${SYMLINK_INDEX} SRC_PATH) + list(FIND PACKAGE_PREFIXES "${SRC_PATH}" SYMLINK_INDEX) # reverse magic + string(LENGTH "${SRC_PATH}" SRC_PATH_LEN) + + set(PARTS_CNT 0) + set(SCRIPT_PART "if [ \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}\" != \"${SRC_PATH}\" ]; then\n") + + # both paths relocated + foreach(POINT_INDEX RANGE ${LAST_INDEX}) + list(GET SORTED_PACKAGE_PREFIXES ${POINT_INDEX} POINT_PATH) + list(FIND PACKAGE_PREFIXES "${POINT_PATH}" POINT_INDEX) # reverse magic + string(LENGTH "${POINT_PATH}" POINT_PATH_LEN) + + if(_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX}) + if("${SYMLINK_INDEX}" EQUAL "${POINT_INDEX}") + set(INDENT "") + else() + string(APPEND SCRIPT_PART " if [ \"$RPM_INSTALL_PREFIX${POINT_INDEX}\" != \"${POINT_PATH}\" ]; then\n") + set(INDENT " ") + endif() + + foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX}) + math(EXPR PARTS_CNT ${PARTS_CNT}+1) + + math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1) + list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR) + string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX) + + math(EXPR SRC_PATH_END ${SPLIT_INDEX}-${SRC_PATH_LEN}) + string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${SRC_PATH_LEN} ${SRC_PATH_END} SYMLINK_) + + math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1+${POINT_PATH_LEN}) + string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_) + + string(APPEND SCRIPT_PART " ${INDENT}if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n") + string(APPEND SCRIPT_PART " ${INDENT}ln -s \"$RPM_INSTALL_PREFIX${POINT_INDEX}${POINT_}\" \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}${SYMLINK_}\"\n") + string(APPEND SCRIPT_PART " ${INDENT}CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n") + string(APPEND SCRIPT_PART " ${INDENT}fi\n") + endforeach() + + if(NOT "${SYMLINK_INDEX}" EQUAL "${POINT_INDEX}") + string(APPEND SCRIPT_PART " fi\n") + endif() + endif() + endforeach() + + # source path relocated + if(_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X) + foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X) + math(EXPR PARTS_CNT ${PARTS_CNT}+1) + + math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1) + list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR) + string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX) + + math(EXPR SRC_PATH_END ${SPLIT_INDEX}-${SRC_PATH_LEN}) + string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${SRC_PATH_LEN} ${SRC_PATH_END} SYMLINK_) + + math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1) + string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_) + + string(APPEND SCRIPT_PART " if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n") + string(APPEND SCRIPT_PART " ln -s \"${POINT_}\" \"$RPM_INSTALL_PREFIX${SYMLINK_INDEX}${SYMLINK_}\"\n") + string(APPEND SCRIPT_PART " CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n") + string(APPEND SCRIPT_PART " fi\n") + endforeach() + endif() + + if(PARTS_CNT) + set(SCRIPT "${SCRIPT_PART}") + string(APPEND SCRIPT "fi\n") + endif() + endforeach() + + # point path relocated + foreach(POINT_INDEX RANGE ${LAST_INDEX}) + list(GET SORTED_PACKAGE_PREFIXES ${POINT_INDEX} POINT_PATH) + list(FIND PACKAGE_PREFIXES "${POINT_PATH}" POINT_INDEX) # reverse magic + string(LENGTH "${POINT_PATH}" POINT_PATH_LEN) + + if(_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX}) + string(APPEND SCRIPT "if [ \"$RPM_INSTALL_PREFIX${POINT_INDEX}\" != \"${POINT_PATH}\" ]; then\n") + + foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX}) + math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1) + list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR) + string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX) + + string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} 0 ${SPLIT_INDEX} SYMLINK_) + + math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1+${POINT_PATH_LEN}) + string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_) + + string(APPEND SCRIPT " if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n") + string(APPEND SCRIPT " ln -s \"$RPM_INSTALL_PREFIX${POINT_INDEX}${POINT_}\" \"${SYMLINK_}\"\n") + string(APPEND SCRIPT " CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}=true\n") + string(APPEND SCRIPT " fi\n") + endforeach() + + string(APPEND SCRIPT "fi\n") + endif() + endforeach() + + # no path relocated + if(_RPM_RELOCATION_SCRIPT_X_X) + foreach(RELOCATION_NO IN LISTS _RPM_RELOCATION_SCRIPT_X_X) + math(EXPR RELOCATION_INDEX ${RELOCATION_NO}-1) + list(GET _RPM_RELOCATION_SCRIPT_PAIRS ${RELOCATION_INDEX} RELOCATION_SCRIPT_PAIR) + string(FIND "${RELOCATION_SCRIPT_PAIR}" ":" SPLIT_INDEX) + + string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} 0 ${SPLIT_INDEX} SYMLINK_) + + math(EXPR POINT_PATH_START ${SPLIT_INDEX}+1) + string(SUBSTRING ${RELOCATION_SCRIPT_PAIR} ${POINT_PATH_START} -1 POINT_) + + string(APPEND SCRIPT "if [ -z \"$CPACK_RPM_RELOCATED_SYMLINK_${RELOCATION_INDEX}\" ]; then\n") + string(APPEND SCRIPT " ln -s \"${POINT_}\" \"${SYMLINK_}\"\n") + string(APPEND SCRIPT "fi\n") + endforeach() + endif() + + set(RPM_SYMLINK_POSTINSTALL "${SCRIPT}" PARENT_SCOPE) +endfunction() + +function(cpack_rpm_symlink_add_for_relocation_script PACKAGE_PREFIXES SYMLINK SYMLINK_RELOCATION_PATHS POINT POINT_RELOCATION_PATHS) + list(LENGTH SYMLINK_RELOCATION_PATHS SYMLINK_PATHS_COUTN) + list(LENGTH POINT_RELOCATION_PATHS POINT_PATHS_COUNT) + + list(APPEND _RPM_RELOCATION_SCRIPT_PAIRS "${SYMLINK}:${POINT}") + list(LENGTH _RPM_RELOCATION_SCRIPT_PAIRS PAIR_NO) + + if(SYMLINK_PATHS_COUTN) + foreach(SYMLINK_RELOC_PATH IN LISTS SYMLINK_RELOCATION_PATHS) + list(FIND PACKAGE_PREFIXES "${SYMLINK_RELOC_PATH}" SYMLINK_INDEX) + + # source path relocated + list(APPEND _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X "${PAIR_NO}") + list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_X") + + foreach(POINT_RELOC_PATH IN LISTS POINT_RELOCATION_PATHS) + list(FIND PACKAGE_PREFIXES "${POINT_RELOC_PATH}" POINT_INDEX) + + # both paths relocated + list(APPEND _RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX} "${PAIR_NO}") + list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_${SYMLINK_INDEX}_${POINT_INDEX}") + + # point path relocated + list(APPEND _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX} "${PAIR_NO}") + list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX}") + endforeach() + endforeach() + elseif(POINT_PATHS_COUNT) + foreach(POINT_RELOC_PATH IN LISTS POINT_RELOCATION_PATHS) + list(FIND PACKAGE_PREFIXES "${POINT_RELOC_PATH}" POINT_INDEX) + + # point path relocated + list(APPEND _RPM_RELOCATION_SCRIPT_X_${POINT_INDEX} "${PAIR_NO}") + list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_${POINT_INDEX}") + endforeach() + endif() + + # no path relocated + list(APPEND _RPM_RELOCATION_SCRIPT_X_X "${PAIR_NO}") + list(APPEND RELOCATION_VARS "_RPM_RELOCATION_SCRIPT_X_X") + + # place variables into parent scope + foreach(VAR IN LISTS RELOCATION_VARS) + set(${VAR} "${${VAR}}" PARENT_SCOPE) + endforeach() + set(_RPM_RELOCATION_SCRIPT_PAIRS "${_RPM_RELOCATION_SCRIPT_PAIRS}" PARENT_SCOPE) + set(REQUIRES_SYMLINK_RELOCATION_SCRIPT "true" PARENT_SCOPE) + set(DIRECTIVE "%ghost " PARENT_SCOPE) +endfunction() + +function(cpack_rpm_prepare_install_files INSTALL_FILES_LIST WDIR PACKAGE_PREFIXES IS_RELOCATABLE) + # Prepend directories in ${CPACK_RPM_INSTALL_FILES} with %dir + # This is necessary to avoid duplicate files since rpmbuild does + # recursion on its own when encountering a pathname which is a directory + # which is not flagged as %dir + string(STRIP "${INSTALL_FILES_LIST}" INSTALL_FILES_LIST) + string(REPLACE "\n" ";" INSTALL_FILES_LIST + "${INSTALL_FILES_LIST}") + string(REPLACE "\"" "" INSTALL_FILES_LIST + "${INSTALL_FILES_LIST}") + string(LENGTH "${WDIR}" WDR_LEN_) + + list(SORT INSTALL_FILES_LIST) # make file order consistent on all platforms + + foreach(F IN LISTS INSTALL_FILES_LIST) + unset(DIRECTIVE) + + if(IS_SYMLINK "${WDIR}/${F}") + if(IS_RELOCATABLE) + # check that symlink has relocatable format + get_filename_component(SYMLINK_LOCATION_ "${WDIR}/${F}" DIRECTORY) + execute_process(COMMAND ls -la "${WDIR}/${F}" + WORKING_DIRECTORY "${WDIR}" + OUTPUT_VARIABLE SYMLINK_POINT_ + OUTPUT_STRIP_TRAILING_WHITESPACE) + + string(FIND "${SYMLINK_POINT_}" "->" SYMLINK_POINT_INDEX_ REVERSE) + math(EXPR SYMLINK_POINT_INDEX_ ${SYMLINK_POINT_INDEX_}+3) + string(LENGTH "${SYMLINK_POINT_}" SYMLINK_POINT_LENGTH_) + + # get destination path + string(SUBSTRING "${SYMLINK_POINT_}" ${SYMLINK_POINT_INDEX_} ${SYMLINK_POINT_LENGTH_} SYMLINK_POINT_) + + # check if path is relative or absolute + string(SUBSTRING "${SYMLINK_POINT_}" 0 1 SYMLINK_IS_ABSOLUTE_) + + if(${SYMLINK_IS_ABSOLUTE_} STREQUAL "/") + # prevent absolute paths from having /../ or /./ section inside of them + get_filename_component(SYMLINK_POINT_ "${SYMLINK_POINT_}" ABSOLUTE) + else() + # handle relative path + get_filename_component(SYMLINK_POINT_ "${SYMLINK_LOCATION_}/${SYMLINK_POINT_}" ABSOLUTE) + endif() + + # recalculate path length after conversion to canonical form + string(LENGTH "${SYMLINK_POINT_}" SYMLINK_POINT_LENGTH_) + + if(SYMLINK_POINT_ MATCHES "${WDIR}/.*") + # only symlinks that are pointing inside the packaging structure should be checked for relocation + string(SUBSTRING "${SYMLINK_POINT_}" ${WDR_LEN_} -1 SYMLINK_POINT_WD_) + cpack_rpm_symlink_get_relocation_prefixes("${F}" "${PACKAGE_PREFIXES}" "SYMLINK_RELOCATIONS") + cpack_rpm_symlink_get_relocation_prefixes("${SYMLINK_POINT_WD_}" "${PACKAGE_PREFIXES}" "POINT_RELOCATIONS") + + list(LENGTH SYMLINK_RELOCATIONS SYMLINK_RELOCATIONS_COUNT) + list(LENGTH POINT_RELOCATIONS POINT_RELOCATIONS_COUNT) + else() + # location pointed to is ouside WDR so it should be treated as a permanent symlink + set(SYMLINK_POINT_WD_ "${SYMLINK_POINT_}") + + unset(SYMLINK_RELOCATIONS) + unset(POINT_RELOCATIONS) + unset(SYMLINK_RELOCATIONS_COUNT) + unset(POINT_RELOCATIONS_COUNT) + + message(AUTHOR_WARNING "CPackRPM:Warning: Symbolic link '${F}' points to location that is outside packaging path! Link will possibly not be relocatable.") + endif() + + if(SYMLINK_RELOCATIONS_COUNT AND POINT_RELOCATIONS_COUNT) + # find matching + foreach(SYMLINK_RELOCATION_PREFIX IN LISTS SYMLINK_RELOCATIONS) + list(FIND POINT_RELOCATIONS "${SYMLINK_RELOCATION_PREFIX}" FOUND_INDEX) + if(NOT ${FOUND_INDEX} EQUAL -1) + break() + endif() + endforeach() + + if(NOT ${FOUND_INDEX} EQUAL -1) + # symlinks have the same subpath + if(${SYMLINK_RELOCATIONS_COUNT} EQUAL 1 AND ${POINT_RELOCATIONS_COUNT} EQUAL 1) + # permanent symlink + get_filename_component(SYMLINK_LOCATION_ "${F}" DIRECTORY) + file(RELATIVE_PATH FINAL_PATH_ ${SYMLINK_LOCATION_} ${SYMLINK_POINT_WD_}) + execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${FINAL_PATH_}" "${WDIR}/${F}") + else() + # relocation subpaths + cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}" + "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}") + endif() + else() + # not on the same relocation path + cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}" + "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}") + endif() + elseif(POINT_RELOCATIONS_COUNT) + # point is relocatable + cpack_rpm_symlink_add_for_relocation_script("${PACKAGE_PREFIXES}" "${F}" "${SYMLINK_RELOCATIONS}" + "${SYMLINK_POINT_WD_}" "${POINT_RELOCATIONS}") + else() + # is not relocatable or points to non relocatable path - permanent symlink + execute_process(COMMAND "${CMAKE_COMMAND}" -E create_symlink "${SYMLINK_POINT_WD_}" "${WDIR}/${F}") + endif() + endif() + elseif(IS_DIRECTORY "${WDIR}/${F}") + set(DIRECTIVE "%dir ") + endif() + + string(APPEND INSTALL_FILES "${DIRECTIVE}\"${F}\"\n") + endforeach() + + if(REQUIRES_SYMLINK_RELOCATION_SCRIPT) + cpack_rpm_symlink_create_relocation_script("${PACKAGE_PREFIXES}") + endif() + + set(RPM_SYMLINK_POSTINSTALL "${RPM_SYMLINK_POSTINSTALL}" PARENT_SCOPE) + set(CPACK_RPM_INSTALL_FILES "${INSTALL_FILES}" PARENT_SCOPE) +endfunction() + +if(CMAKE_BINARY_DIR) + message(FATAL_ERROR "CPackRPM.cmake may only be used by CPack internally.") +endif() + +if(NOT UNIX) + message(FATAL_ERROR "CPackRPM.cmake may only be used under UNIX.") +endif() + +# We need to check if the binaries were compiled with debug symbols +# because without them the package will be useless +function(cpack_rpm_debugsymbol_check INSTALL_FILES WORKING_DIR) + if(NOT CPACK_BUILD_SOURCE_DIRS) + message(FATAL_ERROR "CPackRPM: CPACK_BUILD_SOURCE_DIRS variable is not set!" + " Required for debuginfo packaging. See documentation of" + " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.") + endif() + + # With objdump we should check the debug symbols + find_program(OBJDUMP_EXECUTABLE objdump) + if(NOT OBJDUMP_EXECUTABLE) + message(FATAL_ERROR "CPackRPM: objdump binary could not be found!" + " Required for debuginfo packaging. See documentation of" + " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.") + endif() + + # With debugedit we prepare source files list + find_program(DEBUGEDIT_EXECUTABLE debugedit "/usr/lib/rpm/") + if(NOT DEBUGEDIT_EXECUTABLE) + message(FATAL_ERROR "CPackRPM: debugedit binary could not be found!" + " Required for debuginfo packaging. See documentation of" + " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.") + endif() + + unset(mkdir_list_) + unset(cp_list_) + unset(additional_sources_) + + foreach(F IN LISTS INSTALL_FILES) + if(IS_DIRECTORY "${WORKING_DIR}/${F}" OR IS_SYMLINK "${WORKING_DIR}/${F}") + continue() + endif() + + execute_process(COMMAND "${OBJDUMP_EXECUTABLE}" -h ${WORKING_DIR}/${F} + WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}" + RESULT_VARIABLE OBJDUMP_EXEC_RESULT + OUTPUT_VARIABLE OBJDUMP_OUT + ERROR_QUIET) + # Check if the given file is an executable or not + if(NOT OBJDUMP_EXEC_RESULT) + string(FIND "${OBJDUMP_OUT}" "debug" FIND_RESULT) + if(FIND_RESULT GREATER -1) + set(index_ 0) + foreach(source_dir_ IN LISTS CPACK_BUILD_SOURCE_DIRS) + string(LENGTH "${source_dir_}" source_dir_len_) + string(LENGTH "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}" debuginfo_dir_len) + if(source_dir_len_ LESS debuginfo_dir_len) + message(FATAL_ERROR "CPackRPM: source dir path '${source_dir_}' is" + " shorter than debuginfo sources dir path '${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}'!" + " Source dir path must be longer than debuginfo sources dir path." + " Set CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX variable to a shorter value" + " or make source dir path longer." + " Required for debuginfo packaging. See documentation of" + " CPACK_RPM_DEBUGINFO_PACKAGE variable for details.") + endif() + + file(REMOVE "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}/debugsources_add.list") + execute_process(COMMAND "${DEBUGEDIT_EXECUTABLE}" -b "${source_dir_}" -d "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}" -i -l "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}/debugsources_add.list" "${WORKING_DIR}/${F}" + RESULT_VARIABLE res_ + OUTPUT_VARIABLE opt_ + ERROR_VARIABLE err_ + ) + + file(STRINGS + "${CPACK_RPM_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}/debugsources_add.list" + sources_) + list(REMOVE_DUPLICATES sources_) + + foreach(source_ IN LISTS sources_) + if(EXISTS "${source_dir_}/${source_}" AND NOT IS_DIRECTORY "${source_dir_}/${source_}") + get_filename_component(path_part_ "${source_}" DIRECTORY) + list(APPEND mkdir_list_ "%{buildroot}${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${path_part_}") + list(APPEND cp_list_ "cp \"${source_dir_}/${source_}\" \"%{buildroot}${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${path_part_}\"") + + list(APPEND additional_sources_ "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}/src_${index_}/${source_}") + endif() + endforeach() + + math(EXPR index_ "${index_} + 1") + endforeach() + else() + message(WARNING "CPackRPM: File: ${F} does not contain debug symbols. They will possibly be missing from debuginfo package!") + endif() + + get_file_permissions("${WORKING_DIR}/${F}" permissions_) + if(NOT "USER_EXECUTE" IN_LIST permissions_ AND + NOT "GROUP_EXECUTE" IN_LIST permissions_ AND + NOT "WORLD_EXECUTE" IN_LIST permissions_) + if(CPACK_RPM_INSTALL_WITH_EXEC) + execute_process(COMMAND chmod a+x ${WORKING_DIR}/${F} + RESULT_VARIABLE res_ + ERROR_VARIABLE err_ + OUTPUT_QUIET) + + if(res_) + message(FATAL_ERROR "CPackRPM: could not apply execute permissions " + "requested by CPACK_RPM_INSTALL_WITH_EXEC variable on " + "'${WORKING_DIR}/${F}'! Reason: '${err_}'") + endif() + else() + message(AUTHOR_WARNING "CPackRPM: File: ${WORKING_DIR}/${F} does not " + "have execute permissions. Debuginfo symbols will not be extracted" + "! Missing debuginfo may cause packaging failure. Consider setting " + "execute permissions or setting 'CPACK_RPM_INSTALL_WITH_EXEC' " + "variable.") + endif() + endif() + endif() + endforeach() + + list(LENGTH mkdir_list_ len_) + if(len_) + list(REMOVE_DUPLICATES mkdir_list_) + unset(TMP_RPM_DEBUGINFO_INSTALL) + foreach(part_ IN LISTS mkdir_list_) + string(APPEND TMP_RPM_DEBUGINFO_INSTALL "mkdir -p \"${part_}\"\n") + endforeach() + endif() + + list(LENGTH cp_list_ len_) + if(len_) + list(REMOVE_DUPLICATES cp_list_) + foreach(part_ IN LISTS cp_list_) + string(APPEND TMP_RPM_DEBUGINFO_INSTALL "${part_}\n") + endforeach() + endif() + + if(NOT DEFINED CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS) + set(CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS /usr /usr/src /usr/src/debug) + if(CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION) + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: Adding ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION} to builtin omit list.") + endif() + list(APPEND CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS "${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS_ADDITION}") + endif() + endif() + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS= ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS}") + endif() + + list(LENGTH additional_sources_ len_) + if(len_) + list(REMOVE_DUPLICATES additional_sources_) + unset(additional_sources_all_) + foreach(source_ IN LISTS additional_sources_) + string(REPLACE "/" ";" split_source_ " ${source_}") + list(REMOVE_AT split_source_ 0) + unset(tmp_path_) + # Now generate all segments of the path + foreach(segment_ IN LISTS split_source_) + string(APPEND tmp_path_ "/${segment_}") + list(APPEND additional_sources_all_ "${tmp_path_}") + endforeach() + endforeach() + + list(REMOVE_DUPLICATES additional_sources_all_) + list(REMOVE_ITEM additional_sources_all_ + ${CPACK_RPM_DEBUGINFO_EXCLUDE_DIRS}) + + unset(TMP_DEBUGINFO_ADDITIONAL_SOURCES) + foreach(source_ IN LISTS additional_sources_all_) + string(APPEND TMP_DEBUGINFO_ADDITIONAL_SOURCES "${source_}\n") + endforeach() + endif() + + set(TMP_RPM_DEBUGINFO_INSTALL "${TMP_RPM_DEBUGINFO_INSTALL}" PARENT_SCOPE) + set(TMP_DEBUGINFO_ADDITIONAL_SOURCES "${TMP_DEBUGINFO_ADDITIONAL_SOURCES}" + PARENT_SCOPE) +endfunction() + +function(cpack_rpm_variable_fallback OUTPUT_VAR_NAME) + set(FALLBACK_VAR_NAMES ${ARGN}) + + foreach(variable_name IN LISTS FALLBACK_VAR_NAMES) + if(${variable_name}) + set(${OUTPUT_VAR_NAME} "${${variable_name}}" PARENT_SCOPE) + break() + endif() + endforeach() +endfunction() + +function(cpack_rpm_generate_package) + # rpmbuild is the basic command for building RPM package + # it may be a simple (symbolic) link to rpm command. + find_program(RPMBUILD_EXECUTABLE rpmbuild) + + # Check version of the rpmbuild tool this would be easier to + # track bugs with users and CPackRPM debug mode. + # We may use RPM version in order to check for available version dependent features + if(RPMBUILD_EXECUTABLE) + execute_process(COMMAND ${RPMBUILD_EXECUTABLE} --version + OUTPUT_VARIABLE _TMP_VERSION + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REGEX REPLACE "^.* " "" + RPMBUILD_EXECUTABLE_VERSION + ${_TMP_VERSION}) + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: rpmbuild version is <${RPMBUILD_EXECUTABLE_VERSION}>") + endif() + endif() + + if(NOT RPMBUILD_EXECUTABLE) + message(FATAL_ERROR "RPM package requires rpmbuild executable") + endif() + + # Display lsb_release output if DEBUG mode enable + # This will help to diagnose problem with CPackRPM + # because we will know on which kind of Linux we are + if(CPACK_RPM_PACKAGE_DEBUG) + find_program(LSB_RELEASE_EXECUTABLE lsb_release) + if(LSB_RELEASE_EXECUTABLE) + execute_process(COMMAND ${LSB_RELEASE_EXECUTABLE} -a + OUTPUT_VARIABLE _TMP_LSB_RELEASE_OUTPUT + ERROR_QUIET + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REGEX REPLACE "\n" ", " + LSB_RELEASE_OUTPUT + ${_TMP_LSB_RELEASE_OUTPUT}) + else () + set(LSB_RELEASE_OUTPUT "lsb_release not installed/found!") + endif() + message("CPackRPM:Debug: LSB_RELEASE = ${LSB_RELEASE_OUTPUT}") + endif() + + # We may use RPM version in the future in order + # to shut down warning about space in buildtree + # some recent RPM version should support space in different places. + # not checked [yet]. + if(CPACK_TOPLEVEL_DIRECTORY MATCHES ".* .*") + message(FATAL_ERROR "${RPMBUILD_EXECUTABLE} can't handle paths with spaces, use a build directory without spaces for building RPMs.") + endif() + + # If rpmbuild is found + # we try to discover alien since we may be on non RPM distro like Debian. + # In this case we may try to to use more advanced features + # like generating RPM directly from DEB using alien. + # FIXME feature not finished (yet) + find_program(ALIEN_EXECUTABLE alien) + if(ALIEN_EXECUTABLE) + message(STATUS "alien found, we may be on a Debian based distro.") + endif() + + # Are we packaging components ? + if(CPACK_RPM_PACKAGE_COMPONENT) + string(TOUPPER ${CPACK_RPM_PACKAGE_COMPONENT} CPACK_RPM_PACKAGE_COMPONENT_UPPER) + endif() + + set(WDIR "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}") + + # + # Use user-defined RPM specific variables value + # or generate reasonable default value from + # CPACK_xxx generic values. + # The variables comes from the needed (mandatory or not) + # values found in the RPM specification file aka ".spec" file. + # The variables which may/should be defined are: + # + + # CPACK_RPM_PACKAGE_SUMMARY (mandatory) + + if(CPACK_RPM_PACKAGE_COMPONENT) + cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_SUMMARY" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_SUMMARY" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_SUMMARY") + endif() + + if(NOT CPACK_RPM_PACKAGE_SUMMARY) + if(CPACK_PACKAGE_DESCRIPTION_SUMMARY) + set(CPACK_RPM_PACKAGE_SUMMARY ${CPACK_PACKAGE_DESCRIPTION_SUMMARY}) + else() + # if neither var is defined lets use the name as summary + string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_SUMMARY) + endif() + endif() + + if(NOT CPACK_RPM_PACKAGE_URL AND CMAKE_PROJECT_HOMEPAGE_URL) + set(CPACK_RPM_PACKAGE_URL "${CMAKE_PROJECT_HOMEPAGE_URL}") + endif() + + # CPACK_RPM_PACKAGE_NAME (mandatory) + if(NOT CPACK_RPM_PACKAGE_NAME) + string(TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_RPM_PACKAGE_NAME) + endif() + + if(CPACK_RPM_PACKAGE_COMPONENT) + string(TOUPPER "${CPACK_RPM_MAIN_COMPONENT}" + CPACK_RPM_MAIN_COMPONENT_UPPER) + + if(NOT CPACK_RPM_MAIN_COMPONENT_UPPER STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER) + string(APPEND CPACK_RPM_PACKAGE_NAME "-${CPACK_RPM_PACKAGE_COMPONENT}") + + cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_NAME" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_NAME" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_NAME") + endif() + endif() + + # CPACK_RPM_PACKAGE_VERSION (mandatory) + if(NOT CPACK_RPM_PACKAGE_VERSION) + if(NOT CPACK_PACKAGE_VERSION) + message(FATAL_ERROR "RPM package requires a package version") + endif() + set(CPACK_RPM_PACKAGE_VERSION ${CPACK_PACKAGE_VERSION}) + endif() + # Replace '-' in version with '_' + # '-' character is an Illegal RPM version character + # it is illegal because it is used to separate + # RPM "Version" from RPM "Release" + string(REPLACE "-" "_" CPACK_RPM_PACKAGE_VERSION ${CPACK_RPM_PACKAGE_VERSION}) + + # CPACK_RPM_PACKAGE_ARCHITECTURE (mandatory) + if(NOT CPACK_RPM_PACKAGE_ARCHITECTURE) + execute_process(COMMAND uname "-m" + OUTPUT_VARIABLE CPACK_RPM_PACKAGE_ARCHITECTURE + OUTPUT_STRIP_TRAILING_WHITESPACE) + else() + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: using user-specified build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}") + endif() + endif() + + if(CPACK_RPM_PACKAGE_COMPONENT) + cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_ARCHITECTURE" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_ARCHITECTURE" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_ARCHITECTURE") + + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: using component build arch = ${CPACK_RPM_PACKAGE_ARCHITECTURE}") + endif() + endif() + + if(${CPACK_RPM_PACKAGE_ARCHITECTURE} STREQUAL "noarch") + set(TMP_RPM_BUILDARCH "Buildarch: ${CPACK_RPM_PACKAGE_ARCHITECTURE}") + else() + set(TMP_RPM_BUILDARCH "") + endif() + + # CPACK_RPM_PACKAGE_RELEASE + # The RPM release is the numbering of the RPM package ITSELF + # this is the version of the PACKAGING and NOT the version + # of the CONTENT of the package. + # You may well need to generate a new RPM package release + # without changing the version of the packaged software. + # This is the case when the packaging is buggy (not) the software :=) + # If not set, 1 is a good candidate + if(NOT CPACK_RPM_PACKAGE_RELEASE) + set(CPACK_RPM_PACKAGE_RELEASE "1") + endif() + + if(CPACK_RPM_PACKAGE_RELEASE_DIST) + string(APPEND CPACK_RPM_PACKAGE_RELEASE "%{?dist}") + endif() + + # CPACK_RPM_PACKAGE_LICENSE + if(NOT CPACK_RPM_PACKAGE_LICENSE) + set(CPACK_RPM_PACKAGE_LICENSE "unknown") + endif() + + # CPACK_RPM_PACKAGE_GROUP + if(CPACK_RPM_PACKAGE_COMPONENT) + cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_GROUP" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_GROUP" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_GROUP") + endif() + + if(NOT CPACK_RPM_PACKAGE_GROUP) + set(CPACK_RPM_PACKAGE_GROUP "unknown") + endif() + + # CPACK_RPM_PACKAGE_VENDOR + if(NOT CPACK_RPM_PACKAGE_VENDOR) + if(CPACK_PACKAGE_VENDOR) + set(CPACK_RPM_PACKAGE_VENDOR "${CPACK_PACKAGE_VENDOR}") + else() + set(CPACK_RPM_PACKAGE_VENDOR "unknown") + endif() + endif() + + # CPACK_RPM_PACKAGE_SOURCE + # The name of the source tarball in case we generate a source RPM + + # CPACK_RPM_PACKAGE_DESCRIPTION + # The variable content may be either + # - explicitly given by the user or + # - filled with the content of CPACK_PACKAGE_DESCRIPTION_FILE + # if it is defined + # - set to a default value + # + + if(CPACK_RPM_PACKAGE_COMPONENT) + cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_DESCRIPTION" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_DESCRIPTION" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_DESCRIPTION" + "CPACK_COMPONENT_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DESCRIPTION") + endif() + + if(NOT CPACK_RPM_PACKAGE_DESCRIPTION) + if(CPACK_PACKAGE_DESCRIPTION_FILE) + file(READ ${CPACK_PACKAGE_DESCRIPTION_FILE} CPACK_RPM_PACKAGE_DESCRIPTION) + else () + set(CPACK_RPM_PACKAGE_DESCRIPTION "no package description available") + endif () + endif () + + # CPACK_RPM_COMPRESSION_TYPE + # + if (CPACK_RPM_COMPRESSION_TYPE) + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: User Specified RPM compression type: ${CPACK_RPM_COMPRESSION_TYPE}") + endif() + if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "lzma") + set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.lzdio") + endif() + if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "xz") + set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w7.xzdio") + endif() + if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "bzip2") + set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.bzdio") + endif() + if(CPACK_RPM_COMPRESSION_TYPE STREQUAL "gzip") + set(CPACK_RPM_COMPRESSION_TYPE_TMP "%define _binary_payload w9.gzdio") + endif() + else() + set(CPACK_RPM_COMPRESSION_TYPE_TMP "") + endif() + + if(NOT CPACK_RPM_PACKAGE_SOURCES) + if(CPACK_PACKAGE_RELOCATABLE OR CPACK_RPM_PACKAGE_RELOCATABLE) + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: Trying to build a relocatable package") + endif() + if(CPACK_SET_DESTDIR AND (NOT CPACK_SET_DESTDIR STREQUAL "I_ON")) + message("CPackRPM:Warning: CPACK_SET_DESTDIR is set (=${CPACK_SET_DESTDIR}) while requesting a relocatable package (CPACK_RPM_PACKAGE_RELOCATABLE is set): this is not supported, the package won't be relocatable.") + set(CPACK_RPM_PACKAGE_RELOCATABLE FALSE) + else() + set(CPACK_RPM_PACKAGE_PREFIX ${CPACK_PACKAGING_INSTALL_PREFIX}) # kept for back compatibility (provided external RPM spec files) + cpack_rpm_prepare_relocation_paths() + set(CPACK_RPM_PACKAGE_RELOCATABLE TRUE) + endif() + endif() + else() + if(CPACK_RPM_PACKAGE_COMPONENT) + message(FATAL_ERROR "CPACK_RPM_PACKAGE_SOURCES parameter can not be used" + " in combination with CPACK_RPM_PACKAGE_COMPONENT parameter!") + endif() + + set(CPACK_RPM_PACKAGE_RELOCATABLE FALSE) # disable relocatable option if building source RPM + endif() + + execute_process( + COMMAND "${RPMBUILD_EXECUTABLE}" --querytags + OUTPUT_VARIABLE RPMBUILD_TAG_LIST + OUTPUT_STRIP_TRAILING_WHITESPACE) + string(REPLACE "\n" ";" RPMBUILD_TAG_LIST "${RPMBUILD_TAG_LIST}") + + if(CPACK_RPM_PACKAGE_EPOCH) + set(TMP_RPM_EPOCH "Epoch: ${CPACK_RPM_PACKAGE_EPOCH}") + endif() + + # Check if additional fields for RPM spec header are given + # There may be some COMPONENT specific variables as well + # If component specific var is not provided we use the global one + # for each component + foreach(_RPM_SPEC_HEADER URL REQUIRES SUGGESTS PROVIDES OBSOLETES PREFIX CONFLICTS AUTOPROV AUTOREQ AUTOREQPROV REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN) + + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: processing ${_RPM_SPEC_HEADER}") + endif() + + if(CPACK_RPM_PACKAGE_COMPONENT) + cpack_rpm_variable_fallback("CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_PACKAGE_${_RPM_SPEC_HEADER}" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_PACKAGE_${_RPM_SPEC_HEADER}") + endif() + + if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}) + # Prefix can be replaced by Prefixes but the old version still works so we'll ignore it for now + # Requires* is a special case because it gets transformed to Requires(pre/post/preun/postun) + # Auto* is a special case because the tags can not be queried by querytags rpmbuild flag + set(special_case_tags_ PREFIX REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN AUTOPROV AUTOREQ AUTOREQPROV) + if(NOT _RPM_SPEC_HEADER IN_LIST RPMBUILD_TAG_LIST AND NOT _RPM_SPEC_HEADER IN_LIST special_case_tags_) + message(AUTHOR_WARNING "CPackRPM:Warning: ${_RPM_SPEC_HEADER} not " + "supported in provided rpmbuild. Tag will not be used.") + continue() + endif() + + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: using CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}") + endif() + + set(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}}) + endif() + + # Treat the RPM Spec keyword iff it has been properly defined + if(DEFINED CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP) + # Transform NAME --> Name e.g. PROVIDES --> Provides + # The Upper-case first letter and lowercase tail is the + # appropriate value required in the final RPM spec file. + string(SUBSTRING ${_RPM_SPEC_HEADER} 1 -1 _PACKAGE_HEADER_TAIL) + string(TOLOWER "${_PACKAGE_HEADER_TAIL}" _PACKAGE_HEADER_TAIL) + string(SUBSTRING ${_RPM_SPEC_HEADER} 0 1 _PACKAGE_HEADER_NAME) + string(APPEND _PACKAGE_HEADER_NAME "${_PACKAGE_HEADER_TAIL}") + # The following keywords require parentheses around the "pre" or "post" suffix in the final RPM spec file. + set(SCRIPTS_REQUIREMENTS_LIST REQUIRES_PRE REQUIRES_POST REQUIRES_PREUN REQUIRES_POSTUN) + list(FIND SCRIPTS_REQUIREMENTS_LIST ${_RPM_SPEC_HEADER} IS_SCRIPTS_REQUIREMENT_FOUND) + if(NOT ${IS_SCRIPTS_REQUIREMENT_FOUND} EQUAL -1) + string(REPLACE "_" "(" _PACKAGE_HEADER_NAME "${_PACKAGE_HEADER_NAME}") + string(APPEND _PACKAGE_HEADER_NAME ")") + endif() + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: User defined ${_PACKAGE_HEADER_NAME}:\n ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}") + endif() + set(TMP_RPM_${_RPM_SPEC_HEADER} "${_PACKAGE_HEADER_NAME}: ${CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP}") + unset(CPACK_RPM_PACKAGE_${_RPM_SPEC_HEADER}_TMP) + endif() + endforeach() + + # CPACK_RPM_SPEC_INSTALL_POST + # May be used to define a RPM post intallation script + # for example setting it to "/bin/true" may prevent + # rpmbuild from stripping binaries. + if(CPACK_RPM_SPEC_INSTALL_POST) + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: User defined CPACK_RPM_SPEC_INSTALL_POST = ${CPACK_RPM_SPEC_INSTALL_POST}") + endif() + set(TMP_RPM_SPEC_INSTALL_POST "%define __spec_install_post ${CPACK_RPM_SPEC_INSTALL_POST}") + endif() + + # CPACK_RPM_POST_INSTALL_SCRIPT_FILE (or CPACK_RPM__POST_INSTALL_SCRIPT_FILE) + # CPACK_RPM_POST_UNINSTALL_SCRIPT_FILE (or CPACK_RPM__POST_UNINSTALL_SCRIPT_FILE) + # May be used to embed a post (un)installation script in the spec file. + # The referred script file(s) will be read and directly + # put after the %post or %postun section + # ---------------------------------------------------------------- + # CPACK_RPM_PRE_INSTALL_SCRIPT_FILE (or CPACK_RPM__PRE_INSTALL_SCRIPT_FILE) + # CPACK_RPM_PRE_UNINSTALL_SCRIPT_FILE (or CPACK_RPM__PRE_UNINSTALL_SCRIPT_FILE) + # May be used to embed a pre (un)installation script in the spec file. + # The referred script file(s) will be read and directly + # put after the %pre or %preun section + foreach(RPM_SCRIPT_FILE_TYPE_ "INSTALL" "UNINSTALL") + foreach(RPM_SCRIPT_FILE_TIME_ "PRE" "POST") + set("CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE" + "${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE}") + + if(CPACK_RPM_PACKAGE_COMPONENT) + cpack_rpm_variable_fallback("CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE") + endif() + + # Handle file if it has been specified + if(CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE) + if(EXISTS ${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE}) + file(READ ${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE} + "CPACK_RPM_SPEC_${RPM_SCRIPT_FILE_TIME_}${RPM_SCRIPT_FILE_TYPE_}") + else() + message("CPackRPM:Warning: CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_SCRIPT_FILE <${CPACK_RPM_${RPM_SCRIPT_FILE_TIME_}_${RPM_SCRIPT_FILE_TYPE_}_READ_FILE}> does not exists - ignoring") + endif() + else() + # reset SPEC var value if no file has been specified + # (either globally or component-wise) + set("CPACK_RPM_SPEC_${RPM_SCRIPT_FILE_TIME_}${RPM_SCRIPT_FILE_TYPE_}" "") + endif() + endforeach() + endforeach() + + # CPACK_RPM_CHANGELOG_FILE + # May be used to embed a changelog in the spec file. + # The referred file will be read and directly put after the %changelog section + if(CPACK_RPM_CHANGELOG_FILE) + if(EXISTS ${CPACK_RPM_CHANGELOG_FILE}) + file(READ ${CPACK_RPM_CHANGELOG_FILE} CPACK_RPM_SPEC_CHANGELOG) + else() + message(SEND_ERROR "CPackRPM:Warning: CPACK_RPM_CHANGELOG_FILE <${CPACK_RPM_CHANGELOG_FILE}> does not exists - ignoring") + endif() + else() + set(CPACK_RPM_SPEC_CHANGELOG "* Sun Jul 4 2010 Eric Noulard - ${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}\n Generated by CPack RPM (no Changelog file were provided)") + endif() + + # CPACK_RPM_SPEC_MORE_DEFINE + # This is a generated spec rpm file spaceholder + if(CPACK_RPM_SPEC_MORE_DEFINE) + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: User defined more define spec line specified:\n ${CPACK_RPM_SPEC_MORE_DEFINE}") + endif() + endif() + + # Now we may create the RPM build tree structure + set(CPACK_RPM_ROOTDIR "${CPACK_TOPLEVEL_DIRECTORY}") + message(STATUS "CPackRPM:Debug: Using CPACK_RPM_ROOTDIR=${CPACK_RPM_ROOTDIR}") + # Prepare RPM build tree + file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}) + file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/tmp) + file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/BUILD) + file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/RPMS) + file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SOURCES) + file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SPECS) + file(MAKE_DIRECTORY ${CPACK_RPM_ROOTDIR}/SRPMS) + + # it seems rpmbuild can't handle spaces in the path + # neither escaping (as below) nor putting quotes around the path seem to help + #string(REGEX REPLACE " " "\\\\ " CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}") + set(CPACK_RPM_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}") + + cpack_rpm_prepare_content_list() + + # In component case, put CPACK_ABSOLUTE_DESTINATION_FILES_ + # into CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL + # otherwise, put CPACK_ABSOLUTE_DESTINATION_FILES + # This must be done BEFORE the CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL handling + if(CPACK_RPM_PACKAGE_COMPONENT) + if(CPACK_ABSOLUTE_DESTINATION_FILES) + cpack_rpm_variable_fallback("COMPONENT_FILES_TAG" + "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT}" + "CPACK_ABSOLUTE_DESTINATION_FILES_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}") + set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${${COMPONENT_FILES_TAG}}") + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: Handling Absolute Destination Files: <${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}>") + message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}") + endif() + endif() + else() + if(CPACK_ABSOLUTE_DESTINATION_FILES) + set(CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL "${CPACK_ABSOLUTE_DESTINATION_FILES}") + endif() + endif() + + # In component case, set CPACK_RPM_USER_FILELIST_INTERNAL with CPACK_RPM__USER_FILELIST. + set(CPACK_RPM_USER_FILELIST_INTERNAL "") + if(CPACK_RPM_PACKAGE_COMPONENT) + cpack_rpm_variable_fallback("CPACK_RPM_USER_FILELIST_INTERNAL" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_FILELIST" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_USER_FILELIST") + + if(CPACK_RPM_PACKAGE_DEBUG AND CPACK_RPM_USER_FILELIST_INTERNAL) + message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>") + message("CPackRPM:Debug: in component = ${CPACK_RPM_PACKAGE_COMPONENT}") + endif() + elseif(CPACK_RPM_USER_FILELIST) + set(CPACK_RPM_USER_FILELIST_INTERNAL "${CPACK_RPM_USER_FILELIST}") + endif() + + # Handle user specified file line list in CPACK_RPM_USER_FILELIST_INTERNAL + # Remove those files from CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL + # or CPACK_RPM_INSTALL_FILES, + # hence it must be done before these auto-generated lists are processed. + if(CPACK_RPM_USER_FILELIST_INTERNAL) + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: Handling User Filelist: <${CPACK_RPM_USER_FILELIST_INTERNAL}>") + endif() + + # Create CMake list from CPACK_RPM_INSTALL_FILES + string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST) + string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST + "${CPACK_RPM_INSTALL_FILES_LIST}") + string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST + "${CPACK_RPM_INSTALL_FILES_LIST}") + + set(CPACK_RPM_USER_INSTALL_FILES "") + foreach(F IN LISTS CPACK_RPM_USER_FILELIST_INTERNAL) + string(REGEX REPLACE "%[A-Za-z]+(\\([^()]*\\))? " "" F_PATH ${F}) + string(REGEX MATCH "(%[A-Za-z]+(\\([^()]*\\))? )*" F_PREFIX ${F}) + string(STRIP ${F_PREFIX} F_PREFIX) + + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: F_PREFIX=<${F_PREFIX}>, F_PATH=<${F_PATH}>") + endif() + if(F_PREFIX) + string(APPEND F_PREFIX " ") + endif() + # Rebuild the user list file + string(APPEND CPACK_RPM_USER_INSTALL_FILES "${F_PREFIX}\"${F_PATH}\"\n") + + # Remove from CPACK_RPM_INSTALL_FILES and CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL + list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${F_PATH}) + # ABSOLUTE destination files list may not exists at all + if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL) + list(REMOVE_ITEM CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL ${F_PATH}) + endif() + endforeach() + + # Rebuild CPACK_RPM_INSTALL_FILES + set(CPACK_RPM_INSTALL_FILES "") + foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST) + string(APPEND CPACK_RPM_INSTALL_FILES "\"${F}\"\n") + endforeach() + else() + set(CPACK_RPM_USER_INSTALL_FILES "") + endif() + + if (CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL) + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: Handling Absolute Destination Files: ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}") + endif() + # Remove trailing space + string(STRIP "${CPACK_RPM_INSTALL_FILES}" CPACK_RPM_INSTALL_FILES_LIST) + # Transform endline separated - string into CMake List + string(REPLACE "\n" ";" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}") + # Remove unnecessary quotes + string(REPLACE "\"" "" CPACK_RPM_INSTALL_FILES_LIST "${CPACK_RPM_INSTALL_FILES_LIST}") + # Remove ABSOLUTE install file from INSTALL FILE LIST + list(REMOVE_ITEM CPACK_RPM_INSTALL_FILES_LIST ${CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL}) + # Rebuild INSTALL_FILES + set(CPACK_RPM_INSTALL_FILES "") + foreach(F IN LISTS CPACK_RPM_INSTALL_FILES_LIST) + string(APPEND CPACK_RPM_INSTALL_FILES "\"${F}\"\n") + endforeach() + # Build ABSOLUTE_INSTALL_FILES + set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "") + foreach(F IN LISTS CPACK_ABSOLUTE_DESTINATION_FILES_INTERNAL) + string(APPEND CPACK_RPM_ABSOLUTE_INSTALL_FILES "%config \"${F}\"\n") + endforeach() + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: CPACK_RPM_ABSOLUTE_INSTALL_FILES=${CPACK_RPM_ABSOLUTE_INSTALL_FILES}") + message("CPackRPM:Debug: CPACK_RPM_INSTALL_FILES=${CPACK_RPM_INSTALL_FILES}") + endif() + else() + # reset vars in order to avoid leakage of value(s) from one component to another + set(CPACK_RPM_ABSOLUTE_INSTALL_FILES "") + endif() + + cpack_rpm_variable_fallback("CPACK_RPM_DEBUGINFO_PACKAGE" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_DEBUGINFO_PACKAGE" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEBUGINFO_PACKAGE" + "CPACK_RPM_DEBUGINFO_PACKAGE") + if(CPACK_RPM_DEBUGINFO_PACKAGE OR (CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND NOT GENERATE_SPEC_PARTS)) + cpack_rpm_variable_fallback("CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_BUILD_SOURCE_DIRS_PREFIX" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_BUILD_SOURCE_DIRS_PREFIX" + "CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX") + if(NOT CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX) + set(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX "/usr/src/debug/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}") + endif() + + # handle cases where path contains extra slashes (e.g. /a//b/ instead of + # /a/b) + get_filename_component(CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX + "${CPACK_RPM_BUILD_SOURCE_DIRS_PREFIX}" ABSOLUTE) + + if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND GENERATE_SPEC_PARTS) + file(WRITE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_COMPONENT}.files" + "${CPACK_RPM_INSTALL_FILES}") + else() + if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND CPACK_RPM_PACKAGE_COMPONENT) + # this part is only required by components packaging - with monolithic + # packages we can be certain that there are no other components present + # so CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE is a noop + if(CPACK_RPM_DEBUGINFO_PACKAGE) + # only add current package files to debuginfo list if debuginfo + # generation is enabled for current package + string(STRIP "${CPACK_RPM_INSTALL_FILES}" install_files_) + string(REPLACE "\n" ";" install_files_ "${install_files_}") + string(REPLACE "\"" "" install_files_ "${install_files_}") + else() + unset(install_files_) + endif() + + file(GLOB files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.files") + + foreach(f_ IN LISTS files_) + file(READ "${f_}" tmp_) + string(APPEND install_files_ ";${tmp_}") + endforeach() + + # if there were other components/groups so we need to move files from them + # to current component otherwise those files won't be found + file(GLOB components_ LIST_DIRECTORIES true RELATIVE + "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}" + "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/*") + foreach(component_ IN LISTS components_) + string(TOUPPER "${component_}" component_dir_upper_) + if(component_dir_upper_ STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER) + # skip current component + continue() + endif() + + file(GLOB_RECURSE files_for_move_ LIST_DIRECTORIES false RELATIVE + "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}" + "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}/*") + + foreach(f_ IN LISTS files_for_move_) + get_filename_component(dir_path_ "${f_}" DIRECTORY) + set(src_file_ + "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}/${component_}/${f_}") + + # check that we are not overriding an existing file that doesn't + # match the file that we want to copy + if(EXISTS "${src_file_}" AND EXISTS "${WDIR}/${f_}") + execute_process( + COMMAND ${CMAKE_COMMAND} -E compare_files "${src_file_}" "${WDIR}/${f_}" + RESULT_VARIABLE res_ + ) + if(res_) + message(FATAL_ERROR "CPackRPM:Error: File on path '${WDIR}/${f_}'" + " already exists but is a different than the one in component" + " '${component_}'! Packages will not be generated.") + endif() + endif() + + file(MAKE_DIRECTORY "${WDIR}/${dir_path_}") + file(RENAME "${src_file_}" + "${WDIR}/${f_}") + endforeach() + endforeach() + + cpack_rpm_debugsymbol_check("${install_files_}" "${WDIR}") + else() + string(STRIP "${CPACK_RPM_INSTALL_FILES}" install_files_) + string(REPLACE "\n" ";" install_files_ "${install_files_}") + string(REPLACE "\"" "" install_files_ "${install_files_}") + + cpack_rpm_debugsymbol_check("${install_files_}" "${WDIR}") + endif() + + if(TMP_DEBUGINFO_ADDITIONAL_SOURCES) + set(TMP_RPM_DEBUGINFO " +# Modified version of %%debug_package macro +# defined in /usr/lib/rpm/macros as that one +# can't handle injection of extra source files. +%ifnarch noarch +%global __debug_package 1 +%package debuginfo +Summary: Debug information for package %{name} +Group: Development/Debug +AutoReqProv: 0 +%description debuginfo +This package provides debug information for package %{name}. +Debug information is useful when developing applications that use this +package or when debugging this package. +%files debuginfo -f debugfiles.list +%defattr(-,root,root) +${TMP_DEBUGINFO_ADDITIONAL_SOURCES} +%endif +") + elseif(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE) + message(AUTHOR_WARNING "CPackRPM:Warning: debuginfo package was requested" + " but will not be generated as no source files were found!") + else() + message(AUTHOR_WARNING "CPackRPM:Warning: debuginfo package was requested" + " but will not be generated as no source files were found! Component: '" + "${CPACK_RPM_PACKAGE_COMPONENT}'.") + endif() + endif() + endif() + + # Prepare install files + cpack_rpm_prepare_install_files( + "${CPACK_RPM_INSTALL_FILES}" + "${WDIR}" + "${RPM_USED_PACKAGE_PREFIXES}" + "${CPACK_RPM_PACKAGE_RELOCATABLE}" + ) + + # set default user and group + foreach(_PERM_TYPE "USER" "GROUP") + if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}) + set(TMP_DEFAULT_${_PERM_TYPE} "${CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}}") + elseif(CPACK_RPM_DEFAULT_${_PERM_TYPE}) + set(TMP_DEFAULT_${_PERM_TYPE} "${CPACK_RPM_DEFAULT_${_PERM_TYPE}}") + else() + set(TMP_DEFAULT_${_PERM_TYPE} "root") + endif() + endforeach() + + # set default file and dir permissions + foreach(_PERM_TYPE "FILE" "DIR") + if(CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS) + get_unix_permissions_octal_notation("CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS" "TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS") + set(_PERMISSIONS_VAR "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEFAULT_${_PERM_TYPE}_PERMISSIONS") + elseif(CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS) + get_unix_permissions_octal_notation("CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS" "TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS") + set(_PERMISSIONS_VAR "CPACK_RPM_DEFAULT_${_PERM_TYPE}_PERMISSIONS") + else() + set(TMP_DEFAULT_${_PERM_TYPE}_PERMISSIONS "-") + endif() + endforeach() + + # The name of the final spec file to be used by rpmbuild + set(CPACK_RPM_BINARY_SPECFILE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_NAME}.spec") + + # Print out some debug information if we were asked for that + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: CPACK_TOPLEVEL_DIRECTORY = ${CPACK_TOPLEVEL_DIRECTORY}") + message("CPackRPM:Debug: CPACK_TOPLEVEL_TAG = ${CPACK_TOPLEVEL_TAG}") + message("CPackRPM:Debug: CPACK_TEMPORARY_DIRECTORY = ${CPACK_TEMPORARY_DIRECTORY}") + message("CPackRPM:Debug: CPACK_OUTPUT_FILE_NAME = ${CPACK_OUTPUT_FILE_NAME}") + message("CPackRPM:Debug: CPACK_OUTPUT_FILE_PATH = ${CPACK_OUTPUT_FILE_PATH}") + message("CPackRPM:Debug: CPACK_PACKAGE_FILE_NAME = ${CPACK_PACKAGE_FILE_NAME}") + message("CPackRPM:Debug: CPACK_RPM_BINARY_SPECFILE = ${CPACK_RPM_BINARY_SPECFILE}") + message("CPackRPM:Debug: CPACK_PACKAGE_INSTALL_DIRECTORY = ${CPACK_PACKAGE_INSTALL_DIRECTORY}") + message("CPackRPM:Debug: CPACK_TEMPORARY_PACKAGE_FILE_NAME = ${CPACK_TEMPORARY_PACKAGE_FILE_NAME}") + endif() + + # + # USER generated/provided spec file handling. + # + + # We can have a component specific spec file. + if(CPACK_RPM_PACKAGE_COMPONENT) + cpack_rpm_variable_fallback("CPACK_RPM_USER_BINARY_SPECFILE" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_USER_BINARY_SPECFILE" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_USER_BINARY_SPECFILE") + endif() + + cpack_rpm_variable_fallback("CPACK_RPM_FILE_NAME" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_FILE_NAME" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_FILE_NAME" + "CPACK_RPM_FILE_NAME") + if(NOT CPACK_RPM_FILE_NAME STREQUAL "RPM-DEFAULT") + if(CPACK_RPM_FILE_NAME) + if(NOT CPACK_RPM_FILE_NAME MATCHES ".*\\.rpm") + message(FATAL_ERROR "'${CPACK_RPM_FILE_NAME}' is not a valid RPM package file name as it must end with '.rpm'!") + endif() + else() + # old file name format for back compatibility + string(TOUPPER "${CPACK_RPM_MAIN_COMPONENT}" + CPACK_RPM_MAIN_COMPONENT_UPPER) + + if(CPACK_RPM_MAIN_COMPONENT_UPPER STREQUAL CPACK_RPM_PACKAGE_COMPONENT_UPPER) + # this is the main component so ignore the component filename part + set(CPACK_RPM_FILE_NAME "${CPACK_PACKAGE_FILE_NAME}.rpm") + else() + set(CPACK_RPM_FILE_NAME "${CPACK_OUTPUT_FILE_NAME}") + endif() + endif() + # else example: + #set(CPACK_RPM_FILE_NAME "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}-${CPACK_RPM_PACKAGE_RELEASE}-${CPACK_RPM_PACKAGE_ARCHITECTURE}.rpm") + + if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE AND GENERATE_SPEC_PARTS) + string(TOLOWER "${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.*\\.rpm" expected_filename_) + + file(WRITE "${CPACK_RPM_ROOTDIR}/SPECS/${CPACK_RPM_PACKAGE_COMPONENT}.rpm_name" + "${expected_filename_};${CPACK_RPM_FILE_NAME}") + elseif(NOT CPACK_RPM_DEBUGINFO_PACKAGE) + set(FILE_NAME_DEFINE "%define _rpmfilename ${CPACK_RPM_FILE_NAME}") + endif() + endif() + + if(CPACK_RPM_PACKAGE_SOURCES) # source rpm + set(archive_name_ "${CPACK_RPM_PACKAGE_NAME}-${CPACK_RPM_PACKAGE_VERSION}") + + execute_process( + COMMAND ${CMAKE_COMMAND} -E tar "cfvz" "${CPACK_RPM_DIRECTORY}/SOURCES/${archive_name_}.tar.gz" "${CPACK_PACKAGE_FILE_NAME}" + WORKING_DIRECTORY ${CPACK_RPM_DIRECTORY} + ) + set(TMP_RPM_SOURCE "Source: ${archive_name_}.tar.gz") + + if(CPACK_RPM_BUILDREQUIRES) + set(TMP_RPM_BUILD_REQUIRES "BuildRequires: ${CPACK_RPM_BUILDREQUIRES}") + endif() + + # Disable debuginfo packages - srpm generates invalid packages due to + # releasing control to cpack to generate binary packages. + # Note however that this doesn't prevent cpack to generate debuginfo + # packages when run from srpm with --rebuild. + set(TMP_RPM_DISABLE_DEBUGINFO "%define debug_package %{nil}") + + if(NOT CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX) + set(CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX "/") + endif() + + set(TMP_RPM_BUILD + " +%build +mkdir cpack_rpm_build_dir +cd cpack_rpm_build_dir +cmake ${CPACK_RPM_SOURCE_PKG_BUILD_PARAMS} -DCPACK_PACKAGING_INSTALL_PREFIX=${CPACK_RPM_SOURCE_PKG_PACKAGING_INSTALL_PREFIX} ../${CPACK_PACKAGE_FILE_NAME} +make %{?_smp_mflags}" # %{?_smp_mflags} -> -j option + ) + set(TMP_RPM_INSTALL + " +cd cpack_rpm_build_dir +cpack -G RPM +mv *.rpm %_rpmdir" + ) + set(TMP_RPM_PREP "%setup -c") + + set(RPMBUILD_FLAGS "-bs") + + file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in + "# Restore old style debuginfo creation for rpm >= 4.14. +%undefine _debugsource_packages +%undefine _debuginfo_subpackages + +# -*- rpm-spec -*- +BuildRoot: %_topdir/\@CPACK_PACKAGE_FILE_NAME\@ +Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@ +Name: \@CPACK_RPM_PACKAGE_NAME\@ +Version: \@CPACK_RPM_PACKAGE_VERSION\@ +Release: \@CPACK_RPM_PACKAGE_RELEASE\@ +License: \@CPACK_RPM_PACKAGE_LICENSE\@ +Group: \@CPACK_RPM_PACKAGE_GROUP\@ +Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@ + +\@TMP_RPM_SOURCE\@ +\@TMP_RPM_BUILD_REQUIRES\@ +\@TMP_RPM_BUILDARCH\@ +\@TMP_RPM_PREFIXES\@ + +\@TMP_RPM_DISABLE_DEBUGINFO\@ + +%define _rpmdir %_topdir/RPMS +%define _srcrpmdir %_topdir/SRPMS +\@FILE_NAME_DEFINE\@ +%define _unpackaged_files_terminate_build 0 +\@TMP_RPM_SPEC_INSTALL_POST\@ +\@CPACK_RPM_SPEC_MORE_DEFINE\@ +\@CPACK_RPM_COMPRESSION_TYPE_TMP\@ + +%description +\@CPACK_RPM_PACKAGE_DESCRIPTION\@ + +# This is a shortcutted spec file generated by CMake RPM generator +# we skip _install step because CPack does that for us. +# We do only save CPack installed tree in _prepr +# and then restore it in build. +%prep +\@TMP_RPM_PREP\@ + +\@TMP_RPM_BUILD\@ + +#p build + +%install +\@TMP_RPM_INSTALL\@ + +%clean + +%changelog +\@CPACK_RPM_SPEC_CHANGELOG\@ +" + ) + + elseif(GENERATE_SPEC_PARTS) # binary rpm with single debuginfo package + file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in + "# -*- rpm-spec -*- +%package -n \@CPACK_RPM_PACKAGE_NAME\@ +Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@ +Version: \@CPACK_RPM_PACKAGE_VERSION\@ +Release: \@CPACK_RPM_PACKAGE_RELEASE\@ +License: \@CPACK_RPM_PACKAGE_LICENSE\@ +Group: \@CPACK_RPM_PACKAGE_GROUP\@ +Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@ + +\@TMP_RPM_URL\@ +\@TMP_RPM_REQUIRES\@ +\@TMP_RPM_REQUIRES_PRE\@ +\@TMP_RPM_REQUIRES_POST\@ +\@TMP_RPM_REQUIRES_PREUN\@ +\@TMP_RPM_REQUIRES_POSTUN\@ +\@TMP_RPM_PROVIDES\@ +\@TMP_RPM_OBSOLETES\@ +\@TMP_RPM_CONFLICTS\@ +\@TMP_RPM_SUGGESTS\@ +\@TMP_RPM_AUTOPROV\@ +\@TMP_RPM_AUTOREQ\@ +\@TMP_RPM_AUTOREQPROV\@ +\@TMP_RPM_BUILDARCH\@ +\@TMP_RPM_PREFIXES\@ +\@TMP_RPM_EPOCH\@ + +%description -n \@CPACK_RPM_PACKAGE_NAME\@ +\@CPACK_RPM_PACKAGE_DESCRIPTION\@ + +%files -n \@CPACK_RPM_PACKAGE_NAME\@ +%defattr(\@TMP_DEFAULT_FILE_PERMISSIONS\@,\@TMP_DEFAULT_USER\@,\@TMP_DEFAULT_GROUP\@,\@TMP_DEFAULT_DIR_PERMISSIONS\@) +\@CPACK_RPM_INSTALL_FILES\@ +\@CPACK_RPM_ABSOLUTE_INSTALL_FILES\@ +\@CPACK_RPM_USER_INSTALL_FILES\@ +" + ) + + else() # binary rpm + if(CPACK_RPM_DEBUGINFO_SINGLE_PACKAGE) + # find generated spec file and take its name + file(GLOB spec_files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.spec") + + foreach(f_ IN LISTS spec_files_) + file(READ "${f_}" tmp_) + string(APPEND TMP_OTHER_COMPONENTS "\n${tmp_}\n") + endforeach() + endif() + + # We should generate a USER spec file template: + # - either because the user asked for it : CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE + # - or the user did not provide one : NOT CPACK_RPM_USER_BINARY_SPECFILE + set(RPMBUILD_FLAGS "-bb") + if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE OR NOT CPACK_RPM_USER_BINARY_SPECFILE) + + file(WRITE ${CPACK_RPM_BINARY_SPECFILE}.in + "# Restore old style debuginfo creation for rpm >= 4.14. +%undefine _debugsource_packages +%undefine _debuginfo_subpackages + +# -*- rpm-spec -*- +BuildRoot: %_topdir/\@CPACK_PACKAGE_FILE_NAME\@\@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH\@ +Summary: \@CPACK_RPM_PACKAGE_SUMMARY\@ +Name: \@CPACK_RPM_PACKAGE_NAME\@ +Version: \@CPACK_RPM_PACKAGE_VERSION\@ +Release: \@CPACK_RPM_PACKAGE_RELEASE\@ +License: \@CPACK_RPM_PACKAGE_LICENSE\@ +Group: \@CPACK_RPM_PACKAGE_GROUP\@ +Vendor: \@CPACK_RPM_PACKAGE_VENDOR\@ + +\@TMP_RPM_URL\@ +\@TMP_RPM_REQUIRES\@ +\@TMP_RPM_REQUIRES_PRE\@ +\@TMP_RPM_REQUIRES_POST\@ +\@TMP_RPM_REQUIRES_PREUN\@ +\@TMP_RPM_REQUIRES_POSTUN\@ +\@TMP_RPM_PROVIDES\@ +\@TMP_RPM_OBSOLETES\@ +\@TMP_RPM_CONFLICTS\@ +\@TMP_RPM_SUGGESTS\@ +\@TMP_RPM_AUTOPROV\@ +\@TMP_RPM_AUTOREQ\@ +\@TMP_RPM_AUTOREQPROV\@ +\@TMP_RPM_BUILDARCH\@ +\@TMP_RPM_PREFIXES\@ +\@TMP_RPM_EPOCH\@ + +\@TMP_RPM_DEBUGINFO\@ + +%define _rpmdir %_topdir/RPMS +%define _srcrpmdir %_topdir/SRPMS +\@FILE_NAME_DEFINE\@ +%define _unpackaged_files_terminate_build 0 +\@TMP_RPM_SPEC_INSTALL_POST\@ +\@CPACK_RPM_SPEC_MORE_DEFINE\@ +\@CPACK_RPM_COMPRESSION_TYPE_TMP\@ + +%description +\@CPACK_RPM_PACKAGE_DESCRIPTION\@ + +# This is a shortcutted spec file generated by CMake RPM generator +# we skip _install step because CPack does that for us. +# We do only save CPack installed tree in _prepr +# and then restore it in build. +%prep +mv $RPM_BUILD_ROOT %_topdir/tmpBBroot + +%install +if [ -e $RPM_BUILD_ROOT ]; +then + rm -rf $RPM_BUILD_ROOT +fi +mv %_topdir/tmpBBroot $RPM_BUILD_ROOT + +\@TMP_RPM_DEBUGINFO_INSTALL\@ + +%clean + +%post +\@RPM_SYMLINK_POSTINSTALL\@ +\@CPACK_RPM_SPEC_POSTINSTALL\@ + +%postun +\@CPACK_RPM_SPEC_POSTUNINSTALL\@ + +%pre +\@CPACK_RPM_SPEC_PREINSTALL\@ + +%preun +\@CPACK_RPM_SPEC_PREUNINSTALL\@ + +%files +%defattr(\@TMP_DEFAULT_FILE_PERMISSIONS\@,\@TMP_DEFAULT_USER\@,\@TMP_DEFAULT_GROUP\@,\@TMP_DEFAULT_DIR_PERMISSIONS\@) +\@CPACK_RPM_INSTALL_FILES\@ +\@CPACK_RPM_ABSOLUTE_INSTALL_FILES\@ +\@CPACK_RPM_USER_INSTALL_FILES\@ + +%changelog +\@CPACK_RPM_SPEC_CHANGELOG\@ + +\@TMP_OTHER_COMPONENTS\@ +" + ) + endif() + + # Stop here if we were asked to only generate a template USER spec file + # The generated file may then be used as a template by user who wants + # to customize their own spec file. + if(CPACK_RPM_GENERATE_USER_BINARY_SPECFILE_TEMPLATE) + message(FATAL_ERROR "CPackRPM: STOP here Generated USER binary spec file template is: ${CPACK_RPM_BINARY_SPECFILE}.in") + endif() + endif() + + # After that we may either use a user provided spec file + # or generate one using appropriate variables value. + if(CPACK_RPM_USER_BINARY_SPECFILE) + # User may have specified SPECFILE just use it + message("CPackRPM: Will use USER specified spec file: ${CPACK_RPM_USER_BINARY_SPECFILE}") + # The user provided file is processed for @var replacement + configure_file(${CPACK_RPM_USER_BINARY_SPECFILE} ${CPACK_RPM_BINARY_SPECFILE} @ONLY) + else() + # No User specified spec file, will use the generated spec file + message("CPackRPM: Will use GENERATED spec file: ${CPACK_RPM_BINARY_SPECFILE}") + # Note the just created file is processed for @var replacement + configure_file(${CPACK_RPM_BINARY_SPECFILE}.in ${CPACK_RPM_BINARY_SPECFILE} @ONLY) + endif() + + if(NOT GENERATE_SPEC_PARTS) # generate package + if(RPMBUILD_EXECUTABLE) + # Now call rpmbuild using the SPECFILE + execute_process( + COMMAND "${RPMBUILD_EXECUTABLE}" ${RPMBUILD_FLAGS} + --define "_topdir ${CPACK_RPM_DIRECTORY}" + --buildroot "%_topdir/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}" + --target "${CPACK_RPM_PACKAGE_ARCHITECTURE}" + "${CPACK_RPM_BINARY_SPECFILE}" + WORKING_DIRECTORY "${CPACK_TOPLEVEL_DIRECTORY}/${CPACK_PACKAGE_FILE_NAME}${CPACK_RPM_PACKAGE_COMPONENT_PART_PATH}" + RESULT_VARIABLE CPACK_RPMBUILD_EXEC_RESULT + ERROR_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err" + OUTPUT_FILE "${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out") + if(CPACK_RPM_PACKAGE_DEBUG OR CPACK_RPMBUILD_EXEC_RESULT) + file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err RPMBUILDERR) + file(READ ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out RPMBUILDOUT) + message("CPackRPM:Debug: You may consult rpmbuild logs in: ") + message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.err") + message("CPackRPM:Debug: *** ${RPMBUILDERR} ***") + message("CPackRPM:Debug: - ${CPACK_TOPLEVEL_DIRECTORY}/rpmbuild${CPACK_RPM_PACKAGE_NAME}.out") + message("CPackRPM:Debug: *** ${RPMBUILDOUT} ***") + endif() + else() + if(ALIEN_EXECUTABLE) + message(FATAL_ERROR "RPM packaging through alien not done (yet)") + endif() + endif() + + # find generated rpm files and take their names + file(GLOB_RECURSE GENERATED_FILES "${CPACK_RPM_DIRECTORY}/RPMS/*.rpm" + "${CPACK_RPM_DIRECTORY}/SRPMS/*.rpm") + + if(NOT GENERATED_FILES) + message(FATAL_ERROR "RPM package was not generated! ${CPACK_RPM_DIRECTORY}") + endif() + + unset(expected_filenames_) + unset(filenames_) + if(CPACK_RPM_DEBUGINFO_PACKAGE AND NOT CPACK_RPM_FILE_NAME STREQUAL "RPM-DEFAULT") + list(APPEND expected_filenames_ + "${CPACK_RPM_PACKAGE_NAME}-${CPACK_PACKAGE_VERSION}.*\\.rpm") + list(APPEND filenames_ "${CPACK_RPM_FILE_NAME}") + endif() + + if(CPACK_RPM_DEBUGINFO_PACKAGE) + cpack_rpm_variable_fallback("CPACK_RPM_DEBUGINFO_FILE_NAME" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT}_DEBUGINFO_FILE_NAME" + "CPACK_RPM_${CPACK_RPM_PACKAGE_COMPONENT_UPPER}_DEBUGINFO_FILE_NAME" + "CPACK_RPM_DEBUGINFO_FILE_NAME") + + if(CPACK_RPM_DEBUGINFO_FILE_NAME AND + NOT CPACK_RPM_DEBUGINFO_FILE_NAME STREQUAL "RPM-DEFAULT") + list(APPEND expected_filenames_ + "${CPACK_RPM_PACKAGE_NAME}-debuginfo-${CPACK_PACKAGE_VERSION}.*\\.rpm") + string(REPLACE "@cpack_component@" "${CPACK_RPM_PACKAGE_COMPONENT}" + CPACK_RPM_DEBUGINFO_FILE_NAME "${CPACK_RPM_DEBUGINFO_FILE_NAME}") + list(APPEND filenames_ "${CPACK_RPM_DEBUGINFO_FILE_NAME}") + endif() + endif() + + # check if other files have to be renamed + file(GLOB rename_files_ "${CPACK_RPM_DIRECTORY}/SPECS/*.rpm_name") + if(rename_files_) + foreach(f_ IN LISTS rename_files_) + file(READ "${f_}" tmp_) + list(GET tmp_ 0 efn_) + list(APPEND expected_filenames_ "${efn_}") + list(GET tmp_ 1 fn_) + list(APPEND filenames_ "${fn_}") + endforeach() + endif() + + if(expected_filenames_) + foreach(F IN LISTS GENERATED_FILES) + unset(matched_) + foreach(expected_ IN LISTS expected_filenames_) + if(F MATCHES ".*/${expected_}") + list(FIND expected_filenames_ "${expected_}" idx_) + list(GET filenames_ ${idx_} filename_) + get_filename_component(FILE_PATH "${F}" DIRECTORY) + file(RENAME "${F}" "${FILE_PATH}/${filename_}") + list(APPEND new_files_list_ "${FILE_PATH}/${filename_}") + set(matched_ "YES") + + break() + endif() + endforeach() + + if(NOT matched_) + list(APPEND new_files_list_ "${F}") + endif() + endforeach() + + set(GENERATED_FILES "${new_files_list_}") + endif() + endif() + + set(GEN_CPACK_OUTPUT_FILES "${GENERATED_FILES}" PARENT_SCOPE) + + if(CPACK_RPM_PACKAGE_DEBUG) + message("CPackRPM:Debug: GEN_CPACK_OUTPUT_FILES = ${GENERATED_FILES}") + endif() +endfunction() + +cpack_rpm_generate_package() diff --git a/Modules/Internal/CPack/CPackWIX.cmake b/Modules/Internal/CPack/CPackWIX.cmake new file mode 100644 index 0000000..d1875f2 --- /dev/null +++ b/Modules/Internal/CPack/CPackWIX.cmake @@ -0,0 +1,20 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + +if(NOT CPACK_WIX_ROOT) + string(REPLACE "\\" "/" CPACK_WIX_ROOT "$ENV{WIX}") +endif() + +find_program(CPACK_WIX_CANDLE_EXECUTABLE candle + PATHS "${CPACK_WIX_ROOT}" PATH_SUFFIXES "bin") + +if(NOT CPACK_WIX_CANDLE_EXECUTABLE) + message(FATAL_ERROR "Could not find the WiX candle executable.") +endif() + +find_program(CPACK_WIX_LIGHT_EXECUTABLE light + PATHS "${CPACK_WIX_ROOT}" PATH_SUFFIXES "bin") + +if(NOT CPACK_WIX_LIGHT_EXECUTABLE) + message(FATAL_ERROR "Could not find the WiX light executable.") +endif() diff --git a/Modules/Internal/CPack/CPackZIP.cmake b/Modules/Internal/CPack/CPackZIP.cmake new file mode 100644 index 0000000..f619de4 --- /dev/null +++ b/Modules/Internal/CPack/CPackZIP.cmake @@ -0,0 +1,30 @@ +# Distributed under the OSI-approved BSD 3-Clause License. See accompanying +# file Copyright.txt or https://cmake.org/licensing for details. + + +if(CMAKE_BINARY_DIR) + message(FATAL_ERROR "CPackZIP.cmake may only be used by CPack internally.") +endif() + +find_program(ZIP_EXECUTABLE wzzip PATHS "$ENV{ProgramFiles}/WinZip") +if(ZIP_EXECUTABLE) + set(CPACK_ZIP_COMMAND "\"${ZIP_EXECUTABLE}\" -P \"\" @") + set(CPACK_ZIP_NEED_QUOTES TRUE) +endif() + +if(NOT ZIP_EXECUTABLE) + find_program(ZIP_EXECUTABLE 7z PATHS "$ENV{ProgramFiles}/7-Zip") + if(ZIP_EXECUTABLE) + set(CPACK_ZIP_COMMAND "\"${ZIP_EXECUTABLE}\" a -tzip \"\" @") + set(CPACK_ZIP_NEED_QUOTES TRUE) + endif() +endif() + +if(NOT ZIP_EXECUTABLE) + find_package(Cygwin) + find_program(ZIP_EXECUTABLE zip PATHS "${CYGWIN_INSTALL_PATH}/bin") + if(ZIP_EXECUTABLE) + set(CPACK_ZIP_COMMAND "\"${ZIP_EXECUTABLE}\" -r \"\" . -i@") + set(CPACK_ZIP_NEED_QUOTES FALSE) + endif() +endif() diff --git a/Source/CPack/WiX/cmCPackWIXGenerator.cxx b/Source/CPack/WiX/cmCPackWIXGenerator.cxx index e06efda..382b189 100644 --- a/Source/CPack/WiX/cmCPackWIXGenerator.cxx +++ b/Source/CPack/WiX/cmCPackWIXGenerator.cxx @@ -148,7 +148,7 @@ int cmCPackWIXGenerator::PackageFiles() bool cmCPackWIXGenerator::InitializeWiXConfiguration() { - if (!ReadListFile("CPackWIX.cmake")) { + if (!ReadListFile("Internal/CPack/CPackWIX.cmake")) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while executing CPackWIX.cmake" << std::endl); return false; diff --git a/Source/CPack/cmCPackDebGenerator.cxx b/Source/CPack/cmCPackDebGenerator.cxx index 93cdf41..50499aa 100644 --- a/Source/CPack/cmCPackDebGenerator.cxx +++ b/Source/CPack/cmCPackDebGenerator.cxx @@ -61,7 +61,7 @@ int cmCPackDebGenerator::PackageOnePack(std::string const& initialTopLevel, component_path += packageName; this->SetOption("CPACK_DEB_PACKAGE_COMPONENT_PART_PATH", component_path.c_str()); - if (!this->ReadListFile("CPackDeb.cmake")) { + if (!this->ReadListFile("Internal/CPack/CPackDeb.cmake")) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while execution CPackDeb.cmake" << std::endl); retval = 0; @@ -179,7 +179,7 @@ int cmCPackDebGenerator::PackageComponentsAllInOne( this->SetOption("CPACK_DEB_PACKAGE_COMPONENT_PART_PATH", component_path.c_str()); } - if (!this->ReadListFile("CPackDeb.cmake")) { + if (!this->ReadListFile("Internal/CPack/CPackDeb.cmake")) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while execution CPackDeb.cmake" << std::endl); retval = 0; diff --git a/Source/CPack/cmCPackFreeBSDGenerator.cxx b/Source/CPack/cmCPackFreeBSDGenerator.cxx index 91ae1a2..1433414 100644 --- a/Source/CPack/cmCPackFreeBSDGenerator.cxx +++ b/Source/CPack/cmCPackFreeBSDGenerator.cxx @@ -298,7 +298,7 @@ static bool has_suffix(const std::string& str, const std::string& suffix) int cmCPackFreeBSDGenerator::PackageFiles() { - if (!this->ReadListFile("CPackFreeBSD.cmake")) { + if (!this->ReadListFile("Internal/CPack/CPackFreeBSD.cmake")) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while execution CPackFreeBSD.cmake" << std::endl); return 0; diff --git a/Source/CPack/cmCPackNSISGenerator.cxx b/Source/CPack/cmCPackNSISGenerator.cxx index a893a0f..e46b2cf 100644 --- a/Source/CPack/cmCPackNSISGenerator.cxx +++ b/Source/CPack/cmCPackNSISGenerator.cxx @@ -703,7 +703,7 @@ std::string cmCPackNSISGenerator::CreateComponentDescription( // Find a ZIP program if (!this->IsSet("ZIP_EXECUTABLE")) { - this->ReadListFile("CPackZIP.cmake"); + this->ReadListFile("Internal/CPack/CPackZIP.cmake"); if (!this->IsSet("ZIP_EXECUTABLE")) { cmCPackLogger(cmCPackLog::LOG_ERROR, diff --git a/Source/CPack/cmCPackNuGetGenerator.cxx b/Source/CPack/cmCPackNuGetGenerator.cxx index 2ae8cba..76f0699 100644 --- a/Source/CPack/cmCPackNuGetGenerator.cxx +++ b/Source/CPack/cmCPackNuGetGenerator.cxx @@ -49,7 +49,7 @@ int cmCPackNuGetGenerator::PackageFiles() this->SetOption("CPACK_NUGET_ORDINAL_MONOLITIC", "TRUE"); } - auto retval = this->ReadListFile("CPackNuGet.cmake"); + auto retval = this->ReadListFile("Internal/CPack/CPackNuGet.cmake"); if (retval) { AddGeneratedPackageNames(); } else { diff --git a/Source/CPack/cmCPackRPMGenerator.cxx b/Source/CPack/cmCPackRPMGenerator.cxx index c389884..5834829 100644 --- a/Source/CPack/cmCPackRPMGenerator.cxx +++ b/Source/CPack/cmCPackRPMGenerator.cxx @@ -89,7 +89,7 @@ int cmCPackRPMGenerator::PackageOnePack(std::string const& initialToplevel, component_path += packageName; this->SetOption("CPACK_RPM_PACKAGE_COMPONENT_PART_PATH", component_path.c_str()); - if (!this->ReadListFile("CPackRPM.cmake")) { + if (!this->ReadListFile("Internal/CPack/CPackRPM.cmake")) { cmCPackLogger(cmCPackLog::LOG_ERROR, "Error while execution CPackRPM.cmake" << std::endl); retval = 0; @@ -385,7 +385,7 @@ int cmCPackRPMGenerator::PackageComponentsAllInOne( component_path.c_str()); } - if (this->ReadListFile("CPackRPM.cmake")) { + if (this->ReadListFile("Internal/CPack/CPackRPM.cmake")) { AddGeneratedPackageNames(); } else { cmCPackLogger(cmCPackLog::LOG_ERROR, -- cgit v0.12