Commit 65a927a8 authored by Genis Riera Perez's avatar Genis Riera Perez

Add support for building debian package

This commit add the necessary code that allows to generate debian
package from source by using CMake, CPack and debhelpers tools.
Signed-off-by: 's avatarGenis Riera Perez <genis.riera.perez@gmail.com>
parent 83cc318c
......@@ -18,6 +18,8 @@
PROJECT("paho" C)
CMAKE_MINIMUM_REQUIRED(VERSION 3.0)
SET(CMAKE_SCRIPTS "${CMAKE_SOURCE_DIR}/cmake")
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
## build settings
SET(PAHO_VERSION_MAJOR 1)
......@@ -32,6 +34,7 @@ STRING(STRIP ${BUILD_TIMESTAMP} BUILD_TIMESTAMP)
SET(PAHO_WITH_SSL FALSE CACHE BOOL "Flag that defines whether to build ssl-enabled binaries too. ")
SET(PAHO_BUILD_DOCUMENTATION FALSE CACHE BOOL "Create and install the HTML based API documentation (requires Doxygen)")
SET(PAHO_BUILD_SAMPLES FALSE CACHE BOOL "Build sample programs")
SET(PAHO_BUILD_DEB_PACKAGE FALSE CACHE BOOL "Build debian package")
ADD_SUBDIRECTORY(src)
IF(PAHO_BUILD_SAMPLES)
......@@ -45,6 +48,12 @@ ENDIF()
### packaging settings
IF (CMAKE_SYSTEM_NAME MATCHES "Windows")
SET(CPACK_GENERATOR "ZIP")
ELSEIF(PAHO_BUILD_DEB_PACKAGE)
SET(CPACK_GENERATOR "DEB")
CONFIGURE_FILE(${CMAKE_SCRIPTS}/CPackDebConfig.cmake.in
${CMAKE_BINARY_DIR}/CPackDebConfig.cmake @ONLY)
SET(CPACK_PROJECT_CONFIG_FILE ${CMAKE_BINARY_DIR}/CPackDebConfig.cmake)
ADD_SUBDIRECTORY(debian)
ELSE()
SET(CPACK_GENERATOR "TGZ")
ENDIF()
......
......@@ -20,6 +20,13 @@ On Debian based systems this would mean that the following packages have to be i
```
apt-get install build-essential gcc make cmake cmake-gui cmake-curses-gui
```
Also, in order to build a debian package from the source code, the following packages have to be installed
```
apt-get install fakeroot fakeroot devscripts dh-make lsb-release
```
Ninja can be downloaded from its github project page in the "releases" section. Optionally it is possible to build binaries with SSL support. This requires the OpenSSL libraries and includes to be available. E. g. on Debian:
```
......@@ -41,6 +48,7 @@ OPENSSL_INC_SEARCH_PATH | "" (system default) | Directory containing OpenSSL inc
OPENSSL_LIB_SEARCH_PATH | "" (system default) | Directory containing OpenSSL libraries
PAHO_BUILD_DOCUMENTATION | FALSE | Create and install the HTML based API documentation (requires Doxygen)
PAHO_BUILD_SAMPLES | FALSE | Build sample programs
PAHO_BUILD_DEB_PACKAGE | FALSE | Build debian package
Using these variables CMake can be used to generate your Ninja or Make files. Using CMake, building out-of-source is the default. Therefore it is recommended to invoke all build commands inside your chosen build directory but outside of the source tree.
......
IF (CPACK_GENERATOR MATCHES "DEB")
FIND_PROGRAM(DPKG_PROGRAM dpkg DOC "dpkg program of Debian-based systems")
IF (DPKG_PROGRAM)
EXECUTE_PROCESS(
COMMAND ${DPKG_PROGRAM} --print-architecture
OUTPUT_VARIABLE CPACK_DEBIAN_PACKAGE_ARCHITECTURE
OUTPUT_STRIP_TRAILING_WHITESPACE
)
ELSE (DPKG_PROGRAM)
MESSAGE(FATAL_ERROR "Could not find an architecture for the package")
ENDIF (DPKG_PROGRAM)
EXECUTE_PROCESS(
COMMAND lsb_release -si
OUTPUT_VARIABLE CPACK_DEBIAN_DIST_NAME
RESULT_VARIABLE DIST_NAME_STATUS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
IF (DIST_NAME_STATUS)
MESSAGE(FATAL_ERROR "Could not find a GNU/Linux distribution name")
ENDIF (DIST_NAME_STATUS)
IF (CPACK_DEBIAN_DIST_NAME STREQUAL "")
MESSAGE(FATAL_ERROR "Could not find a GNU/Linux distribution name")
ENDIF ()
EXECUTE_PROCESS(
COMMAND lsb_release -sc
OUTPUT_VARIABLE CPACK_DEBIAN_DIST_CODE
RESULT_VARIABLE DIST_CODE_STATUS
OUTPUT_STRIP_TRAILING_WHITESPACE
)
IF (DIST_NAME_STATUS)
MESSAGE(FATAL_ERROR "Could not find a GNU/Linux distribution codename")
ENDIF (DIST_NAME_STATUS)
IF (CPACK_DEBIAN_DIST_CODE STREQUAL "")
MESSAGE(FATAL_ERROR "Could not find a GNU/Linux distribution codename")
ENDIF ()
SET(CPACK_PACKAGE_VERSION_MAJOR @PAHO_VERSION_MAJOR@)
SET(CPACK_PACKAGE_VERSION_MINOR @PAHO_VERSION_MINOR@)
SET(CPACK_PACKAGE_VERSION_PATCH @PAHO_VERSION_PATCH@)
SET(PACKAGE_VERSION
"${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
IF (PACKAGE_VERSION STREQUAL "")
MESSAGE(FATAL_ERROR "Could not find a version number for the package")
ENDIF ()
SET(PAHO_WITH_SSL @PAHO_WITH_SSL@)
MESSAGE("Package version: ${PACKAGE_VERSION}")
MESSAGE("Package built for: ${CPACK_DEBIAN_DIST_NAME} ${CPACK_DEBIAN_DIST_CODE}")
IF(PAHO_WITH_SSL)
MESSAGE("Package built with ssl-enabled binaries too")
ENDIF()
# Additional lines to a paragraph should start with " "; paragraphs should
# be separated with a " ." line
SET(CPACK_PACKAGE_NAME "libpaho-mqtt")
SET(CPACK_PACKAGE_CONTACT "Eclipse")
SET(CPACK_PACKAGE_DESCRIPTION_SUMMARY "Eclipse Paho MQTT C client")
SET(CPACK_DEBIAN_PACKAGE_NAME ${CPACK_PACKAGE_NAME})
SET(CPACK_DEBIAN_PACKAGE_MAINTAINER
"Genis Riera Perez <genis.riera.perez@gmail.com>")
SET(CPACK_DEBIAN_PACKAGE_DESCRIPTION "Eclipse Paho MQTT C client library")
SET(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON)
SET(CPACK_DEBIAN_PACKAGE_VERSION ${PACKAGE_VERSION})
SET(CPACK_DEBIAN_PACKAGE_SECTION "net")
SET(CPACK_DEBIAN_PACKAGE_CONFLICTS ${CPACK_PACKAGE_NAME})
SET(CPACK_PACKAGE_FILE_NAME
"${CPACK_DEBIAN_PACKAGE_NAME}_${CPACK_DEBIAN_PACKAGE_VERSION}_${CPACK_DEBIAN_PACKAGE_ARCHITECTURE}")
IF(PAHO_WITH_SSL)
SET(CPACK_DEBIAN_PACKAGE_DEPENDS "libssl-dev")
ENDIF()
UNSET(PACKAGE_VERSION CACHE)
UNSET(CPACK_DEBIAN_PACKAGE_VERSION CACHE)
#
# From CMakeDebHelper
# See http://www.cmake.org/Wiki/CMake:CPackPackageGenerators#Overall_usage_.28common_to_all_generators.29
#
# When the DEB-generator runs, we want him to run our install-script
#set( CPACK_INSTALL_SCRIPT ${CPACK_DEBIAN_INSTALL_SCRIPT} )
ENDIF()
#=============================================================================
# CMakeDebHelper, Copyright (C) 2013 Sebastian Kienzl
# http://knzl.de/cmake-debhelper/
# Licensed under the GPL v2, see LICENSE
#=============================================================================
# configure() .in-files to the CURRENT_BINARY_DIR
foreach( _F ${DH_INPUT} )
# strip the .in part
string( REGEX REPLACE ".in$" "" _F_WE ${_F} )
configure_file( ${_F} ${_F_WE} @ONLY )
endforeach()
# compat and control is only needed for running the debhelpers,
# CMake is going to make up the one that ends up in the deb.
file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/compat "9" )
if( NOT CPACK_DEBIAN_PACKAGE_NAME )
string( TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME )
endif()
file( WRITE ${CMAKE_CURRENT_BINARY_DIR}/control "Package: ${CPACK_DEBIAN_PACKAGE_NAME}\nArchitecture: any\n" )
# Some debhelpers need fakeroot, we use it for all of them
find_program( FAKEROOT fakeroot )
if( NOT FAKEROOT )
message( SEND_ERROR "fakeroot not found, please install" )
endif()
find_program( DEBHELPER dh_prep )
if( NOT DEBHELPER )
message( SEND_ERROR "debhelper not found, please install" )
endif()
# Compose a string with a semicolon-seperated list of debhelpers
foreach( _DH ${DH_RUN} )
set( _DH_RUN_SC_LIST "${_DH_RUN_SC_LIST} ${_DH} ;" )
endforeach()
# Making sure the debhelpers run each time we change one of ${DH_INPUT}
add_custom_command(
OUTPUT dhtimestamp
# dh_prep is needed to clean up, dh_* aren't idempotent
COMMAND ${FAKEROOT} dh_prep
# I haven't found another way to run a list of commands here
COMMAND ${FAKEROOT} -- sh -c "${_DH_RUN_SC_LIST}"
# needed to create the files we'll use
COMMAND ${FAKEROOT} dh_installdeb
COMMAND touch ${CMAKE_CURRENT_BINARY_DIR}/dhtimestamp
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/..
DEPENDS ${DH_INPUT}
COMMENT "Running debhelpers"
VERBATIM
)
add_custom_target( dhtarget ALL
DEPENDS dhtimestamp
)
# these files are generated by debhelpers from our templates
foreach( _F ${DH_GENERATED_CONTROL_EXTRA} )
set( CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA
${CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA}
${CMAKE_CURRENT_BINARY_DIR}/${CPACK_DEBIAN_PACKAGE_NAME}/DEBIAN/${_F}
CACHE INTERNAL ""
)
endforeach()
# This will copy the generated dhhelper-files to our to-be-cpacked-directory.
# CPACK_INSTALL_SCRIPT must be set to the value of CPACK_DEBIAN_INSTALL_SCRIPT in the file
# pointed to by CPACK_PROJECT_CONFIG_FILE.
set( CPACK_DEBIAN_INSTALL_SCRIPT ${CMAKE_CURRENT_LIST_DIR}/CMakeDebHelperInstall.cmake CACHE INTERNAL "" )
# This script is used internally by CMakeDebHelper.
# It is run at CPack-Time and copies the files generated by the debhelpers to the right place.
if( NOT CPACK_DEBIAN_PACKAGE_NAME )
string( TOLOWER "${CPACK_PACKAGE_NAME}" CPACK_DEBIAN_PACKAGE_NAME )
endif()
# Copy all generated files where the packing will happen,
# exclude the DEBIAN-directory.
MESSAGE(STATUS "CPACK_OUTPUT_FILE_PREFIX: " "${CPACK_OUTPUT_FILE_PREFIX}/debian/${CPACK_DEBIAN_PACKAGE_NAME}/")
file( COPY
"${CPACK_OUTPUT_FILE_PREFIX}/debian/${CPACK_DEBIAN_PACKAGE_NAME}/"
DESTINATION "${CMAKE_CURRENT_BINARY_DIR}"
PATTERN DEBIAN EXCLUDE
)
# These files (generated by dhelpers) will be copied into the control-part of the deb.
# Files that end up in the filesystem normally (e.g. cron/init-scripts) must not be mentioned here.
# It's a good idea to add "conffiles", as the debhelpers may generate it.
set( DH_GENERATED_CONTROL_EXTRA
preinst
postinst
postrm
prerm
conffiles
)
# At this point, CMakeDebHelper must be included (add .cmake if you have it in this directory)
include( CMakeDebHelper )
# CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA and CPACK_INSTALL_SCRIPT are set now, don't modify them!
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment