Source: zeromq3
Severity: normal
Tags: patch

src:zeromq3 and libzmq3-dev currently embed headers from the separate
cppzmq repository. However, the associated cmake files are not included,
which means when trying to build downstream projects which use cppzmq
and cmake, it's necessary to hack the buildsystem or embed the cmake
files from cppzmq.

I've included a patch (against 4.3.3-2) which adds these files to the
source package and libzmq3-dev. Specifically:

 * move the existing cppzmq files (zmq.hpp, zmq_addon.hpp) to
   debian/cppzmq/ and add the cmake files from cppzmq 4.6.0
 * add Provides: cppzmq-dev to libzmq3-dev, which would hopefully make
   it easier to split the packages in future
 * build-depend on cmake, and add an override after dh_auto_install to
   process and install the cmake.in files from cppzmq 

I appreciate this is a larger change than #951135. Other options would be to

* continue to bundle cppzmq in a common source package, but use
  multiple upstream tarballs so cppzmq is a more obvious component and
  the embedded files can be more readily updated together.
* split cppzmq into a separate source package. Some downstream
  dependencies would need to be fixed. Codesearch suggests gnuradio,
  libopenshot, thrift, tango, ignition-transport, horizon-eda

Gordon
From 5c8f7f94d1e62a8a51bf73484493d9ae2e332a4d Mon Sep 17 00:00:00 2001
From: Gordon Ball <gor...@chronitis.net>
Date: Tue, 15 Sep 2020 08:52:10 +0000
Subject: [PATCH] Add cppzmq cmake files

---
 debian/changelog                              |  10 ++
 debian/control                                |   5 +-
 debian/copyright                              |   6 +-
 debian/cppzmq/CMakeLists.txt                  | 102 ++++++++++++++++++
 debian/cppzmq/cmake/DetectCPPZMQVersion.cmake |   8 ++
 debian/cppzmq/cppzmqConfig.cmake.in           |  36 +++++++
 .../cppzmq/libzmq-pkg-config/FindZeroMQ.cmake |  26 +++++
 debian/{ => cppzmq}/zmq.hpp                   |   0
 debian/{ => cppzmq}/zmq_addon.hpp             |   0
 debian/libzmq3-dev.install                    |   3 +-
 debian/rules                                  |   9 ++
 11 files changed, 199 insertions(+), 6 deletions(-)
 create mode 100644 debian/cppzmq/CMakeLists.txt
 create mode 100644 debian/cppzmq/cmake/DetectCPPZMQVersion.cmake
 create mode 100644 debian/cppzmq/cppzmqConfig.cmake.in
 create mode 100644 debian/cppzmq/libzmq-pkg-config/FindZeroMQ.cmake
 rename debian/{ => cppzmq}/zmq.hpp (100%)
 rename debian/{ => cppzmq}/zmq_addon.hpp (100%)

diff --git a/debian/changelog b/debian/changelog
index 072ba91..d020488 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,13 @@
+zeromq3 (4.3.3-3) UNRELEASED; urgency=medium
+
+  * In addition to the header files zmq.hpp and zmq_addon.hpp from cppzmq,
+    libzmq3-dev now includes the associated CMake files for cppzmq
+     + The embedded cppzmq source files have been moved to d/cppzmq/
+     + Add Provides: cppzmq-dev to libzmq3-dev
+     + Add cmake to Build-Depends
+
+ -- Gordon Ball <gor...@chronitis.net>  Tue, 25 Aug 2020 14:32:39 +0000
+
 zeromq3 (4.3.3-2) unstable; urgency=medium
 
   * Backport upstream fix of broken zmq_ctx_get API.
diff --git a/debian/control b/debian/control
index cac55c3..7eb56ac 100644
--- a/debian/control
+++ b/debian/control
@@ -9,7 +9,8 @@ Build-Depends: debhelper-compat (= 11),
  libkrb5-dev,
  pkg-config,
  xmlto,
- asciidoc
+ asciidoc,
+ cmake
 Standards-Version: 4.5.0
 #Vcs-Browser: http://anonscm.debian.org/gitweb/?p=collab-maint/zeromq3.git
 #Vcs-Git: git://anonscm.debian.org/collab-maint/zeromq3.git
@@ -36,7 +37,7 @@ Section: libdevel
 Depends: libzmq5 (= ${binary:Version}), ${misc:Depends}, libpgm-dev (>= 
5.2.122~dfsg), libsodium-dev, libnorm-dev, libkrb5-dev
 Conflicts: libzmq-dev, libzmq5-dev
 Replaces: libzmq5-dev
