Skip to content

Commit

Permalink
build: initial build support for Ubuntu 22.04
Browse files Browse the repository at this point in the history
fix MSVC build

fix windows, start linux CI

Remove dependency on boost

fix qt dependency

fix mqtt dependency

Start CMake build

Reenable pugixml

fix missing mqttpp lib
  • Loading branch information
matthiasstraka committed Aug 31, 2023
1 parent 989027a commit 3de5098
Show file tree
Hide file tree
Showing 19 changed files with 176 additions and 73 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/cmake.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: CMake
name: CMake on Windows

on: [push]

Expand All @@ -15,7 +15,7 @@ jobs:
runs-on: windows-latest

steps:
- uses: actions/checkout@v2
- uses: actions/checkout@v3
with:
submodules: true

Expand Down
28 changes: 28 additions & 0 deletions .github/workflows/ubuntu.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
name: CMake on Ubuntu

on: [push]

env:
# Customize the CMake build type here (Release, Debug, RelWithDebInfo, etc.)
BUILD_TYPE: Release

jobs:
build:
# The CMake configure and build commands are platform agnostic and should work equally
# well on Windows or Mac. You can convert this to a matrix build if you need
# cross-platform coverage.
# See: https://docs.github.com/en/free-pro-team@latest/actions/learn-github-actions/managing-complex-workflows#using-a-build-matrix
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v3
with:
submodules: true

- name: Install dev requirements
run: sudo apt install -yq libfmt-dev libpaho-mqtt-dev libpaho-mqttpp-dev qtbase5-dev

- name: Configure CMake
run: cmake -B ${{github.workspace}}/build -DCMAKE_BUILD_TYPE=${{env.BUILD_TYPE}} -DCMAKE_CXX_COMPILER=g++ -DBUILD_PLUGIN_WITH_TESTS=OFF

- name: Build
run: cmake --build ${{github.workspace}}/build --target all --parallel
13 changes: 10 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,20 @@ cmake_minimum_required(VERSION 3.20)

project(mqttplugin)

IF (MSVC)
ELSE()
LIST(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
ENDIF()

#
# Default: Disable Plugin/Firmware-Tests
option(BUILD_PLUGIN_WITH_TESTS "Build plugin with tests." OFF)
option(BUILD_PLUGIN_WITH_TESTS "Build plugin with tests" OFF)

if(BUILD_PLUGIN_WITH_TESTS)
# Ensure CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS is TRUE when Building with tests
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
if (WIN32)
# Ensure CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS is TRUE when Building with tests
set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS TRUE)
endif()
endif()

add_subdirectory(mqtt-plugin)
Expand Down
17 changes: 17 additions & 0 deletions cmake/FindLibuuid.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
find_path(Libuuid_INCLUDE_DIRS uuid/uuid.h)
find_library(Libuuid_LIBRARIES uuid)

if (Libuuid_LIBRARIES AND Libuuid_INCLUDE_DIRS)
set(Libuuid_FOUND YES)
if (NOT Libuuid_FIND_QUIETLY)
message(STATUS "Found libuuid: ${Libuuid_LIBRARIES}")
endif ()
else ()
if (Libuuid_FIND_REQUIRED)
message(SEND_ERROR "Could NOT find libuuid")
else ()
if (NOT Libuuid_FIND_QUIETLY)
message(STATUS "Could NOT find libuuid")
endif ()
endif ()
endif ()
34 changes: 34 additions & 0 deletions cmake/FindPahoMqttC.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# find the Paho MQTT C library
if(PAHO_WITH_SSL)
set(_PAHO_MQTT_C_LIB_NAME paho-mqtt3as)
find_package(OpenSSL REQUIRED)
else()
set(_PAHO_MQTT_C_LIB_NAME paho-mqtt3a)
endif()

# add suffix when using static Paho MQTT C library variant on Windows
if(WIN32)
if(PAHO_BUILD_STATIC)
set(_PAHO_MQTT_C_LIB_NAME ${_PAHO_MQTT_C_LIB_NAME}-static)
endif()
endif()

find_library(PAHO_MQTT_C_LIBRARIES NAMES ${_PAHO_MQTT_C_LIB_NAME})
unset(_PAHO_MQTT_C_LIB_NAME)
find_path(PAHO_MQTT_C_INCLUDE_DIRS NAMES MQTTAsync.h)

add_library(PahoMqttC::PahoMqttC UNKNOWN IMPORTED)

set_target_properties(PahoMqttC::PahoMqttC PROPERTIES
IMPORTED_LOCATION "${PAHO_MQTT_C_LIBRARIES}"
INTERFACE_INCLUDE_DIRECTORIES "${PAHO_MQTT_C_INCLUDE_DIRS}"
IMPORTED_LINK_INTERFACE_LANGUAGES "C")
if(PAHO_WITH_SSL)
set_target_properties(PahoMqttC::PahoMqttC PROPERTIES
INTERFACE_COMPILE_DEFINITIONS "OPENSSL=1"
INTERFACE_LINK_LIBRARIES "OpenSSL::SSL;OpenSSL::Crypto")
endif()

