Skip to content

Commit 97b180b

Browse files
trygvisjonnor
authored andcommitted
API improvements and support for MQTT through Mosquitto (#2)
* Added support for MQTT using libmosquitto * Using CMake instead of Makefile * Added a msgflo.h header * Updated to latests AMQP * AMQP: Use libev instead of boost::asio * Fixed discovery message format * Several API changes, see updated example/repeat.cpp
1 parent 9a4fcc5 commit 97b180b

18 files changed

Lines changed: 1221 additions & 270 deletions

.editorconfig

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[*]
2+
indent_style = space
3+
indent_size = 4
4+
trim_trailing_whitespace = true

.gitignore

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
build/
22
node_modules/
3+
.idea
4+
*.iml
5+
examples/Makefile
6+
CMakeFiles
7+
cmake_install.cmake
8+
COPYONLY
9+
CMakeCache.txt
10+
COPYONLY
11+
MsgFlo
12+
amqpcpp_project-prefix/

.gitmodules

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
url = https://github.com/dropbox/json11
44
[submodule "thirdparty/amqpcpp"]
55
path = thirdparty/amqpcpp
6-
url = https://github.com/CopernicaMarketingSoftware/AMQP-CPP.git
6+
url = https://github.com/trygvis/AMQP-CPP.git

.travis.yml

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,19 +9,26 @@ before_install:
99
- sudo add-apt-repository ppa:boost-latest/ppa -y
1010
- sudo apt-get update -qq
1111
- sudo apt-get install g++-4.8
12-
- sudo apt-get install libboost1.55-all-dev
12+
- sudo apt-get install libboost1.55-all-dev libev-dev
1313
- sudo apt-get install pkg-config cmake openssl libc-ares-dev
1414
install:
15+
- export CC=gcc-4.8
16+
- export CXX=g++-4.8
1517
- wget http://mosquitto.org/files/source/mosquitto-1.3.1.tar.gz
1618
- tar xzf mosquitto-1.3.1.tar.gz
1719
- cd mosquitto-1.3.1
1820
- cmake .
1921
- sudo make install
2022
- cd ..
2123
- npm install
24+
- mkdir -p build/
25+
- curl -sSL https://cmake.org/files/v3.5/cmake-3.5.2-Linux-x86_64.tar.gz | tar -xzC ./build
26+
- cd build
27+
- ./cmake-3.5.2-Linux-x86_64/bin/cmake ..
28+
- make -j4
29+
- cd -
2230
before_script:
2331
- mosquitto -d
24-
- make CPP=g++-4.8 EXTRA_LDFLAGS=-L/usr/lib/x86_64-linux-gnu/
2532
script:
2633
- npm test
2734

CMakeLists.txt

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
cmake_minimum_required(VERSION 3.5)
2+
project(msgflo_cpp CXX)
3+
4+
set(MSGFLO_VERSION 1.0)
5+
6+
# AMQP-CPP configuration
7+
8+
set(amqp_install ${CMAKE_CURRENT_BINARY_DIR}/thirdparty-install/amqpcpp)
9+
10+
include(ExternalProject)
11+
ExternalProject_Add(amqpcpp_project
12+
SOURCE_DIR ${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/amqpcpp
13+
CONFIGURE_COMMAND ""
14+
BUILD_COMMAND make CPP=${CMAKE_CXX_COMPILER} LD=${CMAKE_CXX_COMPILER}
15+
BUILD_IN_SOURCE TRUE
16+
INSTALL_COMMAND make install PREFIX=${amqp_install}
17+
)
18+
19+
# Json11 configuration
20+
set(JSON11 thirdparty/json11/json11.cpp thirdparty/json11/json11.hpp)
21+
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/json11/"
22+
DESTINATION "include"
23+
FILES_MATCHING PATTERN "*.hpp")
24+
25+
# Boost
26+
set(Boost_USE_STATIC_LIBS ON)
27+
find_package(Boost COMPONENTS REQUIRED system)
28+
29+
# libev
30+
find_path(libev_INCLUDE_DIRECTORY ev.h)
31+
find_library(libev_LIB ev)
32+
33+
if (NOT libev_INCLUDE_DIRECTORY OR NOT libev_LIB)
34+
message(FATAL_ERROR "Could not find header and/or library for libev")
35+
endif ()
36+
37+
# Mosquitto
38+
find_path(mosquitto_INCLUDE_DIRECTORY mosquitto.h)
39+
find_library(mosquitto_LIB mosquitto)
40+
41+
if (NOT mosquitto_INCLUDE_DIRECTORY OR NOT mosquitto_LIB)
42+
message(FATAL_ERROR "Could not find header and/or library for Mosquitto")
43+
endif ()
44+
45+
# MsgFlo library
46+
add_library(msgflo src/msgflo.cpp src/mqtt_support.cpp src/mqtt_support.h ${JSON11})
47+
target_include_directories(msgflo
48+
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>
49+
PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/thirdparty/json11>
50+
# Boost could made private with little effort, migth be worth.
51+
PUBLIC ${Boost_INCLUDE_DIR}
52+
PRIVATE ${libev_INCLUDE_DIRECTORY}
53+
PRIVATE ${amqp_install}/include
54+
PRIVATE ${mosquitto_INCLUDE_DIRECTORY}
55+
PRIVATE src)
56+
57+
# amqp just as too many unused parameters
58+
target_compile_options(msgflo PRIVATE -Wall -Wextra -Wno-unused-parameter)
59+
60+
target_link_libraries(msgflo
61+
PRIVATE ${Boost_LIBRARIES}
62+
PRIVATE ${amqp_install}/lib/libamqpcpp.a
63+
PRIVATE ${mosquitto_LIB})
64+
target_compile_features(msgflo PUBLIC cxx_range_for)
65+
install(DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/include/"
66+
DESTINATION "include")
67+
68+
add_subdirectory(examples)
69+
70+
add_dependencies(msgflo amqpcpp_project)
71+
72+
# Installation
73+
74+
include(GenerateExportHeader)
75+
include(CMakePackageConfigHelpers)
76+
install(TARGETS msgflo
77+
EXPORT msgflo_export
78+
LIBRARY DESTINATION lib
79+
ARCHIVE DESTINATION lib
80+
INCLUDES include)
81+
82+
install(EXPORT msgflo_export
83+
FILE MsgFloTargets.cmake
84+
NAMESPACE MsgFlo::
85+
DESTINATION lib/cmake/MsgFlo)
86+
87+
configure_file(cmake/MsgFloConfig.cmake
88+
COPYONLY
89+
)
90+
91+
write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/MsgFlo/MsgFloConfigVersion.cmake"
92+
VERSION ${MSGFLO_VERSION}
93+
COMPATIBILITY AnyNewerVersion)
94+
95+
install(
96+
FILES cmake/MsgFloConfig.cmake "${CMAKE_CURRENT_BINARY_DIR}/MsgFlo/MsgFloConfigVersion.cmake"
97+
DESTINATION lib/cmake/MsgFlo)