-Provides: libzmq5-dev
+Provides: libzmq5-dev, cppzmq-dev
 Multi-Arch: same
 Description: lightweight messaging kernel (development files)
  ØMQ is a library which extends the standard socket interfaces with features
diff --git a/debian/copyright b/debian/copyright
index a7cd247..f11fb19 100644
--- a/debian/copyright
+++ b/debian/copyright
@@ -55,12 +55,14 @@ Copyright: 2014-    , Laszlo Boszormenyi (GCS) 
<g...@debian.org>
  2012, Alessandro Ghedini <gh...@debian.org>
 License: LGPL-2.0+
 
-Files: debian/zmq.hpp
+Files: debian/cppzmq/*
 Copyright: 2009-2011, 250bpm s.r.o.
  2011, Botond Ballo
  2007-2013, iMatix Corporation
+ 2016, VOCA AS / Harald Nøkland
+ 2016-2020, ZeroMQ community
 License: MIT
-Comment: The C++ header was downloaded from https://github.com/zeromq/cppzmq
+Comment: Downloaded from https://github.com/zeromq/cppzmq
 
 License: LGPL-2.0+
  This package is free software; you can redistribute it and/or
diff --git a/debian/cppzmq/CMakeLists.txt b/debian/cppzmq/CMakeLists.txt
new file mode 100644
index 0000000..81e19e8
--- /dev/null
+++ b/debian/cppzmq/CMakeLists.txt
@@ -0,0 +1,102 @@
+cmake_minimum_required(VERSION 3.0.0)
+
+list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
+
+include (DetectCPPZMQVersion)
+
+project(cppzmq VERSION ${DETECTED_CPPZMQ_VERSION})
+
+find_package(ZeroMQ QUIET)
+
+# libzmq autotools install: fallback to pkg-config
+if(NOT ZeroMQ_FOUND)
+    message(STATUS "CMake libzmq package not found, trying again with 
pkg-config (normal install of zeromq)")
+    list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/libzmq-pkg-config)
+    find_package(ZeroMQ REQUIRED)
+endif()
+
+# TODO "REQUIRED" above should already cause a fatal failure if not found, but 
this doesn't seem to work
+if(NOT ZeroMQ_FOUND)
+    message(FATAL_ERROR "ZeroMQ was not found, neither as a CMake package nor 
via pkg-config")
+endif()
+
+if (ZeroMQ_FOUND AND (NOT TARGET libzmq OR NOT TARGET libzmq-static))
+  message(FATAL_ERROR "ZeroMQ version not supported!")
+endif()
+
+if (EXISTS "${CMAKE_SOURCE_DIR}/.git")
+    OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" ON)
+else ()
+    OPTION (ENABLE_DRAFTS "Build and install draft classes and methods" OFF)
+endif ()
+if (ENABLE_DRAFTS)
+    ADD_DEFINITIONS (-DZMQ_BUILD_DRAFT_API)
+    set (pkg_config_defines "-DZMQ_BUILD_DRAFT_API=1")
+else (ENABLE_DRAFTS)
+    set (pkg_config_defines "")
+endif (ENABLE_DRAFTS)
+
+message(STATUS "cppzmq v${cppzmq_VERSION}")
+
+set(CPPZMQ_HEADERS
+    zmq.hpp
+    zmq_addon.hpp
+)
+
+foreach (target cppzmq cppzmq-static)
+  add_library(${target} INTERFACE)
+  target_include_directories(${target} INTERFACE 
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
+                                                 $<INSTALL_INTERFACE:include>)
+endforeach()
+
+target_link_libraries(cppzmq INTERFACE libzmq)
+target_link_libraries(cppzmq-static INTERFACE libzmq-static)
+
+include(GNUInstallDirs)
+include(CMakePackageConfigHelpers)
+
+install(TARGETS cppzmq cppzmq-static
+        EXPORT ${PROJECT_NAME}-targets)
+
+install(FILES ${CPPZMQ_HEADERS}
+        DESTINATION ${CMAKE_INSTALL_INCLUDEDIR})
+
+# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
+set(CPPZMQ_CMAKECONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}" CACHE STRING 
"install path for cppzmqConfig.cmake")
+
+configure_file(libzmq-pkg-config/FindZeroMQ.cmake
+               libzmq-pkg-config/FindZeroMQ.cmake
+               COPYONLY)
+
+export(EXPORT ${PROJECT_NAME}-targets
+     FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
+configure_package_config_file(${PROJECT_NAME}Config.cmake.in
+                              
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
+                              INSTALL_DESTINATION 
${CPPZMQ_CMAKECONFIG_INSTALL_DIR})
+# Workaround until ARCH_INDEPENDENT flag can be used with cmake 3.14.
+# The ConigVersion.cmake file contains checks for the architecture is was
+# generated on, which can cause problems for header only libraries
+# used with e.g. the Conan package manager. Since it is header only we
+# can/should omit those checks.
+set(CPPZMQ_SIZEOF_VOID_P ${CMAKE_SIZEOF_VOID_P})
+set(CMAKE_SIZEOF_VOID_P "") # a simple unset is not sufficient
+write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
+                                 VERSION ${CPPZMQ_VERSION}
+                                 COMPATIBILITY AnyNewerVersion)
+set(CMAKE_SIZEOF_VOID_P ${CPPZMQ_SIZEOF_VOID_P})
+
+install(EXPORT ${PROJECT_NAME}-targets
+        FILE ${PROJECT_NAME}Targets.cmake
+        DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR})
+install(FILES ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake
+              ${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
+              DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR})
+install(FILES ${CMAKE_CURRENT_SOURCE_DIR}/libzmq-pkg-config/FindZeroMQ.cmake
+              DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR}/libzmq-pkg-config)
+
+option(CPPZMQ_BUILD_TESTS "Whether or not to build the tests" ON)
+
+if (CPPZMQ_BUILD_TESTS)
+    enable_testing()
+    add_subdirectory(tests)
+endif()
diff --git a/debian/cppzmq/cmake/DetectCPPZMQVersion.cmake 
b/debian/cppzmq/cmake/DetectCPPZMQVersion.cmake
new file mode 100644
index 0000000..99ed9bf
--- /dev/null
+++ b/debian/cppzmq/cmake/DetectCPPZMQVersion.cmake
@@ -0,0 +1,8 @@
+
+file(READ "${CMAKE_CURRENT_SOURCE_DIR}/zmq.hpp" _CPPZMQ_H_CONTENTS)
+string(REGEX REPLACE ".*#define CPPZMQ_VERSION_MAJOR ([0-9]+).*" "\\1" 
DETECTED_CPPZMQ_VERSION_MAJOR "${_CPPZMQ_H_CONTENTS}")
+string(REGEX REPLACE ".*#define CPPZMQ_VERSION_MINOR ([0-9]+).*" "\\1" 
DETECTED_CPPZMQ_VERSION_MINOR "${_CPPZMQ_H_CONTENTS}")
+string(REGEX REPLACE ".*#define CPPZMQ_VERSION_PATCH ([0-9]+).*" "\\1" 
DETECTED_CPPZMQ_VERSION_PATCH "${_CPPZMQ_H_CONTENTS}")
+set(DETECTED_CPPZMQ_VERSION 
"${DETECTED_CPPZMQ_VERSION_MAJOR}.${DETECTED_CPPZMQ_VERSION_MINOR}.${DETECTED_CPPZMQ_VERSION_PATCH}")
+
+message(STATUS "Detected CPPZMQ Version - ${DETECTED_CPPZMQ_VERSION}")
diff --git a/debian/cppzmq/cppzmqConfig.cmake.in 
b/debian/cppzmq/cppzmqConfig.cmake.in
new file mode 100644
index 0000000..f596517
--- /dev/null
+++ b/debian/cppzmq/cppzmqConfig.cmake.in
@@ -0,0 +1,36 @@
+# cppzmq cmake module
+#
+# The following import targets are created
+#
+# ::
+#
+#   cppzmq-static
+#   cppzmq
+#
+# This module sets the following variables in your project::
+#
+# cppzmq_FOUND - true if cppzmq found on the system
+# cppzmq_INCLUDE_DIR - the directory containing cppzmq headers
+# cppzmq_LIBRARY - the ZeroMQ library for dynamic linking
+# cppzmq_STATIC_LIBRARY - the ZeroMQ library for static linking
+
+@PACKAGE_INIT@
+
+include(CMakeFindDependencyMacro)
+find_package(ZeroMQ QUIET)
+
+# libzmq autotools install: fallback to pkg-config
+if(NOT ZeroMQ_FOUND)
+    list (APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_LIST_DIR}/libzmq-pkg-config)
+    find_package(ZeroMQ REQUIRED)
+endif()
+
+if(NOT ZeroMQ_FOUND)
+    message(FATAL_ERROR "ZeroMQ was NOT found!")
+endif()
+
+if(NOT TARGET @PROJECT_NAME@)
+    include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
+    get_target_property(@PROJECT_NAME@_INCLUDE_DIR cppzmq 
INTERFACE_INCLUDE_DIRECTORIES)
+endif()
+
diff --git a/debian/cppzmq/libzmq-pkg-config/FindZeroMQ.cmake 
b/debian/cppzmq/libzmq-pkg-config/FindZeroMQ.cmake
new file mode 100644
index 0000000..1b84c95
--- /dev/null
+++ b/debian/cppzmq/libzmq-pkg-config/FindZeroMQ.cmake
@@ -0,0 +1,26 @@
+set(PKG_CONFIG_USE_CMAKE_PREFIX_PATH ON)
+find_package(PkgConfig)
+pkg_check_modules(PC_LIBZMQ QUIET libzmq)
+
+set(ZeroMQ_VERSION ${PC_LIBZMQ_VERSION})
+find_library(ZeroMQ_LIBRARY NAMES libzmq.so libzmq.dylib libzmq.dll
+             PATHS ${PC_LIBZMQ_LIBDIR} ${PC_LIBZMQ_LIBRARY_DIRS})
+find_library(ZeroMQ_STATIC_LIBRARY NAMES libzmq-static.a libzmq.a libzmq.dll.a
+             PATHS ${PC_LIBZMQ_LIBDIR} ${PC_LIBZMQ_LIBRARY_DIRS})
+
+if(ZeroMQ_LIBRARY OR ZeroMQ_STATIC_LIBRARY)
+    set(ZeroMQ_FOUND ON)
+endif()
+
+if (TARGET libzmq)
+    # avoid errors defining targets twice
+    return()
+endif()
+
+add_library(libzmq SHARED IMPORTED)
+set_property(TARGET libzmq PROPERTY INTERFACE_INCLUDE_DIRECTORIES 
${PC_LIBZMQ_INCLUDE_DIRS})
+set_property(TARGET libzmq PROPERTY IMPORTED_LOCATION ${ZeroMQ_LIBRARY})
+
+add_library(libzmq-static STATIC IMPORTED ${PC_LIBZMQ_INCLUDE_DIRS})
+set_property(TARGET libzmq-static PROPERTY INTERFACE_INCLUDE_DIRECTORIES 
${PC_LIBZMQ_INCLUDE_DIRS})
+set_property(TARGET libzmq-static PROPERTY IMPORTED_LOCATION 
${ZeroMQ_STATIC_LIBRARY})
diff --git a/debian/zmq.hpp b/debian/cppzmq/zmq.hpp
similarity index 100%
rename from debian/zmq.hpp
rename to debian/cppzmq/zmq.hpp
diff --git a/debian/zmq_addon.hpp b/debian/cppzmq/zmq_addon.hpp
similarity index 100%
rename from debian/zmq_addon.hpp
rename to debian/cppzmq/zmq_addon.hpp
diff --git a/debian/libzmq3-dev.install b/debian/libzmq3-dev.install
index d984009..a1e6692 100644
--- a/debian/libzmq3-dev.install
+++ b/debian/libzmq3-dev.install
@@ -2,5 +2,4 @@ usr/include/*
 usr/lib/*/libzmq.a
 usr/lib/*/libzmq.so
 usr/lib/*/pkgconfig/libzmq.pc
-debian/zmq.hpp usr/include
-debian/zmq_addon.hpp usr/include
+usr/share/cmake
diff --git a/debian/rules b/debian/rules
index ae2707b..e59dba0 100755
--- a/debian/rules
+++ b/debian/rules
@@ -20,6 +20,15 @@ override_dh_auto_configure:
        dh_auto_configure -- --with-pgm --with-libsodium --with-norm=yes \
                --with-libgssapi_krb5=yes
 
+override_dh_auto_install:
+       dh_auto_install
+       # configure and build cppzmq cmake files after libzmq is installed
+       # in the package build dir, which we can then use as the cmake prefix
+       # so that the library is found
+       dh_auto_configure --buildsystem=cmake --sourcedir=debian/cppzmq -- 
-DCPPZMQ_BUILD_TESTS=OFF -DCMAKE_PREFIX_PATH=../../debian/tmp/usr
+       dh_auto_build --buildsystem=cmake --sourcedir=debian/cppzmq
+       dh_auto_install --buildsystem=cmake --sourcedir=debian/cppzmq
+
 override_dh_auto_test:
 ifeq (,$(filter nocheck,$(DEB_BUILD_OPTIONS)))
 ifneq ($(DO_TEST), no)
-- 
2.28.0

Reply via email to