Commit 236f4415 authored by Ian Craggs's avatar Ian Craggs

Merge branch 'feature/debian-package' of https://github.com/griera/paho.mqtt.c into fixes #158

Conflicts:
	CMakeLists.txt
	README.md
parents 359a9f4a fc4b1544
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
# #
# Contributors: # Contributors:
# Rainer Poisel - initial version # Rainer Poisel - initial version
# Genis Riera Perez - Add support for building debian package
#*******************************************************************************/ #*******************************************************************************/
# Note: on OS X you should install XCode and the associated command-line tools # Note: on OS X you should install XCode and the associated command-line tools
...@@ -21,6 +22,9 @@ PROJECT("paho" C) ...@@ -21,6 +22,9 @@ PROJECT("paho" C)
MESSAGE(STATUS "CMake version: " ${CMAKE_VERSION}) MESSAGE(STATUS "CMake version: " ${CMAKE_VERSION})
MESSAGE(STATUS "CMake system name: " ${CMAKE_SYSTEM_NAME}) MESSAGE(STATUS "CMake system name: " ${CMAKE_SYSTEM_NAME})
SET(CMAKE_SCRIPTS "${CMAKE_SOURCE_DIR}/cmake")
SET(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/modules")
## build settings ## build settings
SET(PAHO_VERSION_MAJOR 1) SET(PAHO_VERSION_MAJOR 1)
SET(PAHO_VERSION_MINOR 1) SET(PAHO_VERSION_MINOR 1)
...@@ -61,6 +65,7 @@ SET(PAHO_WITH_SSL FALSE CACHE BOOL "Flag that defines whether to build ssl-enabl ...@@ -61,6 +65,7 @@ SET(PAHO_WITH_SSL FALSE CACHE BOOL "Flag that defines whether to build ssl-enabl
SET(PAHO_BUILD_STATIC FALSE CACHE BOOL "Build static library") SET(PAHO_BUILD_STATIC FALSE CACHE BOOL "Build static library")
SET(PAHO_BUILD_DOCUMENTATION FALSE CACHE BOOL "Create and install the HTML based API documentation (requires Doxygen)") 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_SAMPLES FALSE CACHE BOOL "Build sample programs")
SET(PAHO_BUILD_DEB_PACKAGE FALSE CACHE BOOL "Build debian package")
ADD_SUBDIRECTORY(src) ADD_SUBDIRECTORY(src)
IF(PAHO_BUILD_SAMPLES) IF(PAHO_BUILD_SAMPLES)
...@@ -74,7 +79,13 @@ ENDIF() ...@@ -74,7 +79,13 @@ ENDIF()
### packaging settings ### packaging settings
IF (WIN32) IF (WIN32)
SET(CPACK_GENERATOR "ZIP") SET(CPACK_GENERATOR "ZIP")
ELSEIF(UNIX) 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") SET(CPACK_GENERATOR "TGZ")
ENDIF() ENDIF()
......
# Eclipse Paho MQTT C client # Eclipse Paho MQTT C client
This repository contains the source code for the [Eclipse Paho](http://eclipse.org/paho) MQTT C client library.
This repository contains the source code for the [Eclipse Paho](http://eclipse.org/paho) MQTT C client library.
This code builds libraries which enable applications to connect to an [MQTT](http://mqtt.org) broker to publish messages, and to subscribe to topics and receive published messages. This code builds libraries which enable applications to connect to an [MQTT](http://mqtt.org) broker to publish messages, and to subscribe to topics and receive published messages.
...@@ -16,7 +15,7 @@ The Paho C client comprises four shared libraries: ...@@ -16,7 +15,7 @@ The Paho C client comprises four shared libraries:
* libmqttv3c.so - "classic" / synchronous * libmqttv3c.so - "classic" / synchronous
* libmqttv3cs.so - "classic" / synchronous with SSL * libmqttv3cs.so - "classic" / synchronous with SSL
Optionally, you can build static version of those libraries. Optionally, using the CMake build, you can build static versions of those libraries.
## Build instructions for GNU Make ## Build instructions for GNU Make
...@@ -63,6 +62,13 @@ On Debian based systems this would mean that the following packages have to be i ...@@ -63,6 +62,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 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: 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:
``` ```
...@@ -88,6 +94,7 @@ PAHO_BUILD_SAMPLES | FALSE | Build sample programs ...@@ -88,6 +94,7 @@ PAHO_BUILD_SAMPLES | FALSE | Build sample programs
MQTT_TEST_BROKER | tcp://localhost:1883 | MQTT connection URL for a broker to use during test execution MQTT_TEST_BROKER | tcp://localhost:1883 | MQTT connection URL for a broker to use during test execution
MQTT_TEST_PROXY | tcp://localhost:1883 | Hostname of the test proxy to use MQTT_TEST_PROXY | tcp://localhost:1883 | Hostname of the test proxy to use
MQTT_SSL_HOSTNAME | localhost | Hostname of a test SSL MQTT broker to use MQTT_SSL_HOSTNAME | localhost | Hostname of a test SSL MQTT broker to use
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. 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.
...@@ -105,7 +112,7 @@ Invoking cmake and specifying build options can also be performed using cmake-gu ...@@ -105,7 +112,7 @@ Invoking cmake and specifying build options can also be performed using cmake-gu
ccmake -GNinja ~/git/org.eclipse.paho.mqtt.c ccmake -GNinja ~/git/org.eclipse.paho.mqtt.c
``` ```
To compile/link the binaries and to generate packages, simply invoke `ninja package` or `make -j <number-of-cores-to-use> package` after CMake. To simply compile/link invoke `ninja` or `make -j <number-of-cores-to-use>`. To compile/link the binaries and to generate packages, simply invoke `ninja package` or `make -j <number-of-cores-to-use> package` after CMake. To simply compile/link invoke `ninja` or `make -j <number-of-cores-to-use>`.
### Debug builds ### Debug builds
...@@ -127,10 +134,9 @@ python ../test/mqttsas2.py & ...@@ -127,10 +134,9 @@ python ../test/mqttsas2.py &
ctest -VV ctest -VV
``` ```
### Cross compilation ### Cross compilation
Cross compilation using CMake is performed by using so called "toolchain files" (see: http://www.vtk.org/Wiki/CMake_Cross_Compiling). Cross compilation using CMake is performed by using so called "toolchain files" (see: http://www.vtk.org/Wiki/CMake_Cross_Compiling).
The path to the toolchain file can be specified by using CMake's `-DCMAKE_TOOLCHAIN_FILE` option. In case no toolchain file is specified, the build is performed for the native build platform. The path to the toolchain file can be specified by using CMake's `-DCMAKE_TOOLCHAIN_FILE` option. In case no toolchain file is specified, the build is performed for the native build platform.
...@@ -140,7 +146,7 @@ For your convenience toolchain files for the following platforms can be found in ...@@ -140,7 +146,7 @@ For your convenience toolchain files for the following platforms can be found in
* Windows x86_64 * Windows x86_64
* Windows x86 * Windows x86
The provided toolchain files assume that required compilers/linkers are to be found in the environment, i. e. the PATH-Variable of your user or system. If you prefer, you can also specify the absolute location of your compilers in the toolchain files. The provided toolchain files assume that required compilers/linkers are to be found in the environment, i. e. the PATH-Variable of your user or system. If you prefer, you can also specify the absolute location of your compilers in the toolchain files.
Example invocation for the Raspberry Pi: Example invocation for the Raspberry Pi:
...@@ -163,7 +169,6 @@ In this case the libraries and executable are not linked against OpenSSL Librari ...@@ -163,7 +169,6 @@ In this case the libraries and executable are not linked against OpenSSL Librari
apt-get install gcc-mingw-w64-x86-64 gcc-mingw-w64-i686 apt-get install gcc-mingw-w64-x86-64 gcc-mingw-w64-i686
``` ```
## Usage and API ## Usage and API
Detailed API documentation is available by building the Doxygen docs in the ``doc`` directory. A [snapshot is also available online](http://www.eclipse.org/paho/files/mqttdoc/Cclient/index.html). Detailed API documentation is available by building the Doxygen docs in the ``doc`` directory. A [snapshot is also available online](http://www.eclipse.org/paho/files/mqttdoc/Cclient/index.html).
...@@ -181,9 +186,9 @@ Note that using the C headers from a C++ program requires the following declarat ...@@ -181,9 +186,9 @@ Note that using the C headers from a C++ program requires the following declarat
## Runtime tracing ## Runtime tracing
A number of environment variables control runtime tracing of the C library. A number of environment variables control runtime tracing of the C library.
Tracing is switched on using ``MQTT_C_CLIENT_TRACE`` (a value of ON traces to stdout, any other value should specify a file to trace to). Tracing is switched on using ``MQTT_C_CLIENT_TRACE`` (a value of ON traces to stdout, any other value should specify a file to trace to).
The verbosity of the output is controlled using the ``MQTT_C_CLIENT_TRACE_LEVEL`` environment variable - valid values are ERROR, PROTOCOL, MINIMUM, MEDIUM and MAXIMUM (from least to most verbose). The verbosity of the output is controlled using the ``MQTT_C_CLIENT_TRACE_LEVEL`` environment variable - valid values are ERROR, PROTOCOL, MINIMUM, MEDIUM and MAXIMUM (from least to most verbose).
......
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