include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(PahoMqttC
REQUIRED_VARS PAHO_MQTT_C_LIBRARIES PAHO_MQTT_C_INCLUDE_DIRS)
7 changes: 4 additions & 3 deletions mqtt-plugin/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ include(OxygenPluginFunctions)
set(MSVC_RUNTIME_LIBRARY "MultiThreaded$<$<CONFIG:Debug>:Debug>")

SetCommonOutputDirectory()
SetBoostOptions()
find_package(Boost REQUIRED)
#SetBoostOptions()
#find_package(Boost REQUIRED)
find_package(SDKQt REQUIRED)

message(STATUS "Qt5Core_RCC_EXECUTABLE = ${Qt5Core_RCC_EXECUTABLE}")
Expand Down Expand Up @@ -118,7 +118,8 @@ target_link_libraries(${PROJECT_NAME}

target_include_directories(${PROJECT_NAME}
PUBLIC include
SYSTEM ${Boost_INCLUDE_DIRS}
SYSTEM
#${Boost_INCLUDE_DIRS}
)

#
Expand Down
15 changes: 10 additions & 5 deletions mqtt-plugin/externals/fmt/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
)
IF (WIN32)
FetchContent_Declare(
fmt
GIT_REPOSITORY https://github.com/fmtlib/fmt.git
)

FetchContent_MakeAvailable(fmt)
ELSE()
find_package(fmt REQUIRED)
ENDIF()

FetchContent_MakeAvailable(fmt)
target_link_libraries(${PROJECT_NAME} PUBLIC fmt::fmt)
21 changes: 12 additions & 9 deletions mqtt-plugin/externals/oxygen-sdk/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,19 @@ if(NOT DEFINED ENV{OXYGEN_SDK_ROOT})
GIT_REPOSITORY https://github.com/DEWETRON/OXYGEN-SDK.git
)

#
# Fetch boost
SET(BOOST_UNPACK_PATH ${oxygen_SOURCE_DIR}/3rdparty/boost_1_70_0/)
if (WIN32_DISABLED)
message(STATUS "Fetching Boost...")
#
# Fetch boost
SET(BOOST_UNPACK_PATH ${oxygen_SOURCE_DIR}/3rdparty/boost_1_70_0/)

# message(STATUS "Fetching boost v1.70.0...")
FetchContent_Populate(
boost_1_70_0
URL https://boostorg.jfrog.io/artifactory/main/release/1.70.0/source/boost_1_70_0.zip
SOURCE_DIR ${BOOST_UNPACK_PATH}
)
# message(STATUS "Fetching boost v1.70.0...")
FetchContent_Populate(
boost_1_70_0
URL https://boostorg.jfrog.io/artifactory/main/release/1.70.0/source/boost_1_70_0.zip
SOURCE_DIR ${BOOST_UNPACK_PATH}
)
ENDIF()

if(WIN32)
#
Expand Down
46 changes: 27 additions & 19 deletions mqtt-plugin/externals/paho-mqtt-cpp/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,22 +1,30 @@
set(PAHO_BUILD_SHARED OFF CACHE INTERNAL "")
set(PAHO_BUILD_STATIC ON CACHE INTERNAL "")
set(PAHO_ENABLE_TESTING OFF CACHE INTERNAL "")
set(PAHO_BUILD_TESTS OFF CACHE INTERNAL "")
set(PAHO_WITH_MQTT_C ON CACHE INTERNAL "")

#
# TODO Change to official paho.mqtt.cpp repository once patches to CMake build system have been accepted
FetchContent_Declare(
paho-mqttpp3-static
GIT_REPOSITORY https://github.com/HpLightcorner/paho.mqtt.cpp.git
GIT_TAG mqtt-c-submodule
)
IF (MSVC)
message(STATUS "Setting up PAHO MQTT for Windows")
set(PAHO_BUILD_SHARED OFF CACHE INTERNAL "")
set(PAHO_BUILD_STATIC ON CACHE INTERNAL "")
set(PAHO_ENABLE_TESTING OFF CACHE INTERNAL "")
set(PAHO_BUILD_TESTS OFF CACHE INTERNAL "")
set(PAHO_WITH_MQTT_C ON CACHE INTERNAL "")

FetchContent_MakeAvailable(paho-mqttpp3-static)
target_include_directories(${PROJECT_NAME} INTERFACE
${paho-mqttpp3-static_SOURCE_DIR}/src
)
#
# TODO Change to official paho.mqtt.cpp repository once patches to CMake build system have been accepted
FetchContent_Declare(
paho-mqttpp3-static
GIT_REPOSITORY https://github.com/HpLightcorner/paho.mqtt.cpp.git
GIT_TAG mqtt-c-submodule
)

