Skip to content

Commit 810dc2a

Browse files
committed
mqtt: fixes for msvc-22/gcc/clang building
1 parent cbc7079 commit 810dc2a

23 files changed

Lines changed: 139 additions & 94 deletions

CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@ if (POLICY CMP0077)
2525
cmake_policy(SET CMP0077 NEW)
2626
endif()
2727

28-
2928
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
3029
list(APPEND CMAKE_MESSAGE_CONTEXT ${REPO_NAME})
3130
set(CMAKE_MESSAGE_CONTEXT_SHOW ON CACHE BOOL "Show CMake message context")
@@ -39,6 +38,7 @@ if ((CMAKE_COMPILER_IS_GNUCXX OR CMAKE_COMPILER_IS_CLANGXX) AND NOT MSVC)
3938
if (NOT WIN32)
4039
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -pthread")
4140
endif()
41+
add_compile_options(-Wno-deprecated-declarations)
4242
endif()
4343

4444
include(CommonUtils)

external/mqtt/CMakeLists.txt

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,28 +22,37 @@ endif()
2222
set(PAHO_BUILD_STATIC ON CACHE BOOL "Build static paho library" FORCE)
2323
set(PAHO_BUILD_SHARED OFF CACHE BOOL "Build dynamic paho library" FORCE)
2424
set(CMAKE_POSITION_INDEPENDENT_CODE ${PAHO_BUILD_STATIC} CACHE BOOL "" FORCE)
25-
set(PAHO_ENABLE_TESTING ON CACHE BOOL "" FORCE)
25+
set(PAHO_ENABLE_TESTING OFF CACHE BOOL "" FORCE)
2626

2727
set(CMAKE_FOLDER "${CMAKE_FOLDER}/mqtt")
2828

29+
set(CMAKE_C_STANDARD 99)
30+
set(CMAKE_C_STANDARD_REQUIRED ON)
31+
2932
add_subdirectory(${paho_mqtt_c_SOURCE_DIR} ${paho_mqtt_c_BINARY_DIR})
3033

3134
# Apply WIN32_LEAN_AND_MEAN to the Paho MQTT C library as well
3235
if(WIN32)
3336
# Add global compile definition to prevent inclusion of winsock.h and force winsock2.h
34-
if(PAHO_WITH_SSL)
35-
target_compile_definitions(paho-mqtt3as PRIVATE _WINSOCKAPI_)
36-
target_compile_definitions(paho-mqtt3as PRIVATE NOMINMAX)
37-
target_compile_definitions(paho-mqtt3as PRIVATE WIN32_LEAN_AND_MEAN)
38-
target_compile_definitions(common_ssl_obj PRIVATE _WINSOCKAPI_)
39-
target_compile_definitions(common_ssl_obj PRIVATE NOMINMAX)
40-
target_compile_definitions(common_ssl_obj PRIVATE WIN32_LEAN_AND_MEAN)
41-
else()
42-
target_compile_definitions(paho-mqtt3a PRIVATE _WINSOCKAPI_)
43-
target_compile_definitions(paho-mqtt3a PRIVATE NOMINMAX)
44-
target_compile_definitions(paho-mqtt3a PRIVATE WIN32_LEAN_AND_MEAN)
45-
target_compile_definitions(common_obj PRIVATE _WINSOCKAPI_)
46-
target_compile_definitions(common_obj PRIVATE NOMINMAX)
47-
target_compile_definitions(common_obj PRIVATE WIN32_LEAN_AND_MEAN)
48-
endif()
49-
endif()
37+
foreach(tgt
38+
paho-mqtt3a
39+
paho-mqtt3a-static
40+
paho-mqtt3c
41+
paho-mqtt3c-static
42+
paho-mqtt3as
43+
paho-mqtt3as-static
44+
common_obj
45+
common_ssl_obj
46+
common_obj_static
47+
common_ssl_obj_static
48+
)
49+
if(TARGET ${tgt})
50+
target_compile_definitions("${tgt}" PRIVATE _WINSOCKAPI_ NOMINMAX WIN32_LEAN_AND_MEAN)
51+
if(MSVC)
52+
target_compile_options(${tgt} PRIVATE /WX-)
53+
endif()
54+
endif()
55+
endforeach()
56+
target_compile_options(Base64Test PRIVATE /WX-)
57+
target_compile_options(Sha1Test PRIVATE /WX-)
58+
endif()

