diff --git a/.github/workflows/cmake.yml b/.github/workflows/cmake.yml index 3845f4d..341ecc0 100644 --- a/.github/workflows/cmake.yml +++ b/.github/workflows/cmake.yml @@ -1,4 +1,4 @@ -name: CMake +name: CMake on Windows on: [push] @@ -15,7 +15,7 @@ jobs: runs-on: windows-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v3 with: submodules: true diff --git a/.github/workflows/ubuntu.yml b/.github/workflows/ubuntu.yml new file mode 100644 index 0000000..832fdd7 --- /dev/null +++ b/.github/workflows/ubuntu.yml @@ -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 diff --git a/CMakeLists.txt b/CMakeLists.txt index 538a3cb..c6c10e0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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) diff --git a/cmake/FindLibuuid.cmake b/cmake/FindLibuuid.cmake new file mode 100644 index 0000000..383140f --- /dev/null +++ b/cmake/FindLibuuid.cmake @@ -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 () diff --git a/cmake/FindPahoMqttC.cmake b/cmake/FindPahoMqttC.cmake new file mode 100644 index 0000000..b3e7ec3 --- /dev/null +++ b/cmake/FindPahoMqttC.cmake @@ -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) diff --git a/mqtt-plugin/CMakeLists.txt b/mqtt-plugin/CMakeLists.txt index 69ca747..6f1917f 100644 --- a/mqtt-plugin/CMakeLists.txt +++ b/mqtt-plugin/CMakeLists.txt @@ -53,8 +53,8 @@ include(OxygenPluginFunctions) set(MSVC_RUNTIME_LIBRARY "MultiThreaded$<$:Debug>") SetCommonOutputDirectory() -SetBoostOptions() -find_package(Boost REQUIRED) +#SetBoostOptions() +#find_package(Boost REQUIRED) find_package(SDKQt REQUIRED) message(STATUS "Qt5Core_RCC_EXECUTABLE = ${Qt5Core_RCC_EXECUTABLE}") @@ -118,7 +118,8 @@ target_link_libraries(${PROJECT_NAME} target_include_directories(${PROJECT_NAME} PUBLIC include - SYSTEM ${Boost_INCLUDE_DIRS} + SYSTEM + #${Boost_INCLUDE_DIRS} ) # diff --git a/mqtt-plugin/externals/fmt/CMakeLists.txt b/mqtt-plugin/externals/fmt/CMakeLists.txt index f25d19a..471f53a 100644 --- a/mqtt-plugin/externals/fmt/CMakeLists.txt +++ b/mqtt-plugin/externals/fmt/CMakeLists.txt @@ -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) diff --git a/mqtt-plugin/externals/oxygen-sdk/CMakeLists.txt b/mqtt-plugin/externals/oxygen-sdk/CMakeLists.txt index cc2d4b8..d437426 100644 --- a/mqtt-plugin/externals/oxygen-sdk/CMakeLists.txt +++ b/mqtt-plugin/externals/oxygen-sdk/CMakeLists.txt @@ -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) # diff --git a/mqtt-plugin/externals/paho-mqtt-cpp/CMakeLists.txt b/mqtt-plugin/externals/paho-mqtt-cpp/CMakeLists.txt index 35adf7d..265e931 100644 --- a/mqtt-plugin/externals/paho-mqtt-cpp/CMakeLists.txt +++ b/mqtt-plugin/externals/paho-mqtt-cpp/CMakeLists.txt @@ -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() diff --git a/mqtt-plugin/include/Service.h b/mqtt-plugin/include/Service.h index 1469f65..40c638a 100644 --- a/mqtt-plugin/include/Service.h +++ b/mqtt-plugin/include/Service.h @@ -1,19 +1,19 @@ #pragma once -// -#include -#include -#include - // #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 +#include + +// +#include +#include +#include namespace plugin::mqtt { diff --git a/mqtt-plugin/include/configuration/Configuration.h b/mqtt-plugin/include/configuration/Configuration.h index e691598..5468703 100644 --- a/mqtt-plugin/include/configuration/Configuration.h +++ b/mqtt-plugin/include/configuration/Configuration.h @@ -71,7 +71,7 @@ namespace plugin::mqtt::config * @brief Get the Publish Handlers * @return Topics */ - Topics Configuration::getPublishers(); + Topics getPublishers(); /** * @brief Get the Servers diff --git a/mqtt-plugin/include/resampling/Stream.h b/mqtt-plugin/include/resampling/Stream.h index 9bb0c73..9312858 100644 --- a/mqtt-plugin/include/resampling/Stream.h +++ b/mqtt-plugin/include/resampling/Stream.h @@ -3,6 +3,7 @@ #include "resampling/StreamClock.h" // +#include #include #include diff --git a/mqtt-plugin/include/resampling/StreamClock.h b/mqtt-plugin/include/resampling/StreamClock.h index 7a30e0f..84549b7 100644 --- a/mqtt-plugin/include/resampling/StreamClock.h +++ b/mqtt-plugin/include/resampling/StreamClock.h @@ -1,7 +1,7 @@ #pragma once // -#include +#include #include namespace plugin::mqtt diff --git a/mqtt-plugin/include/subscription/Channel.h b/mqtt-plugin/include/subscription/Channel.h index 36a12a8..b59a612 100644 --- a/mqtt-plugin/include/subscription/Channel.h +++ b/mqtt-plugin/include/subscription/Channel.h @@ -4,13 +4,12 @@ #include "Types.h" #include "subscription/decoding/Decoder.h" +#include + // #include #include -// -#include "mqtt/message.h" - namespace plugin::mqtt { using namespace ::mqtt; diff --git a/mqtt-plugin/include/subscription/Subscription.h b/mqtt-plugin/include/subscription/Subscription.h index eaeb2a4..b1140ed 100644 --- a/mqtt-plugin/include/subscription/Subscription.h +++ b/mqtt-plugin/include/subscription/Subscription.h @@ -1,19 +1,19 @@ #pragma once -// -#include -#include -#include -#include -#include - // #include "Types.h" #include "subscription/Channel.h" #include "subscription/decoding/Decoder.h" // -#include "mqtt/message.h" +#include + +// +#include +#include +#include +#include +#include namespace plugin::mqtt { diff --git a/mqtt-plugin/src/MqttPlugin.cpp b/mqtt-plugin/src/MqttPlugin.cpp index f220137..040f843 100644 --- a/mqtt-plugin/src/MqttPlugin.cpp +++ b/mqtt-plugin/src/MqttPlugin.cpp @@ -12,7 +12,7 @@ #include "qml.rcc.h" // -#include "fmt/core.h" +#include using namespace odk::framework; diff --git a/mqtt-plugin/src/Utility.cpp b/mqtt-plugin/src/Utility.cpp index 658717b..79026f3 100644 --- a/mqtt-plugin/src/Utility.cpp +++ b/mqtt-plugin/src/Utility.cpp @@ -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 } \ No newline at end of file diff --git a/mqtt-plugin/src/resampling/Stream.cpp b/mqtt-plugin/src/resampling/Stream.cpp index 0b1cb2c..0d7cba2 100644 --- a/mqtt-plugin/src/resampling/Stream.cpp +++ b/mqtt-plugin/src/resampling/Stream.cpp @@ -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(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(nominal_sampling_rate)), + m_unrecoverable(false), + m_actual_scnt(0), + m_packet_received_counter(0) { } @@ -191,13 +191,13 @@ void Stream::append(std::vector 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 NaN; NaN.resize(static_cast(diff)); diff --git a/tests/TestResampler.cpp b/tests/TestResampler.cpp index 33e90b8..4c3c7df 100644 --- a/tests/TestResampler.cpp +++ b/tests/TestResampler.cpp @@ -62,7 +62,7 @@ class TestStream Packet p; p.timestamp = m_samples[num_samples - 1].timestamp; - for (int i = 0; i < num_samples; i++) + for (size_t i = 0; i < num_samples; i++) { Sample s = m_samples.front(); p.samples.push_back(s.value);