Skip to content

Commit 3937983

Browse files
authored
Merge pull request #191 from sigiesec/add-travis-ci
Add basic Travis CI for cppzmq
2 parents 52c606e + 7a8cc9d commit 3937983

File tree

6 files changed

+118
-9
lines changed

6 files changed

+118
-9
lines changed

.travis.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Travis CI script
2+
3+
language: c
4+
5+
os:
6+
- linux
7+
#- osx
8+
9+
dist: trusty
10+
11+
cache: ccache
12+
13+
env:
14+
matrix:
15+
# - BUILD_TYPE=cmake DRAFT=enabled
16+
- BUILD_TYPE=cmake
17+
18+
matrix:
19+
include:
20+
# - env: BUILD_TYPE=cmake DO_CLANG_FORMAT_CHECK=1 CLANG_FORMAT=/usr/local/clang-5.0.0/bin/clang-format
21+
# os: linux
22+
# addons:
23+
# apt:
24+
# sources:
25+
# - llvm-toolchain-trusty-5.0
26+
# packages:
27+
# - clang-5.0
28+
29+
sudo: required
30+
31+
# Build and check this project according to the BUILD_TYPE
32+
script:
33+
- ./ci_build.sh

CMakeLists.txt

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,12 @@
11
cmake_minimum_required(VERSION 3.0.0)
2-
project(cppzmq)
32

