From 7a8cc9d7cf448b8fd654ec4cd24fd48b57a76162 Mon Sep 17 00:00:00 2001 From: Simon Giesecke Date: Wed, 28 Mar 2018 12:46:59 +0200 Subject: [PATCH] Problem: version detection broken, confuses libzmq and cppzmq versions Solution: Fix version detection and cmake syntax errors Fixes #182 --- .travis.yml | 1 - CMakeLists.txt | 20 +++++++++++--------- ci_build.sh | 0 cmake/DetectCPPZMQVersion.cmake | 8 ++++++++ version.sh | 21 +++++++++++++++++++++ zmq.hpp | 7 +++++++ 6 files changed, 47 insertions(+), 10 deletions(-) mode change 100644 => 100755 ci_build.sh create mode 100644 cmake/DetectCPPZMQVersion.cmake create mode 100755 version.sh diff --git a/.travis.yml b/.travis.yml index fb1269d..0046a7c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -30,5 +30,4 @@ sudo: required # Build and check this project according to the BUILD_TYPE script: - - chmod +x ci_build.sh - ./ci_build.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 16b2f55..6937b37 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,12 @@ cmake_minimum_required(VERSION 3.0.0) -project(cppzmq) -find_package(ZeroMQ QUIET) +list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake") + +include (DetectCPPZMQVersion) + +project(cppzmq VERSION ${DETECTED_CPPZMQ_VERSION}) + +find_package(ZeroMQ) # libzmq autotools install: fallback to pkg-config if(NOT ZeroMQ_FOUND) @@ -14,8 +19,7 @@ if (ZeroMQ_FOUND AND (NOT TARGET libzmq OR NOT TARGET libzmq-static)) message(FATAL_ERROR "ZeroMQ version not supported!") endif() -set (${PROJECT_NAME}_VERSION ${ZeroMQ_VERSION}) -message(STATUS "cppzmq v${${PROJECT_NAME}_VERSION}") +message(STATUS "cppzmq v${CPPZMQ_VERSION}") set(CPPZMQ_HEADERS zmq.hpp @@ -43,15 +47,13 @@ install(FILES ${CPPZMQ_HEADERS} # 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") -if (NOT CMAKE_VERSION VERSION_LESS 3.0) - export(EXPORT ${PROJECT_NAME}-targets - FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake") -endif() +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}) write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake - VERSION ${${PROJECT_NAME}_VERSION} + VERSION ${CPPZMQ_VERSION}} COMPATIBILITY AnyNewerVersion) install(EXPORT ${PROJECT_NAME}-targets FILE ${PROJECT_NAME}Targets.cmake diff --git a/ci_build.sh b/ci_build.sh old mode 100644 new mode 100755 diff --git a/cmake/DetectCPPZMQVersion.cmake b/cmake/DetectCPPZMQVersion.cmake new file mode 100644 index 0000000..99ed9bf --- /dev/null +++ b/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/version.sh b/version.sh new file mode 100755 index 0000000..f7d9eb6 --- /dev/null +++ b/version.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# +# This script extracts the 0MQ version from zmq.hpp, which is the master +# location for this information. +# +if [ ! -f zmq.hpp ]; then + echo "version.sh: error: zmq.hpp does not exist" 1>&2 + exit 1 +fi +MAJOR=$(grep '^#define CPPZMQ_VERSION_MAJOR \+[0-9]\+' zmq.hpp) +MINOR=$(grep '^#define CPPZMQ_VERSION_MINOR \+[0-9]\+' zmq.hpp) +PATCH=$(grep '^#define CPPZMQ_VERSION_PATCH \+[0-9]\+' zmq.hpp) +if [ -z "$MAJOR" -o -z "$MINOR" -o -z "$PATCH" ]; then + echo "version.sh: error: could not extract version from zmq.hpp" 1>&2 + exit 1 +fi +MAJOR=$(echo $MAJOR | awk '{ print $3 }') +MINOR=$(echo $MINOR | awk '{ print $3 }') +PATCH=$(echo $PATCH | awk '{ print $3 }') +echo $MAJOR.$MINOR.$PATCH | tr -d '\n\r' + diff --git a/zmq.hpp b/zmq.hpp index 71a6c81..3af536b 100644 --- a/zmq.hpp +++ b/zmq.hpp @@ -53,6 +53,13 @@ #include #include +/* Version macros for compile-time API version detection */ +#define CPPZMQ_VERSION_MAJOR 4 +#define CPPZMQ_VERSION_MINOR 3 +#define CPPZMQ_VERSION_PATCH 0 + +#define CPPZMQ_VERSION \ + ZMQ_MAKE_VERSION (CPPZMQ_VERSION_MAJOR, CPPZMQ_VERSION_MINOR, CPPZMQ_VERSION_PATCH) #ifdef ZMQ_CPP11 #include