Skip to content

Supported travis-ci and appveyor. #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 8, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 21 additions & 37 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,46 +1,30 @@
sudo: false
language: cpp
os:
- linux
- osx
cache:
- apt
compiler:
- clang
- gcc
os:
- osx
- linux
before_install:
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:ubuntu-toolchain-r/test; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo add-apt-repository -y ppa:h-rayflood/llvm-upper; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update -qq; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get update; fi
install:
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -qq gcc-5-multilib g++-5-multilib; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install --allow-unauthenticated -qq clang-3.6; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/g++-4.8 90; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/gcc-4.8 90; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y lib32gcc1; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y libc6-i386; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y lib32z1-dev; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y lib32stdc++6; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y bzip2; fi
- if [ "$TRAVIS_OS_NAME" == "linux" ]; then sudo apt-get install -y libc6-dbg; fi
- clang++
# - g++

- if [ "$TRAVIS_OS_NAME" == "osx" ]; then brew unlink boost; fi
- if [ "$BOOST" == "boost" ]; then wget http://sourceforge.net/projects/boost/files/boost/1.59.0/boost_1_59_0.zip && unzip -q boost_1_59_0.zip && cd boost_1_59_0 && ./bootstrap.sh && ./b2 --with-timer --with-chrono address-model="$ARCH" > /dev/null && sudo ./b2 --with-timer --with-chrono address-model="$ARCH" install > /dev/null && cd ..; fi
install:
- if [ "$CXX" = "g++" ]; then export CXXFLAGS="-std=c++14"; fi
- if [ "$CXX" = "g++" ]; then export CXX="g++-5" CC="gcc-5"; fi
- if [ "$CXX" = "clang++" ]; then export CXXFLAGS="-std=c++14"; fi
- if [ "$CXX" = "clang++" ]; then export CXX="clang++-3.7" CC="clang-3.7"; fi
- wget -O boost_1_59_0.tar.bz2 http://sourceforge.net/projects/boost/files/latest/download?source=files && tar xf boost_1_59_0.tar.bz2 && cd boost_1_59_0 && cp ../user-config.jam . && cat user-config.jam && ./bootstrap.sh && ./b2 install --address-model=64 --with-system --with-test --prefix=../boost > /dev/null && cd ..
addons:
apt:
sources:
- ubuntu-toolchain-r-test
- llvm-toolchain-precise-3.7
- llvm-toolchain-precise
packages:
- clang-3.7
- g++-5
- gcc-5
- cmake

env:
- FLAGS="-DMQTT_NO_TLS=ON"
- FLAGS="-DMQTT_NO_TLS=OFF"

before_script:
- export PATH=/usr/local/bin:$PATH

matrix:
exclude:
- os: osx
compiler: gcc

script:
- git clean -xdf && mkdir build && cd build && cmake $FLAGS .. && make && make test
- mkdir build && cd build && cmake $FLAGS -DBoost_NO_SYSTEM_PATHS=ON -DBOOST_ROOT=`pwd`/../boost -DBOOST_INCLUDEDIR=`pwd`/../boost/include -DBOOST_LIBRARYDIR=`pwd`/../boost/lib .. && make VERBOSE=1 && ctest -VV
17 changes: 16 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,28 @@ CMAKE_MINIMUM_REQUIRED (VERSION 2.8.6)
PROJECT (mqtt_client_cpp)

IF (MQTT_NO_TLS)
SET (CMAKE_CXX_FLAGS "-DMQTT_NO_TLS ${CMAKE_CXX_FLAGS}")
SET (CMAKE_CXX_FLAGS "-DMQTT_NO_TLS ${CMAKE_CXX_FLAGS}")
ELSE ()
FIND_PACKAGE (OpenSSL)
ENDIF ()

SET (Boost_USE_STATIC_LIBS ON) # only find static libs
SET (Boost_USE_MULTITHREADED ON)
# SET (Boost_USE_STATIC_RUNTIME OFF)
FIND_PACKAGE (Boost 1.59.0 COMPONENTS chrono timer test_exec_monitor system)
FIND_PACKAGE (Threads)

INCLUDE_DIRECTORIES (
${Boost_INCLUDE_DIR}
include
)

IF (NOT MQTT_NO_TLS)
LIST (APPEND INCLUDE_DIRECTORIES
${OpenSSL_INCLUDE_DIR}
)
ENDIF ()

ENABLE_TESTING ()
ADD_SUBDIRECTORY (test)
ADD_SUBDIRECTORY (example)
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
MQTT client for C++14 based on Boost.Asio
=========================================