4-
find_package(ZeroMQ QUIET)
3+
list (APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
4+
5+
include (DetectCPPZMQVersion)
6+
7+
project(cppzmq VERSION ${DETECTED_CPPZMQ_VERSION})
8+
9+
find_package(ZeroMQ)
510

611
# libzmq autotools install: fallback to pkg-config
712
if(NOT ZeroMQ_FOUND)
@@ -14,8 +19,7 @@ if (ZeroMQ_FOUND AND (NOT TARGET libzmq OR NOT TARGET libzmq-static))
1419
message(FATAL_ERROR "ZeroMQ version not supported!")
1520
endif()
1621

17-
set (${PROJECT_NAME}_VERSION ${ZeroMQ_VERSION})
18-
message(STATUS "cppzmq v${${PROJECT_NAME}_VERSION}")
22+
message(STATUS "cppzmq v${CPPZMQ_VERSION}")
1923

2024
set(CPPZMQ_HEADERS
2125
zmq.hpp
@@ -43,15 +47,13 @@ install(FILES ${CPPZMQ_HEADERS}
4347
# GNUInstallDirs "DATADIR" wrong here; CMake search path wants "share".
4448
set(CPPZMQ_CMAKECONFIG_INSTALL_DIR "share/cmake/${PROJECT_NAME}" CACHE STRING "install path for cppzmqConfig.cmake")
4549

46-
if (NOT CMAKE_VERSION VERSION_LESS 3.0)
47-
export(EXPORT ${PROJECT_NAME}-targets
48-
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
49-
endif()
50+
export(EXPORT ${PROJECT_NAME}-targets
51+
FILE "${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Targets.cmake")
5052
configure_package_config_file(${PROJECT_NAME}Config.cmake.in
5153
"${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}Config.cmake"
5254
INSTALL_DESTINATION ${CPPZMQ_CMAKECONFIG_INSTALL_DIR})
5355
write_basic_package_version_file(${CMAKE_CURRENT_BINARY_DIR}/${PROJECT_NAME}ConfigVersion.cmake
54-
VERSION ${${PROJECT_NAME}_VERSION}
56+
VERSION ${CPPZMQ_VERSION}}
5557
COMPATIBILITY AnyNewerVersion)
5658
install(EXPORT ${PROJECT_NAME}-targets
5759
FILE ${PROJECT_NAME}Targets.cmake

ci_build.sh

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#!/usr/bin/env bash
2+
3+
set -x
4+
5+
install_zeromq() {
6+
pushd .
7+
8+
mkdir libzmq
9+
cd libzmq
10+
curl -L https://github.com/zeromq/libzmq/releases/download/v${ZMQ_VERSION}/zeromq-${ZMQ_VERSION}.tar.gz >zeromq.tar.gz
11+
tar -xvzf zeromq.tar.gz
12+
cd zeromq-${ZMQ_VERSION}
13+
14+
mkdir build
15+
cd build
16+
cmake ..
17+
sudo make -j4 install
18+
19+
popd
20+
}
21+
22+
# build zeromq first
23+
24+
if [ "${ZMQ_VERSION}" != "" ] ; then install_zeromq ; fi
25+
26+
# build cppzmq
27+
28+
mkdir build
29+
cd build
30+
cmake ..
31+
sudo make -j4 install
32+
33+
# build cppzmq tests
34+
# cd tests
35+
# mkdir build
36+
# cd build
37+
# cmake ..
38+
# make -j5 test ARGS="-V"

cmake/DetectCPPZMQVersion.cmake

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
2+
file(READ "${CMAKE_CURRENT_SOURCE_DIR}/zmq.hpp" _CPPZMQ_H_CONTENTS)
3+
string(REGEX REPLACE ".*#define CPPZMQ_VERSION_MAJOR ([0-9]+).*" "\\1" DETECTED_CPPZMQ_VERSION_MAJOR "${_CPPZMQ_H_CONTENTS}")
4+
string(REGEX REPLACE ".*#define CPPZMQ_VERSION_MINOR ([0-9]+).*" "\\1" DETECTED_CPPZMQ_VERSION_MINOR "${_CPPZMQ_H_CONTENTS}")
5+
string(REGEX REPLACE ".*#define CPPZMQ_VERSION_PATCH ([0-9]+).*" "\\1" DETECTED_CPPZMQ_VERSION_PATCH "${_CPPZMQ_H_CONTENTS}")
6+
set(DETECTED_CPPZMQ_VERSION "${DETECTED_CPPZMQ_VERSION_MAJOR}.${DETECTED_CPPZMQ_VERSION_MINOR}.${DETECTED_CPPZMQ_VERSION_PATCH}")
7+
8+
message(STATUS "Detected CPPZMQ Version - ${DETECTED_CPPZMQ_VERSION}")

version.sh

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
#!/bin/sh
2+
#
3+
# This script extracts the 0MQ version from zmq.hpp, which is the master
4+
# location for this information.
5+
#
6+
if [ ! -f zmq.hpp ]; then
7+
echo "version.sh: error: zmq.hpp does not exist" 1>&2
8+
exit 1
9+
fi
10+
MAJOR=$(grep '^#define CPPZMQ_VERSION_MAJOR \+[0-9]\+' zmq.hpp)
11+
MINOR=$(grep '^#define CPPZMQ_VERSION_MINOR \+[0-9]\+' zmq.hpp)
12+
PATCH=$(grep '^#define CPPZMQ_VERSION_PATCH \+[0-9]\+' zmq.hpp)
13+
if [ -z "$MAJOR" -o -z "$MINOR" -o -z "$PATCH" ]; then
14+
echo "version.sh: error: could not extract version from zmq.hpp" 1>&2
15+
exit 1
16+
fi
17+
MAJOR=$(echo $MAJOR | awk '{ print $3 }')
18+
MINOR=$(echo $MINOR | awk '{ print $3 }')
19+
PATCH=$(echo $PATCH | awk '{ print $3 }')
20+
echo $MAJOR.$MINOR.$PATCH | tr -d '\n\r'
21+

zmq.hpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,13 @@
5353
#include <string>
5454
#include <vector>
5555

56+
/* Version macros for compile-time API version detection */
57+
#define CPPZMQ_VERSION_MAJOR 4
58+
#define CPPZMQ_VERSION_MINOR 3
59+
#define CPPZMQ_VERSION_PATCH 0
60+
61+
#define CPPZMQ_VERSION \
62+
ZMQ_MAKE_VERSION (CPPZMQ_VERSION_MAJOR, CPPZMQ_VERSION_MINOR, CPPZMQ_VERSION_PATCH)
5663

5764
#ifdef ZMQ_CPP11
5865
#include <chrono>

0 commit comments

Comments
 (0)