Makefile

Lines changed: 0 additions & 23 deletions
This file was deleted.

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,10 @@ msgflo-cpp is written in C++11 and is built on top of [AMQP-CPP](https://github.
1818

1919
See [./examples/repeat.cpp](./examples/repeat.cpp)
2020

21+
mkdir build
22+
cmake ..
2123
make
22-
./build/repeat-cpp
24+
./examples/repeat
2325

2426
## License
2527

build.sh

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
#!/bin/bash
2+
3+
set -e
4+
5+
mkdir -p build
6+
cd build
7+
cmake .. -DCMAKE_INSTALL_PREFIX=$HOME/opt/msgflo-cpp
8+
make -j
9+
make install
10+
cd ..

cmake/MsgFloConfig.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
include("${CMAKE_CURRENT_LIST_DIR}/MsgFloTargets.cmake")

examples/CMakeLists.txt

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# If we're not included by the msgflo project, find the sources the normal way. This is what you should do in your
2+
# application
3+
if (CMAKE_CURRENT_SOURCE_DIR STREQUAL CMAKE_SOURCE_DIR)
4+
cmake_minimum_required(VERSION 3.5)
5+
project(msgflo_cpp_examples CXX)
6+
7+
find_package(MsgFlo)
8+
set(msgflo_lib MsgFlo::msgflo)
9+
else ()
10+
set(msgflo_lib msgflo)
11+
endif ()
12+
13+
add_executable(repeat repeat.cpp)
14+
target_compile_features(repeat PUBLIC cxx_range_for)
15+
target_link_libraries(repeat PUBLIC ${msgflo_lib} ev pthread)

0 commit comments

Comments
 (0)