mqtt_streaming_module/CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,12 @@ set(MQTT_MODULE_PRJ_NAME "OpenDaqMqttModule")
77
message(STATUS "${MQTT_MODULE_PRJ_NAME} version: ${MQTT_MODULE_VERSION}")
88
project(${MQTT_MODULE_PRJ_NAME} VERSION ${MQTT_MODULE_VERSION} LANGUAGES C CXX)
99

10+
if(MSVC)
11+
add_compile_options(
12+
$<$<CONFIG:Release>:/wd4201>
13+
)
14+
endif()
15+
1016
add_subdirectory(src)
1117
if (OPENDAQ_MQTT_ENABLE_TESTS)
1218
add_subdirectory(tests)

mqtt_streaming_module/include/mqtt_streaming_module/common.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,3 +19,13 @@
1919

2020
#define BEGIN_NAMESPACE_OPENDAQ_MQTT_STREAMING_MODULE BEGIN_NAMESPACE_OPENDAQ_MODULE(mqtt_streaming_module)
2121
#define END_NAMESPACE_OPENDAQ_MQTT_STREAMING_MODULE END_NAMESPACE_OPENDAQ_MODULE
22+
23+
#if defined(_WIN32)
24+
#ifdef OPENDAQ_MODULE_DLL_IMPORT
25+
#define DAQ_MQTT_STREAM_MODULE_API __declspec(dllexport)
26+
#else
27+
#define DAQ_MQTT_STREAM_MODULE_API __declspec(dllimport)
28+
#endif
29+
#else
30+
#define DAQ_MQTT_STREAM_MODULE_API
31+
#endif

mqtt_streaming_module/include/mqtt_streaming_module/mqtt_base_fb.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ class MqttBaseFb : public FunctionBlock
5050
};
5151

5252

