Skip to content

Commit

Permalink
Problem: version detection broken, confuses libzmq and cppzmq versions
Browse files Browse the repository at this point in the history
Solution: Fix version detection and cmake syntax errors
Fixes zeromq#182
  • Loading branch information
sigiesec committed Mar 28, 2018
1 parent 702d2fc commit 7a8cc9d
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 10 deletions.
1 change: 0 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
20 changes: 11 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand Down
Empty file modified ci_build.sh
100644 → 100755
Empty file.
8 changes: 8 additions & 0 deletions cmake/DetectCPPZMQVersion.cmake
Original file line number Diff line number Diff line change
@@ -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}")
21 changes: 21 additions & 0 deletions version.sh
Original file line number Diff line number Diff line change
@@ -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'

7 changes: 7 additions & 0 deletions zmq.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,13 @@
#include <string>
#include <vector>

/* 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 <chrono>
Expand Down

0 comments on commit 7a8cc9d

Please sign in to comment.