Skip to content

Commit 08ba0f1

Browse files
authored
MQTT module aligning with external module layout (#11)
- CMakeLists.txt files updating according new external module layout; - Fixes to build module with installed openDAQ; - Warning fixes; - rapidjson lib is aligned with openDAQ rapidjson lib;
1 parent 5d4e584 commit 08ba0f1

File tree

94 files changed

+19595
-529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

94 files changed

+19595
-529
lines changed

.github/workflows/ci.yml

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
name: Build and Test
22

33
on:
4+
workflow_dispatch:
5+
inputs:
6+
opendaq_ref:
7+
description: "openDAQ SDK commit, branch or tag"
8+
required: false
9+
default: ""
410
pull_request:
511
types: [opened, reopened, synchronize, ready_for_review]
612

@@ -12,8 +18,16 @@ jobs:
1218
include:
1319
- os: ubuntu-latest
1420
generator: Ninja
21+
build_type: Debug
1522
- os: windows-latest
1623
generator: "Visual Studio 17 2022"
24+
build_type: Debug
25+
- os: ubuntu-latest
26+
generator: Ninja
27+
build_type: Release
28+
- os: windows-latest
29+
generator: "Visual Studio 17 2022"
30+
build_type: Release
1731

1832
runs-on: ${{ matrix.os }}
1933

@@ -28,11 +42,15 @@ jobs:
2842
with:
2943
ref: ${{ github.event.inputs.branch || github.event.client_payload.branch || github.ref }}
3044

45+
- name: Overwrite opendaq_ref
46+
if: ${{ github.event.inputs.opendaq_ref != '' }}
47+
run: echo "${{ github.event.inputs.opendaq_ref }}" > opendaq_ref
48+
3149
- name: Configure project with CMake
32-
run: cmake -B build/output -S . -G "${{ matrix.generator }}" -DOPENDAQ_MQTT_ENABLE_TESTS=ON -DCMAKE_BUILD_TYPE=Debug
50+
run: cmake -B build/output -S . -G "${{ matrix.generator }}" -DDAQMODULES_MQTT_ENABLE_TESTS=ON -DDAQMODULES_MQTT_DEBUG_WARNINGS_AS_ERRORS=ON -DOPENDAQ_DEBUG_WARNINGS_AS_ERRORS=ON -DCMAKE_BUILD_TYPE="${{ matrix.build_type }}"
3351

3452
- name: Build project with CMake
35-
run: cmake --build build/output --config Debug
53+
run: cmake --build build/output --config "${{ matrix.build_type }}"
3654

3755
- name: Install and run mosquitto Linux
3856
if: matrix.os == 'ubuntu-latest'
@@ -41,4 +59,86 @@ jobs:
4159
4260
- name: Run project tests with CMake
4361
if: matrix.os == 'ubuntu-latest'
44-
run: ctest --test-dir build/output --output-on-failure -C Debug
62+
run: ctest --test-dir build/output --output-on-failure -C "${{ matrix.build_type }}"
63+
64+
install-build-and-test:
65+
strategy:
66+
fail-fast: false
67+
matrix:
68+
include:
69+
- os: ubuntu-latest
70+
generator: Ninja
71+
build_type: Debug
72+
- os: windows-latest
73+
generator: "Visual Studio 17 2022"
74+
build_type: Debug
75+
- os: ubuntu-latest
76+
generator: Ninja
77+
build_type: Release
78+
- os: windows-latest
79+
generator: "Visual Studio 17 2022"
80+
build_type: Release
81+
82+
runs-on: ${{ matrix.os }}
83+
env:
84+
INSTALL_PREFIX: ${{ github.workspace }}/opendaq_install
85+
86+
steps:
87+
- name: Install additional dependencies
88+
if: matrix.os == 'ubuntu-latest'
89+
run: |
90+
sudo apt-get install -y --no-install-recommends mono-runtime libmono-system-json-microsoft4.0-cil libmono-system-data4.0-cil
91+
92+
- name: Checkout module
93+
uses: actions/checkout@v4
94+
with:
95+
ref: ${{ github.event.inputs.branch || github.event.client_payload.branch || github.ref }}
96+
path: module
97+
98+
- name: Overwrite opendaq_ref
99+
if: ${{ github.event.inputs.opendaq_ref != '' }}
100+
working-directory: module
101+
run: echo "${{ github.event.inputs.opendaq_ref }}" > opendaq_ref
102+
103+
- name: Read openDAQ version
104+
shell: bash
105+
working-directory: module
106+
run: |
107+
opendaq_ref=$(cat opendaq_ref)
108+
echo "OPENDAQ_REF=$opendaq_ref" >> $GITHUB_ENV
109+
110+
- name: Checkout openDAQ
111+
uses: actions/checkout@v4
112+
with:
113+
repository: openDAQ/openDAQ
114+
ref: ${{ env.OPENDAQ_REF }}
115+
path: opendaq
116+
117+
- name: Configure, build and install openDAQ
118+
working-directory: opendaq
119+
run: |
120+
cmake -B build/output -S . -G "${{ matrix.generator }}" -DOPENDAQ_ENABLE_TESTS=OFF -DCMAKE_BUILD_TYPE="${{ matrix.build_type }}" -DCMAKE_INSTALL_PREFIX="${{ env.INSTALL_PREFIX }}"
121+
cmake --build build/output --config "${{ matrix.build_type }}"
122+
cmake --install build/output --config "${{ matrix.build_type }}"
123+
124+
- name: Add DLL path (Windows only)
125+
if: matrix.os == 'windows-latest'
126+
run: echo "${{ env.INSTALL_PREFIX }}/lib" >> $env:GITHUB_PATH
127+
128+
- name: Configure project with CMake
129+
working-directory: module
130+
run: cmake -B build/output -S . -G "${{ matrix.generator }}" -DDAQMODULES_MQTT_ENABLE_TESTS=ON -DDAQMODULES_MQTT_DEBUG_WARNINGS_AS_ERRORS=ON -DCMAKE_BUILD_TYPE="${{ matrix.build_type }}" -DopenDAQ_DIR="${{ env.INSTALL_PREFIX }}/lib/cmake/opendaq/"
131+
132+
- name: Build project with CMake
133+
working-directory: module
134+
run: cmake --build build/output --config "${{ matrix.build_type }}"
135+
136+
- name: Install and run mosquitto Linux
137+
if: matrix.os == 'ubuntu-latest'
138+
run: |
139+
sudo apt-get install -y --no-install-recommends mosquitto
140+
141+
- name: Run project tests with CMake
142+
if: matrix.os == 'ubuntu-latest'
143+
working-directory: module
144+
run: ctest --test-dir build/output --output-on-failure -C "${{ matrix.build_type }}"

CMakeLists.txt

Lines changed: 62 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,77 +1,95 @@
1-
# CMakeList.txt : CMake project for MQTTStreamingModule, include source and define
2-
# project specific logic here.
3-
#
4-
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
1+
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
52
cmake_minimum_required(VERSION 3.25)
63

7-
set(SDK_TARGET_NAMESPACE daq)
8-
set(REPO_NAME mqtt_module)
9-
set(REPO_OPTION_PREFIX MQTT_MODULE)
4+
set(REPO_NAME MqttModule)
5+
set(REPO_OPTION_PREFIX DAQMODULES_MQTT)
106
set(CMAKE_FOLDER "${CMAKE_FOLDER}/${REPO_NAME}")
117

12-
project (${REPO_NAME} CXX)
8+
list(APPEND CMAKE_MESSAGE_CONTEXT ${REPO_NAME})
9+
add_subdirectory(cmake)
1310

14-
# Enable Hot Reload for MSVC compilers if supported.
15-
if (POLICY CMP0141)
16-
cmake_policy(SET CMP0141 NEW)
17-
set(CMAKE_MSVC_DEBUG_INFORMATION_FORMAT "$<IF:$<AND:$<C_COMPILER_ID:MSVC>,$<CXX_COMPILER_ID:MSVC>>,$<$<CONFIG:Debug,RelWithDebInfo>:EditAndContinue>,$<$<CONFIG:Debug,RelWithDebInfo>:ProgramDatabase>>")
18-
endif()
11+
opendaq_read_file_contents("${CMAKE_CURRENT_LIST_DIR}/module_version" module_version)
12+
opendaq_get_version_major_minor_patch("${module_version}" ${REPO_OPTION_PREFIX}_VERSION)
1913

20-
if (POLICY CMP0135)
21-
cmake_policy(SET CMP0135 NEW)
14+
# the following section is required if module-project being built standalone with 32bit arch, it is "temporary" workaround, though - the correct one would be using `-DCMAKE_TOOLCHAIN_FILE`
15+
# 32-bit Linux cross-compilation setup (must be before any project())
16+
if (NOT DEFINED PROJECT_SOURCE_DIR AND OPENDAQ_FORCE_COMPILE_32BIT AND CMAKE_HOST_SYSTEM_NAME STREQUAL "Linux")
17+
opendaq_32bit_build_linux_early_setup()
2218
endif()
2319

24-
if (POLICY CMP0077)
25-
cmake_policy(SET CMP0077 NEW)
26-
endif()
20+
project(${REPO_NAME} VERSION ${${REPO_OPTION_PREFIX}_VERSION} LANGUAGES CXX)
2721

28-
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
29-
list(APPEND CMAKE_MESSAGE_CONTEXT ${REPO_NAME})
30-
set(CMAKE_MESSAGE_CONTEXT_SHOW ON CACHE BOOL "Show CMake message context")
22+
opendaq_common_early_setup()
3123

32-
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake")
24+
if (PROJECT_IS_TOP_LEVEL)
25+
message(STATUS "Building ${REPO_NAME} version ${${REPO_OPTION_PREFIX}_VERSION} standalone")
26+
else()
27+
message(STATUS "Building ${REPO_NAME} version ${${REPO_OPTION_PREFIX}_VERSION} as submodule")
28+
endif()
3329

34-
option(OPENDAQ_MQTT_MODULE_ENABLE_SSL "Enable building with openSSL" OFF)
35-
option(OPENDAQ_DEVICE_EXAMPLE_ENABLE_EXAMPLE_APPS "Enable building example applications" OFF)
30+
# options
31+
opendaq_setup_common_build_options()
32+
opendaq_setup_project_specific_build_options(${REPO_OPTION_PREFIX})
33+
option(${REPO_OPTION_PREFIX}_ENABLE_EXAMPLE_APP "Enable ${REPO_NAME} example applications" ${PROJECT_IS_TOP_LEVEL})
34+
option(${REPO_OPTION_PREFIX}_ENABLE_TESTS "Enable ${REPO_NAME} testing" ${PROJECT_IS_TOP_LEVEL})
35+
option(${REPO_OPTION_PREFIX}_ENABLE_SSL "Enable building with openSSL" OFF)
3636

37-
if ((CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) AND NOT MSVC)
38-
if (NOT WIN32)
39-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
40-
endif()
41-
add_compile_options(-Wno-deprecated-declarations)
42-
endif()
37+
opendaq_common_compile_targets_settings()
38+
opendaq_setup_compiler_flags(${REPO_OPTION_PREFIX})
4339

44-
include(CommonUtils)
45-
setup_repo(${REPO_OPTION_PREFIX})
40+
if (${REPO_OPTION_PREFIX}_ENABLE_TESTS)
41+
message(STATUS "Unit tests in ${REPO_NAME} are ENABLED")
42+
enable_testing()
43+
else()
44+
message(STATUS "Unit tests in ${REPO_NAME} are DISABLED")
45+
endif()
4646

47-
if(OPENDAQ_DEVICE_EXAMPLE_ENABLE_EXAMPLE_APPS)
47+
if(${REPO_OPTION_PREFIX}_ENABLE_EXAMPLE_APP)
4848
set(DAQMODULES_REF_DEVICE_MODULE ON CACHE BOOL "" FORCE)
4949
endif()
5050

51-
option(OPENDAQ_MQTT_ENABLE_TESTS "Enable module testing" OFF)
52-
option(OPENDAQ_MQTT_ENABLE_EXAMPLE_APPS "Enable example applications building" OFF)
53-
54-
if(OPENDAQ_MQTT_MODULE_ENABLE_SSL)
51+
if(${REPO_OPTION_PREFIX}_ENABLE_SSL)
5552
find_package(OpenSSL REQUIRED)
5653
if (OPENSSL_FOUND)
5754
message(STATUS "Found OpenSSL ${OPENSSL_VERSION}")
5855
else()
5956
message(FATAL_ERROR "OpenSSL Not Found")
6057
endif()
61-
add_compile_definitions(OPENDAQ_MQTT_MODULE_ENABLE_SSL)
58+
add_compile_definitions(${REPO_OPTION_PREFIX}_ENABLE_SSL)
6259
endif()
6360

64-
set(MQTT_MODULE_VERSION "0.1.0" CACHE STRING "MQTT module version" FORCE)
65-
66-
if(OPENDAQ_MQTT_ENABLE_TESTS)
67-
enable_testing()
61+
if (NOT TARGET "${OPENDAQ_SDK_TARGET_NAMESPACE}::${OPENDAQ_SDK_TARGET_NAME}")
62+
if (PROJECT_IS_TOP_LEVEL)
63+
find_package(${OPENDAQ_SDK_NAME} GLOBAL)
64+
endif()
65+
if (NOT ${OPENDAQ_SDK_NAME}_FOUND)
66+
include(FetchContent)
67+
set(OPENDAQ_ENABLE_TESTS OFF CACHE BOOL "")
68+
69+
opendaq_read_file_contents("${CMAKE_CURRENT_LIST_DIR}/opendaq_ref" OPENDAQ_REF)
70+
opendaq_get_custom_fetch_content_params(${OPENDAQ_SDK_NAME} FC_PARAMS)
71+
72+
FetchContent_Declare(
73+
${OPENDAQ_SDK_NAME}
74+
GIT_REPOSITORY https://github.com/openDAQ/openDAQ.git
75+
GIT_TAG ${OPENDAQ_REF}
76+
GIT_PROGRESS ON
77+
${FC_PARAMS}
78+
)
79+
FetchContent_MakeAvailable(${OPENDAQ_SDK_NAME})
80+
else()
81+
message(STATUS "Found installed ${OPENDAQ_SDK_NAME} version: ${${OPENDAQ_SDK_NAME}_VERSION}")
82+
set(OPENDAQ_PACKAGE_VERSION "${${OPENDAQ_SDK_NAME}_VERSION}" CACHE INTERNAL "${OPENDAQ_SDK_NAME} SDK version")
83+
endif()
6884
endif()
6985

7086
add_subdirectory(external)
7187
add_subdirectory(shared)
7288
add_subdirectory(modules)
7389

74-
if(OPENDAQ_DEVICE_EXAMPLE_ENABLE_EXAMPLE_APPS)
75-
message(STATUS "Example applications have been enabled")
90+
if(${REPO_OPTION_PREFIX}_ENABLE_EXAMPLE_APP)
91+
message(STATUS "Example applications in ${REPO_NAME} are ENABLED")
7692
add_subdirectory(examples)
93+
else()
94+
message(STATUS "Example applications in ${REPO_NAME} are DISABLED")
7795
endif()

CMakePresets.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -95,9 +95,8 @@
9595
"name": "full",
9696
"hidden": true,
9797
"cacheVariables": {
98-
"OPENDAQ_DEVICE_EXAMPLE_ENABLE_EXAMPLE_APPS": "true",
99-
"OPENDAQ_MQTT_ENABLE_TESTS": "true",
100-
"OPENDAQ_MQTT_ENABLE_EXAMPLE_APPS": "true"
98+
"DAQMODULES_MQTT_ENABLE_EXAMPLE_APP": "true",
99+
"DAQMODULES_MQTT_ENABLE_TESTS": "true"
101100
}
102101
},
103102
{

cmake/CMakeLists.txt

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
set(CMAKE_FOLDER "cmake")
2+
3+
list(APPEND CMAKE_MESSAGE_CONTEXT cmake)
4+
set(CURR_MESSAGE_CONTEXT ${CMAKE_MESSAGE_CONTEXT})
5+
6+
message(STATUS "Import functions and macro from opendaq-cmake-utils repo")
7+
include(FetchContent)
8+
FetchContent_Declare(
9+
opendaq-cmake-utils
10+
GIT_REPOSITORY https://github.com/openDAQ/opendaq-cmake-utils.git
11+
GIT_TAG v1.0.0
12+
GIT_PROGRESS ON
13+
)
14+
FetchContent_MakeAvailable(opendaq-cmake-utils)

0 commit comments

Comments
 (0)