Version 0.1.0 [![Build Status](https://travis-ci.org/redboltz/mqtt_client_cpp.svg?branch=master)](https://travis-ci.org/redboltz/mqtt_client_cpp) [![Build status](https://ci.appveyor.com/api/projects/status/8kstcgt79qj123mw/branch/master?svg=true)](https://ci.appveyor.com/project/redboltz/mqtt_client_cpp/branch/master)
Version 0.1.0 [![Build Status](https://travis-ci.org/redboltz/mqtt_client_cpp.svg?branch=master)](https://travis-ci.org/redboltz/mqtt_client_cpp) [![Build status](https://ci.appveyor.com/api/projects/status/21a267hd34s0kqu5?svg=true)](https://ci.appveyor.com/project/redboltz/mqtt_client_cpp/branch/master)

Overview
--------
Expand Down Expand Up @@ -36,6 +36,14 @@ make test

In order to build tests, you need to prepare the Boost Libraries 1.59.0.

Documents
---------

You can create html documents using doxygen.

```
make doxygen
```

License
-------
Expand Down
14 changes: 11 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,20 @@ version: 0.1.0.{build}
environment:
matrix:
- notls: -DMQTT_NO_TLS=ON
- notls: -DMQTT_NO_TLS=OFF
# - notls: -DMQTT_NO_TLS=OFF

install:
- ps: Start-FileDownload 'http://slproweb.com/download/Win32OpenSSL_Light-1_0_2e.exe'
- ps: Start-Process "Win32OpenSSL_Light-1_0_2e.exe" -ArgumentList "/silent /verysilent /sp- /suppressmsgboxes" -Wait

build_script:
- md build
- cd build
- cmake %notls% ..
- cmake %notls% -DBoost_NO_SYSTEM_PATHS=ON -DBOOST_ROOT="C:\Libraries\boost_1_59_0" -DBOOST_INCLUDEDIR="C:\Libraries\boost_1_59_0\include" -DBOOST_LIBRARYDIR="C:\Libraries\boost_1_59_0\lib32-msvc-14.0" -DCMAKE_CXX_FLAGS="/IC:\Libraries\boost_1_59_0\include /EHsc" -DBoost_LIBRARY_DIRS=C:\Libraries\boost_1_59_0\stage\lib -DCMAKE_EXE_LINKER_FLAGS=/LIBPATH:C:\Libraries\boost_1_59_0\lib32-msvc-14.0 ..
- cmake --build . --config Release

test_script:
- ctest -V
- SET PATH=C:\Libraries\boost_1_59_0\lib32-msvc-14.0;%PATH%
- cd test
- cd Release
- mqtt_client_cpp_test --log_level=all
22 changes: 11 additions & 11 deletions example/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,19 @@ FOREACH (source_file ${exec_PROGRAMS})
${source_file_we}
${source_file}
)
IF (MQTT_NO_TLS)
TARGET_LINK_LIBRARIES (${source_file_we}
boost_system
pthread
)
ELSE ()
TARGET_LINK_LIBRARIES (${source_file_we}
boost_system
pthread
ssl
crypto
LIST (APPEND MQTT_LINK_LIBRARIES
${Boost_SYSTEM_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
)
IF (NOT MQTT_NO_TLS)
LIST (APPEND MQTT_LINK_LIBRARIES
${OPENSSL_LIBRARIES}
)
ENDIF ()
LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
TARGET_LINK_LIBRARIES (${source_file_we}
${MQTT_LINK_LIBRARIES}
)
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "Clang" OR "${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU")
SET_PROPERTY (TARGET ${source_file_we}
APPEND_STRING PROPERTY COMPILE_FLAGS "-std=c++14 -Wall -Wextra -pthread -g -O0")
Expand Down
27 changes: 14 additions & 13 deletions include/mqtt/client.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include <vector>
#include <functional>
#include <set>
#include <memory>

#include <boost/optional.hpp>
#include <boost/lexical_cast.hpp>
Expand Down Expand Up @@ -296,8 +297,8 @@ class client {
* Before calling connect(), call set_xxx member functions to configure the connection.
*/
void connect() {
static as::ip::tcp::resolver r(ios_);
static as::ip::tcp::resolver::query q(host_, port_);
as::ip::tcp::resolver r(ios_);
as::ip::tcp::resolver::query q(host_, port_);
auto it = r.resolve(q);
#if defined(MQTT_NO_TLS)
socket_.reset(new Socket(ios_));
Expand Down Expand Up @@ -774,28 +775,28 @@ class client {

class send_buffer {
public:
send_buffer():buf_(payload_position_, 0) {}
send_buffer():buf_(std::make_shared<std::string>(static_cast<int>(payload_position_), 0)) {}

std::string const& buf() const {
return buf_;
return *buf_;
}

std::string& buf() {
return buf_;
return *buf_;
}

std::pair<char const*, std::size_t> finalize(std::uint8_t fixed_header) {
auto rb = remaining_bytes(buf_.size() - payload_position_);
auto rb = remaining_bytes(buf_->size() - payload_position_);
std::size_t start_position = payload_position_ - rb.size() - 1;
buf_[start_position] = fixed_header;
buf_.replace(start_position + 1, rb.size(), rb);
(*buf_)[start_position] = fixed_header;
buf_->replace(start_position + 1, rb.size(), rb);
return std::make_pair(
buf_.data() + start_position,
buf_.size() - start_position);
buf_->data() + start_position,
buf_->size() - start_position);
}
private:
static constexpr std::size_t const payload_position_ = 5;
std::string buf_;
std::shared_ptr<std::string> buf_;
};

struct resend {
Expand Down Expand Up @@ -1211,7 +1212,7 @@ class client {
std::uint16_t packet_id,
std::string const& topic_name,
std::uint8_t qos, Args... args) {
params.push_back(std::make_pair(topic_name, qos));
params.push_back(std::make_pair(std::cref(topic_name), qos));
send_subscribe(params, packet_id, args...);
}

Expand Down Expand Up @@ -1239,7 +1240,7 @@ class client {
std::uint16_t packet_id,
std::string const& topic_name,
Args... args) {
params.push_back(topic_name);
params.push_back(std::cref(topic_name));
send_unsubscribe(params, packet_id, args...);
}

Expand Down
2 changes: 1 addition & 1 deletion include/mqtt/connect_flags.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ inline constexpr bool has_user_name_flag(char v) {
return v & user_name_flag;
}

inline constexpr void set_will_qos(char& v, std::size_t qos) {
inline void set_will_qos(char& v, std::size_t qos) {
v |= (qos & 0b00000011) << 3;
}

Expand Down
4 changes: 2 additions & 2 deletions include/mqtt/str_connect_return_code.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@
namespace mqtt {

inline
constexpr char const* connect_return_code_to_str(std::uint8_t v) {
constexpr char const* str[] = {
char const* connect_return_code_to_str(std::uint8_t v) {
char const * const str[] = {
"accepted",
" unacceptable_protocol_version",
"identifier_rejected",
Expand Down
4 changes: 2 additions & 2 deletions include/mqtt/str_qos.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ namespace mqtt {
namespace qos {

inline
constexpr char const* to_str(std::uint8_t v) {
constexpr char const* str[] = {
char const* to_str(std::uint8_t v) {
char const * const str[] = {
"at_most_once",
"at_least_once",
"at_exactly_once"
Expand Down
23 changes: 23 additions & 0 deletions include/mqtt_client_cpp.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
// Copyright Takatoshi Kondo 2015
//
// Distributed under the Boost Software License, Version 1.0.
// (See accompanying file LICENSE_1_0.txt or copy at
// http://www.boost.org/LICENSE_1_0.txt)


#include <mqtt/client.hpp>
#include <mqtt/connect_flags.hpp>
#include <mqtt/connect_return_code.hpp>
#include <mqtt/control_packet_type.hpp>
#include <mqtt/encoded_length.hpp>
#include <mqtt/exception.hpp>
#include <mqtt/fixed_header.hpp>
#include <mqtt/hexdump.hpp>
#include <mqtt/publish.hpp>
#include <mqtt/qos.hpp>
#include <mqtt/remaining_length.hpp>
#include <mqtt/session_present.hpp>
#include <mqtt/str_connect_return_code.hpp>
#include <mqtt/str_qos.hpp>
#include <mqtt/utf8encoded_strings.hpp>
#include <mqtt/will.hpp>
19 changes: 14 additions & 5 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,21 @@ LIST (APPEND check_PROGRAMS
)

ADD_EXECUTABLE (${PROJECT_NAME} ${check_PROGRAMS})

LIST (APPEND MQTT_LINK_LIBRARIES
${Boost_TEST_EXEC_MONITOR_LIBRARY}
${Boost_SYSTEM_LIBRARY}
${CMAKE_THREAD_LIBS_INIT}
)
IF (NOT MQTT_NO_TLS)
LIST (APPEND MQTT_LINK_LIBRARIES
${OPENSSL_LIBRARIES}
)
ENDIF ()

LINK_DIRECTORIES(${Boost_LIBRARY_DIRS})
TARGET_LINK_LIBRARIES (${PROJECT_NAME}
boost_test_exec_monitor
boost_system
pthread
ssl
crypto
${MQTT_LINK_LIBRARIES}
)

ADD_TEST (${PROJECT_NAME} ${PROJECT_NAME})
Expand Down
Loading