2009-10-30 19:06:53 +03:00
# - The builtin (binary) CPack Deb generator (Unix only)
# CPackDeb may be used to create Deb package using CPack.
# CPackDeb is a CPack generator thus it uses the CPACK_XXX variables
2010-07-28 20:24:20 +04:00
# used by CPack : http://www.cmake.org/Wiki/CMake:CPackConfiguration.
# 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.
2009-10-30 19:06:53 +03:00
#
2010-07-28 20:24:20 +04:00
# CPackDeb has specific features which are controlled by
# the specifics CPACK_DEBIAN_XXX variables.You'll find a detailed usage on
# the wiki:
2009-10-30 19:06:53 +03:00
# http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#DEB_.28UNIX_only.29
# However as a handy reminder here comes the list of specific variables:
#
2010-07-28 20:24:20 +04:00
# CPACK_DEBIAN_PACKAGE_NAME
2009-10-30 19:06:53 +03:00
# Mandatory : YES
# Default : CPACK_PACKAGE_NAME (lower case)
# The debian package summary
# CPACK_DEBIAN_PACKAGE_VERSION
# Mandatory : YES
# Default : CPACK_PACKAGE_VERSION
# The debian package version
# CPACK_DEBIAN_PACKAGE_ARCHITECTURE)
# Mandatory : YES
2010-07-28 20:24:20 +04:00
# Default : Output of dpkg --print-architecture (or i386 if dpkg is not found)
2009-10-30 19:06:53 +03:00
# The debian package architecture
# CPACK_DEBIAN_PACKAGE_DEPENDS
# Mandatory : NO
# Default : -
2010-07-28 20:24:20 +04:00
# May be used to set deb dependencies.
2009-10-30 19:06:53 +03:00
# CPACK_DEBIAN_PACKAGE_MAINTAINER
# Mandatory : YES
# Default : CPACK_PACKAGE_CONTACT
# The debian package maintainer
# CPACK_DEBIAN_PACKAGE_DESCRIPTION
# Mandatory : YES
# Default : CPACK_PACKAGE_DESCRIPTION_SUMMARY
# The debian package description
# CPACK_DEBIAN_PACKAGE_SECTION
# Mandatory : YES
# Default : 'devel'
# The debian package section
# CPACK_DEBIAN_PACKAGE_PRIORITY
# Mandatory : YES
# Default : 'optional'
# The debian package priority
2010-07-28 20:24:20 +04:00
# CPACK_DEBIAN_PACKAGE_HOMEPAGE
# Mandatory : NO
# Default : -
# The URL of the web site for this package
# CPACK_DEBIAN_PACKAGE_SHLIBDEPS
# Mandatory : NO
# Default : OFF
# May be set to ON in order to use dpkg-shlibdeps to generate
# better package dependency list.
# You may need set CMAKE_INSTALL_RPATH toi appropriate value
# if you use this feature, because if you don't dpkg-shlibdeps
# may fail to find your own shared libs.
# See http://www.cmake.org/Wiki/CMake_RPATH_handling.
# CPACK_DEBIAN_PACKAGE_DEBUG
# Mandatory : NO
# Default : -
# May be set when invoking cpack in order to trace debug informations
# during CPackDeb run.
2007-08-08 22:18:13 +04:00
2009-09-28 19:46:51 +04:00
#=============================================================================
# Copyright 2007-2009 Kitware, Inc.
2009-10-30 19:06:53 +03:00
# Copyright 2007-2009 Mathieu Malaterre <mathieu.malaterre@gmail.com>
2009-09-28 19:46:51 +04:00
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
2010-08-07 04:48:47 +04:00
# (To distribute this file outside of CMake, substitute the full
2009-09-28 19:46:51 +04:00
# License text for the above reference.)
2007-08-08 22:18:13 +04:00
# CPack script for creating Debian package
# Author: Mathieu Malaterre
#
# http://wiki.debian.org/HowToPackageForDebian
2007-07-25 18:57:33 +04:00
IF ( CMAKE_BINARY_DIR )
MESSAGE ( FATAL_ERROR "CPackDeb.cmake may only be used by CPack internally." )
ENDIF ( CMAKE_BINARY_DIR )
IF ( NOT UNIX )
MESSAGE ( FATAL_ERROR "CPackDeb.cmake may only be used under UNIX." )
ENDIF ( NOT UNIX )
2010-07-28 20:24:20 +04:00
# 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 ( NOT DEFINED CPACK_DEBIAN_PACKAGE_SHLIBDEPS )
IF ( CPACK_DEBIAN_PACKAGE_SHLIBDEPS )
# dpkg-shlibdeps is a Debian utility for generating dependency list
FIND_PROGRAM ( SHLIBDEPS_EXECUTABLE dpkg-shlibdeps )
# Check version of the dpkg-shlibdeps tool using CPackRPM method
IF ( SHLIBDEPS_EXECUTABLE )
EXECUTE_PROCESS ( COMMAND ${ SHLIBDEPS_EXECUTABLE } --version
O U T P U T _ V A R I A B L E _ T M P _ V E R S I O N
E R R O R _ Q U I E T
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
STRING ( REGEX MATCH "dpkg-shlibdeps version ([0-9]+\\.[0-9]+\\.[0-9]+)"
S H L I B D E P S _ E X E C U T A B L E _ V E R S I O N
$ { _ T M P _ V E R S I O N } )
SET ( SHLIBDEPS_EXECUTABLE_VERSION "${CMAKE_MATCH_1}" )
IF ( CPACK_DEBIAN_PACKAGE_DEBUG )
MESSAGE ( "CPackDeb Debug: dpkg-shlibdeps version is <${SHLIBDEPS_EXECUTABLE_VERSION}>" )
ENDIF ( CPACK_DEBIAN_PACKAGE_DEBUG )
# Generating binary list - Get type of all install files
EXECUTE_PROCESS ( COMMAND find -type f
C O M M A N D x a r g s f i l e
W O R K I N G _ D I R E C T O R Y " $ { C P A C K _ T E M P O R A R Y _ D I R E C T O R Y } "
O U T P U T _ V A R I A B L E C P A C K _ D E B _ I N S T A L L _ F I L E S )
# Convert to CMake list
STRING ( REGEX REPLACE "\n" ";" CPACK_DEB_INSTALL_FILES ${ CPACK_DEB_INSTALL_FILES } )
# Only dynamically linked ELF files are included
# Extract only file name infront of ":"
FOREACH ( _FILE ${ 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 } )
ENDIF ( )
ENDFOREACH ( )
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 "" )
# 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 -O ${ CPACK_DEB_BINARY_FILES }
W O R K I N G _ D I R E C T O R Y " $ { C P A C K _ T E M P O R A R Y _ D I R E C T O R Y } "
O U T P U T _ V A R I A B L E S H L I B D E P S _ O U T P U T
R E S U L T _ V A R I A B L E S H L I B D E P S _ R E S U L T
E R R O R _ V A R I A B L E S H L I B D E P S _ E R R O R
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E )
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 ( CPACK_DEBIAN_PACKAGE_DEBUG )
IF ( NOT SHLIBDEPS_RESULT EQUAL 0 )
MESSAGE ( FATAL_ERROR "CPackDeb: dpkg-shlibdeps: ${SHLIBDEPS_ERROR}" )
ENDIF ( NOT SHLIBDEPS_RESULT EQUAL 0 )
#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}" )
ENDIF ( CPACK_DEBIAN_PACKAGE_DEBUG )
# Remove blank control file
# Might not be safe if package actual contain file or directory named debian
FILE ( REMOVE_RECURSE "${CPACK_TEMPORARY_DIRECTORY}/debian" )
# Append user depend if set
IF ( CPACK_DEBIAN_PACKAGE_DEPENDS )
SET ( CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}, ${CPACK_DEBIAN_PACKAGE_DEPENDS}" )
ELSE ( CPACK_DEBIAN_PACKAGE_DEPENDS )
SET ( CPACK_DEBIAN_PACKAGE_DEPENDS "${CPACK_DEBIAN_PACKAGE_AUTO_DEPENDS}" )
ENDIF ( CPACK_DEBIAN_PACKAGE_DEPENDS )
ELSE ( SHLIBDEPS_EXECUTABLE )
IF ( CPACK_DEBIAN_PACKAGE_DEBUG )
MESSAGE ( "CPackDeb Debug: Using only user-provided depends because dpkg-shlibdeps is not found." )
ENDIF ( CPACK_DEBIAN_PACKAGE_DEBUG )
ENDIF ( SHLIBDEPS_EXECUTABLE )
ELSE ( CPACK_DEBIAN_PACKAGE_SHLIBDEPS )
IF ( CPACK_DEBIAN_PACKAGE_DEBUG )
MESSAGE ( "CPackDeb Debug: Using only user-provided depends" )
ENDIF ( CPACK_DEBIAN_PACKAGE_DEBUG )
ENDIF ( CPACK_DEBIAN_PACKAGE_SHLIBDEPS )
2007-07-27 16:59:59 +04:00
# Let's define the control file found in debian package:
2007-08-08 22:18:13 +04:00
# Binary package:
# http://www.debian.org/doc/debian-policy/ch-controlfields.html#s-binarycontrolfiles
# DEBIAN/control
2007-07-27 16:59:59 +04:00
# debian policy enforce lower case for package name
2007-08-08 22:18:13 +04:00
# Package: (mandatory)
2007-10-25 21:26:54 +04:00
IF ( NOT CPACK_DEBIAN_PACKAGE_NAME )
STRING ( TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME )
ENDIF ( NOT CPACK_DEBIAN_PACKAGE_NAME )
2007-07-27 16:59:59 +04:00
2007-08-08 22:18:13 +04:00
# Version: (mandatory)
2007-10-25 21:26:54 +04:00
IF ( NOT CPACK_DEBIAN_PACKAGE_VERSION )
2007-07-27 16:59:59 +04:00
IF ( NOT CPACK_PACKAGE_VERSION )
2010-07-28 20:24:20 +04:00
MESSAGE ( FATAL_ERROR "CPackDeb: Debian package requires a package version" )
2007-07-27 16:59:59 +04:00
ENDIF ( NOT CPACK_PACKAGE_VERSION )
2007-10-25 21:26:54 +04:00
SET ( CPACK_DEBIAN_PACKAGE_VERSION ${ CPACK_PACKAGE_VERSION } )
ENDIF ( NOT CPACK_DEBIAN_PACKAGE_VERSION )
2007-07-27 16:59:59 +04:00
2007-08-08 22:18:13 +04:00
# Architecture: (mandatory)
2007-10-25 21:26:54 +04:00
IF ( NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE )
2008-03-28 18:47:24 +03:00
# There is no such thing as i686 architecture on debian, you should use i386 instead
# $ dpkg --print-architecture
2008-03-28 18:49:48 +03:00
FIND_PROGRAM ( DPKG_CMD dpkg )
IF ( NOT DPKG_CMD )
2010-07-28 20:24:20 +04:00
MESSAGE ( STATUS "CPackDeb: Can not find dpkg in your path, default to i386." )
2008-03-28 21:08:07 +03:00
SET ( CPACK_DEBIAN_PACKAGE_ARCHITECTURE i386 )
2008-03-28 18:49:48 +03:00
ENDIF ( NOT DPKG_CMD )
EXECUTE_PROCESS ( COMMAND "${DPKG_CMD}" --print-architecture
2008-04-01 17:56:41 +04:00
O U T P U T _ V A R I A B L E C P A C K _ D E B I A N _ P A C K A G E _ A R C H I T E C T U R E
O U T P U T _ S T R I P _ T R A I L I N G _ W H I T E S P A C E
)
2007-10-25 21:26:54 +04:00
ENDIF ( NOT CPACK_DEBIAN_PACKAGE_ARCHITECTURE )
2007-07-27 16:59:59 +04:00
2008-01-18 01:19:13 +03:00
# have a look at GET_PROPERTY(result GLOBAL PROPERTY ENABLED_FEATURES),
# this returns the successful FIND_PACKAGE() calls, maybe this can help
2007-07-27 16:59:59 +04:00
# Depends:
2008-03-28 18:47:24 +03:00
# You should set: DEBIAN_PACKAGE_DEPENDS
# TODO: automate 'objdump -p | grep NEEDED'
2007-10-25 21:26:54 +04:00
IF ( NOT CPACK_DEBIAN_PACKAGE_DEPENDS )
MESSAGE ( STATUS "CPACK_DEBIAN_PACKAGE_DEPENDS not set, the package will have no dependencies." )
ENDIF ( NOT CPACK_DEBIAN_PACKAGE_DEPENDS )
2007-07-27 16:59:59 +04:00
2007-08-08 22:18:13 +04:00
# Maintainer: (mandatory)
2007-10-25 21:26:54 +04:00
IF ( NOT CPACK_DEBIAN_PACKAGE_MAINTAINER )
2007-07-27 16:59:59 +04:00
IF ( NOT CPACK_PACKAGE_CONTACT )
2010-07-28 20:24:20 +04:00
MESSAGE ( FATAL_ERROR "CPackDeb: Debian package requires a maintainer for a package, set CPACK_PACKAGE_CONTACT or CPACK_DEBIAN_PACKAGE_MAINTAINER" )
2007-07-27 16:59:59 +04:00
ENDIF ( NOT CPACK_PACKAGE_CONTACT )
2007-10-25 21:26:54 +04:00
SET ( CPACK_DEBIAN_PACKAGE_MAINTAINER ${ CPACK_PACKAGE_CONTACT } )
ENDIF ( NOT CPACK_DEBIAN_PACKAGE_MAINTAINER )
2007-07-27 16:59:59 +04:00
2007-08-08 22:18:13 +04:00
# Description: (mandatory)
2007-10-25 21:26:54 +04:00
IF ( NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION )
2007-07-27 16:59:59 +04:00
IF ( NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY )
2010-07-28 20:24:20 +04:00
MESSAGE ( FATAL_ERROR "CPackDeb: Debian package requires a summary for a package, set CPACK_PACKAGE_DESCRIPTION_SUMMARY or CPACK_DEBIAN_PACKAGE_DESCRIPTION" )
2007-07-27 16:59:59 +04:00
ENDIF ( NOT CPACK_PACKAGE_DESCRIPTION_SUMMARY )
2007-10-25 21:26:54 +04:00
SET ( CPACK_DEBIAN_PACKAGE_DESCRIPTION ${ CPACK_PACKAGE_DESCRIPTION_SUMMARY } )
ENDIF ( NOT CPACK_DEBIAN_PACKAGE_DESCRIPTION )
2007-08-08 22:18:13 +04:00
# Section: (recommended)
2007-10-25 21:26:54 +04:00
IF ( NOT CPACK_DEBIAN_PACKAGE_SECTION )
SET ( CPACK_DEBIAN_PACKAGE_SECTION "devel" )
ENDIF ( NOT CPACK_DEBIAN_PACKAGE_SECTION )
2007-08-08 22:18:13 +04:00
# Priority: (recommended)
2007-10-25 21:26:54 +04:00
IF ( NOT CPACK_DEBIAN_PACKAGE_PRIORITY )
SET ( CPACK_DEBIAN_PACKAGE_PRIORITY "optional" )
ENDIF ( NOT CPACK_DEBIAN_PACKAGE_PRIORITY )
2007-08-08 22:18:13 +04:00
# Recommends:
2007-10-25 21:26:54 +04:00
# You should set: CPACK_DEBIAN_PACKAGE_RECOMMENDS
2007-08-08 22:18:13 +04:00
# Suggests:
2007-10-25 21:26:54 +04:00
# You should set: CPACK_DEBIAN_PACKAGE_SUGGESTS
2007-08-08 22:18:13 +04:00
2008-04-02 01:51:18 +04:00
# CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
# This variable allow advanced user to add custom script to the control.tar.gz (inside the .deb archive)
2010-07-28 20:24:20 +04:00
# Typical examples are:
2008-04-02 01:51:18 +04:00
# - conffiles
# - postinst
# - postrm
# - prerm"
# Usage:
2010-07-28 20:24:20 +04:00
# SET(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
2008-04-02 01:51:18 +04:00
# "${CMAKE_CURRENT_SOURCE_DIR/prerm;${CMAKE_CURRENT_SOURCE_DIR}/postrm")
2007-08-08 22:18:13 +04:00
# 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:
2007-10-25 21:26:54 +04:00
#IF(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS)
# SET(CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS
2007-08-08 22:18:13 +04:00
# "debhelper (>> 5.0.0), libncurses5-dev, tcl8.4"
# )
2007-10-25 21:26:54 +04:00
#ENDIF(NOT CPACK_DEBIAN_PACKAGE_BUILDS_DEPENDS)