53-
explicit MqttBaseFb(const ContextPtr& ctx,
53+
explicit DAQ_MQTT_STREAM_MODULE_API MqttBaseFb(const ContextPtr& ctx,
5454
const ComponentPtr& parent,
5555
const FunctionBlockTypePtr& type,
5656
const StringPtr& localId,
5757
std::shared_ptr<mqtt::MqttAsyncClient> subscriber,
5858
const PropertyObjectPtr& config = nullptr);
59-
~MqttBaseFb() = default;
59+
virtual ~MqttBaseFb() = default;
6060

6161
virtual std::string getSubscribedTopic() const = 0;
6262

@@ -72,7 +72,7 @@ class MqttBaseFb : public FunctionBlock
7272
void initProperties(const PropertyObjectPtr& config);
7373
virtual void readProperties() = 0;
7474

75-
void onSignalsMessage(const mqtt::MqttAsyncClient& subscriber, const mqtt::MqttMessage& msg);
75+
DAQ_MQTT_STREAM_MODULE_API void onSignalsMessage(const mqtt::MqttAsyncClient& subscriber, const mqtt::MqttMessage& msg);
7676

7777
virtual void clearSubscribedTopic() = 0;
7878
CmdResult subscribeToTopic();

mqtt_streaming_module/include/mqtt_streaming_module/mqtt_json_receiver_fb_impl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,16 @@ class MqttJsonReceiverFbImpl final : public MqttBaseFb
2929
friend class MqttJsonDecoderFbHelper;
3030

3131
public:
32-
explicit MqttJsonReceiverFbImpl(const ContextPtr& ctx,
32+
explicit DAQ_MQTT_STREAM_MODULE_API MqttJsonReceiverFbImpl(const ContextPtr& ctx,
3333
const ComponentPtr& parent,
3434
const FunctionBlockTypePtr& type,
3535
std::shared_ptr<mqtt::MqttAsyncClient> subscriber,
3636
const PropertyObjectPtr& config = nullptr);
37-
~MqttJsonReceiverFbImpl() override;
37+
DAQ_MQTT_STREAM_MODULE_API ~MqttJsonReceiverFbImpl() override;
3838

39-
static FunctionBlockTypePtr CreateType();
39+
DAQ_MQTT_STREAM_MODULE_API static FunctionBlockTypePtr CreateType();
4040

41-
std::string getSubscribedTopic() const override;
41+
DAQ_MQTT_STREAM_MODULE_API std::string getSubscribedTopic() const override;
4242

4343
protected:
4444
mqtt::MqttDataWrapper jsonDataWorker;

mqtt_streaming_module/include/mqtt_streaming_module/mqtt_publisher_fb_impl.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,22 @@ class MqttPublisherFbImpl final : public FunctionBlock
5555
const PropertyObjectPtr& config = nullptr);
5656
~MqttPublisherFbImpl();
5757

58-
static FunctionBlockTypePtr CreateType();
59-
PublisherFbConfig getFbConfig() const;
58+
DAQ_MQTT_STREAM_MODULE_API static FunctionBlockTypePtr CreateType();
59+
DAQ_MQTT_STREAM_MODULE_API PublisherFbConfig getFbConfig() const;
6060

6161
void onConnected(const InputPortPtr& port) override;
6262
void onDisconnected(const InputPortPtr& port) override;
6363

64-
static const std::vector<std::pair<SignalStatus, std::string>> signalStatusMap;
65-
static const std::vector<std::pair<PublishingStatus, std::string>> publishingStatusMap;
66-
static const std::vector<std::pair<SettingStatus, std::string>> settingStatusMap;
64+
inline static const std::vector<std::pair<SignalStatus, std::string>> signalStatusMap =
65+
{{SignalStatus::NotConnected, "NotConnected"},
66+
{SignalStatus::Invalid, "Invalid"},
67+
{SignalStatus::Valid, "Valid"}};
68+
inline static const std::vector<std::pair<PublishingStatus, std::string>> publishingStatusMap =
69+
{{PublishingStatus::Ok, "Ok"},
70+
{PublishingStatus::SampleSkipped, "SampleSkipped"}};
71+
inline static const std::vector<std::pair<SettingStatus, std::string>> settingStatusMap =
72+
{{SettingStatus::Valid, "Valid"},
73+
{SettingStatus::Invalid, "Invalid"}};
6774

6875
private:
6976
static std::atomic<int> localIndex;

mqtt_streaming_module/include/mqtt_streaming_module/mqtt_raw_receiver_fb_impl.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ class MqttRawReceiverFbImpl final : public MqttBaseFb
2727
friend class MqttRawFbTest;
2828

2929
public:
30-
explicit MqttRawReceiverFbImpl(const ContextPtr& ctx,
30+
explicit DAQ_MQTT_STREAM_MODULE_API MqttRawReceiverFbImpl(const ContextPtr& ctx,
3131
const ComponentPtr& parent,
3232
const FunctionBlockTypePtr& type,
3333
std::shared_ptr<mqtt::MqttAsyncClient> subscriber,
3434
const PropertyObjectPtr& config = nullptr);
35-
~MqttRawReceiverFbImpl() override;
35+
DAQ_MQTT_STREAM_MODULE_API ~MqttRawReceiverFbImpl() override;
3636

3737
static FunctionBlockTypePtr CreateType();
3838

mqtt_streaming_module/src/CMakeLists.txt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,10 @@ if (MSVC)
9090
target_compile_options(${LIB_NAME} PRIVATE /bigobj)
9191
endif()
9292

93+
if (WIN32)
94+
target_compile_definitions(${LIB_NAME} PRIVATE OPENDAQ_MODULE_DLL_IMPORT)
95+
endif()
96+
9397
target_link_libraries(${LIB_NAME} PUBLIC daq::opendaq
9498
mqtt_streaming_protocol
9599
mqtt_streaming_helper

mqtt_streaming_module/src/mqtt_json_decoder_fb_impl.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include "mqtt_streaming_module/constants.h"
22
#include <mqtt_streaming_module/helper.h>
33
#include <mqtt_streaming_module/mqtt_json_decoder_fb_impl.h>
4+
#include <chrono>
45

56
BEGIN_NAMESPACE_OPENDAQ_MQTT_STREAMING_MODULE
67

0 commit comments

Comments
 (0)