target_link_libraries(${PROJECT_NAME} PUBLIC
paho-mqttpp3-static
)
FetchContent_MakeAvailable(paho-mqttpp3-static)
target_include_directories(${PROJECT_NAME} INTERFACE
${paho-mqttpp3-static_SOURCE_DIR}/src
)

target_link_libraries(${PROJECT_NAME} PUBLIC
paho-mqttpp3-static
)
ELSE()
message(STATUS "Setting up PAHO MQTT for Linux")
find_package(PahoMqttC REQUIRED)
target_link_libraries(${PROJECT_NAME} PUBLIC PahoMqttC::PahoMqttC)
ENDIF()
14 changes: 7 additions & 7 deletions mqtt-plugin/include/Service.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#pragma once

//
#include <memory>
#include <functional>
#include <mutex>

//
#include "configuration/Server.h"
#include "subscription/Subscription.h"
#include "publish/Publish.h"
#include "Types.h"
#include "fmt/core.h"

//
#include "mqtt/async_client.h"
#include <fmt/core.h>
#include <mqtt/async_client.h>

//
#include <memory>
#include <functional>
#include <mutex>

namespace plugin::mqtt
{
Expand Down
2 changes: 1 addition & 1 deletion mqtt-plugin/include/configuration/Configuration.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ namespace plugin::mqtt::config
* @brief Get the Publish Handlers
* @return Topics
*/
Topics Configuration::getPublishers();
Topics getPublishers();

/**
* @brief Get the Servers
Expand Down
1 change: 1 addition & 0 deletions mqtt-plugin/include/resampling/Stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include "resampling/StreamClock.h"

//
#include <cstdint>
#include <optional>
#include <vector>

Expand Down
2 changes: 1 addition & 1 deletion mqtt-plugin/include/resampling/StreamClock.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

//
#include <ctype.h>
#include <cstdint>
#include <memory>

namespace plugin::mqtt
Expand Down
5 changes: 2 additions & 3 deletions mqtt-plugin/include/subscription/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,12 @@
#include "Types.h"
#include "subscription/decoding/Decoder.h"

#include <mqtt/message.h>

//
#include <memory>
#include <vector>

//
#include "mqtt/message.h"

namespace plugin::mqtt
{
using namespace ::mqtt;
Expand Down
16 changes: 8 additions & 8 deletions mqtt-plugin/include/subscription/Subscription.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#pragma once

//
#include <map>
#include <vector>
#include <functional>
#include <string>
#include <optional>

//
#include "Types.h"
#include "subscription/Channel.h"
#include "subscription/decoding/Decoder.h"

//
#include "mqtt/message.h"
#include <mqtt/message.h>

//
#include <map>
#include <vector>
#include <functional>
#include <string>
#include <optional>

namespace plugin::mqtt
{
Expand Down
2 changes: 1 addition & 1 deletion mqtt-plugin/src/MqttPlugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#include "qml.rcc.h"

//
#include "fmt/core.h"
#include <fmt/core.h>

using namespace odk::framework;

Expand Down
2 changes: 1 addition & 1 deletion mqtt-plugin/src/Utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ std::string getCurrentDllPath()
GetModuleFileNameA(phModule, path, sizeof(path));
std::filesystem::path res(path);
return res.parent_path().u8string();
#elif
#else
return std::string();
#endif
}
18 changes: 9 additions & 9 deletions mqtt-plugin/src/resampling/Stream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,13 @@ namespace

}

Stream::Stream(StreamClock::Pointer clock, int nominal_sampling_rate) : m_clock(clock),
m_unrecoverable(false),
m_estimated_sampling_rate(std::nullopt),
m_nominal_sampling_interval(1 / static_cast<double>(nominal_sampling_rate)),
m_nominal_sampling_rate(nominal_sampling_rate),
m_actual_scnt(0),
m_packet_received_counter(0)
Stream::Stream(StreamClock::Pointer clock, int nominal_sampling_rate) :
m_clock(clock),
m_nominal_sampling_rate(nominal_sampling_rate),
m_nominal_sampling_interval(1 / static_cast<double>(nominal_sampling_rate)),
m_unrecoverable(false),
m_actual_scnt(0),
m_packet_received_counter(0)
{
}

Expand Down Expand Up @@ -191,13 +191,13 @@ void Stream::append(std::vector<double> samples, double incoming_ts_seconds, std
if (aligned_ts_seconds > (expected_packet_timestamp + (nominal_packet_interval * 0.25)))
{
// Packet lost based on timetamp estimation, align with stream
const auto diff = num - samples.size();

if (diff < 0)
if (num < samples.size())
{
m_unrecoverable = true;
throw std::runtime_error("Error while recovering stream.");
}
const auto diff = num - samples.size();

std::vector<double> NaN;
NaN.resize(static_cast<size_t>(diff));
Expand Down
Loading

0 comments on commit 3de5098

Please sign in to comment.