From 02cf646d849f953ee1b7f91504e4f3bb31fd2d59 Mon Sep 17 00:00:00 2001 From: fpagliughi Date: Mon, 20 Nov 2023 19:30:04 -0500 Subject: [PATCH] Added Windows DLL export nonsense to make class static constants visible to apps --- src/CMakeLists.txt | 22 +++--- src/client.cpp | 11 +-- src/connect_options.cpp | 14 ++-- src/message.cpp | 6 +- src/mqtt/CMakeLists.txt | 4 +- src/mqtt/client.h | 4 +- src/mqtt/connect_options.h | 11 +-- src/mqtt/export.h | 45 ++++++++++++ src/mqtt/message.h | 7 +- src/mqtt/platform.h | 30 ++++++++ src/mqtt/properties.h | 5 +- src/mqtt/ssl_options.h | 3 +- src/mqtt/subscribe_options.h | 9 +-- src/mqtt/will_options.h | 7 +- src/properties.cpp | 3 +- src/samples/CMakeLists.txt | 128 +++++++++++++++-------------------- src/ssl_options.cpp | 5 +- src/subscribe_options.cpp | 8 +-- src/will_options.cpp | 6 +- test/unit/CMakeLists.txt | 8 +++ 20 files changed, 213 insertions(+), 123 deletions(-) create mode 100644 src/mqtt/export.h create mode 100644 src/mqtt/platform.h diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c0d6670..e2b934a 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -7,7 +7,7 @@ #******************************************************************************* # Copyright (c) 2016-2017, Guilherme Maciel Ferreira -# Copyright (c) 2017-2018, Frank Pagliughi +# Copyright (c) 2017-2023, Frank Pagliughi # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v2.0 @@ -40,6 +40,9 @@ endif() add_subdirectory(mqtt) +include(GenerateExportHeader) +#generate_export_header(mylibrary) + ## --- Library dependencies --- set (THREADS_PREFER_PTHREAD_FLAG ON) @@ -75,14 +78,16 @@ add_library(paho-cpp-objs OBJECT #target_include_directories(OBJS PRIVATE ${PAHO_MQTT_C_INCLUDE_DIRS}) target_include_directories(paho-cpp-objs - PUBLIC - $ - $ - PRIVATE - ${PAHO_MQTT_C_INCLUDE_DIRS} - src + PUBLIC + $ + $ + PRIVATE + ${PAHO_MQTT_C_INCLUDE_DIRS} + src ) +target_compile_definitions(paho-cpp-objs PRIVATE PAHO_MQTTPP_EXPORTS) + # --- Warnings --- # Maybe set '-Werror' for Release builds? @@ -103,7 +108,7 @@ if(PAHO_BUILD_SHARED) PRIVATE ${LIBS_SYSTEM} PUBLIC PahoMqttC::PahoMqttC Threads::Threads) - # It would be nice to exort the include paths from the obj lib, but we + # It would be nice to export the include paths from the obj lib, but we # get an export error. Perhaps in a future version? # # CMake Error: install(EXPORT "PahoMqttCpp" ...) includes target "paho-mqttpp3" @@ -143,6 +148,7 @@ if(PAHO_BUILD_STATIC) target_include_directories(paho-mqttpp3-static PUBLIC $ + $ $ ) diff --git a/src/client.cpp b/src/client.cpp index 55505b3..36435d2 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -23,12 +23,15 @@ namespace mqtt { -const std::chrono::seconds client::DFLT_TIMEOUT = std::chrono::seconds(30); - -const int client::DFLT_QOS = 1; - ///////////////////////////////////////////////////////////////////////////// +PAHO_MQTTPP_EXPORT const std::chrono::seconds client::DFLT_TIMEOUT + = std::chrono::seconds(30); + +PAHO_MQTTPP_EXPORT const int client::DFLT_QOS = 1; + +// -------------------------------------------------------------------------- + client::client(const string& serverURI, const string& clientId, iclient_persistence* persistence /*=nullptr*/) : cli_(serverURI, clientId, persistence), diff --git a/src/connect_options.cpp b/src/connect_options.cpp index ea27bcc..69f649f 100644 --- a/src/connect_options.cpp +++ b/src/connect_options.cpp @@ -25,18 +25,20 @@ namespace mqtt { ///////////////////////////////////////////////////////////////////////////// -const MQTTAsync_connectOptions connect_options::DFLT_C_STRUCT = +PAHO_MQTTPP_EXPORT const MQTTAsync_connectOptions connect_options::DFLT_C_STRUCT = MQTTAsync_connectOptions_initializer; -const MQTTAsync_connectOptions connect_options::DFLT_C_STRUCT5 = +PAHO_MQTTPP_EXPORT const MQTTAsync_connectOptions connect_options::DFLT_C_STRUCT5 = MQTTAsync_connectOptions_initializer5; -const MQTTAsync_connectOptions connect_options::DFLT_C_STRUCT_WS = +PAHO_MQTTPP_EXPORT const MQTTAsync_connectOptions connect_options::DFLT_C_STRUCT_WS = MQTTAsync_connectOptions_initializer_ws; -const MQTTAsync_connectOptions connect_options::DFLT_C_STRUCT5_WS = +PAHO_MQTTPP_EXPORT const MQTTAsync_connectOptions connect_options::DFLT_C_STRUCT5_WS = MQTTAsync_connectOptions_initializer5_ws; +// -------------------------------------------------------------------------- + connect_options::connect_options(int ver /*=MQTTVERSION_DEFAULT*/) { opts_ = (ver < MQTTVERSION_5) ? DFLT_C_STRUCT : DFLT_C_STRUCT5; @@ -368,8 +370,8 @@ void connect_options::set_https_proxy(const string& httpsProxy) ///////////////////////////////////////////////////////////////////////////// // connect_data -const MQTTAsync_connectData connect_data::DFLT_C_STRUCT = - MQTTAsync_connectData_initializer; +PAHO_MQTTPP_EXPORT const MQTTAsync_connectData connect_data::DFLT_C_STRUCT + = MQTTAsync_connectData_initializer; connect_data::connect_data() : data_(DFLT_C_STRUCT) { diff --git a/src/message.cpp b/src/message.cpp index 9d7366f..b20424b 100644 --- a/src/message.cpp +++ b/src/message.cpp @@ -25,10 +25,10 @@ namespace mqtt { ///////////////////////////////////////////////////////////////////////////// -const int message::DFLT_QOS = 0; -const bool message::DFLT_RETAINED = false; +PAHO_MQTTPP_EXPORT const int message::DFLT_QOS = 0; +PAHO_MQTTPP_EXPORT const bool message::DFLT_RETAINED = false; -const MQTTAsync_message message::DFLT_C_STRUCT = MQTTAsync_message_initializer; +PAHO_MQTTPP_EXPORT const MQTTAsync_message message::DFLT_C_STRUCT = MQTTAsync_message_initializer; // -------------------------------------------------------------------------- diff --git a/src/mqtt/CMakeLists.txt b/src/mqtt/CMakeLists.txt index c59b01f..db38d92 100644 --- a/src/mqtt/CMakeLists.txt +++ b/src/mqtt/CMakeLists.txt @@ -1,5 +1,5 @@ #******************************************************************************* -# Copyright (c) 2016-2018 +# Copyright (c) 2016-2023 # # All rights reserved. This program and the accompanying materials # are made available under the terms of the Eclipse Public License v2.0 @@ -27,10 +27,12 @@ install( delivery_token.h disconnect_options.h exception.h + export.h iaction_listener.h iasync_client.h iclient_persistence.h message.h + platform.h properties.h response_options.h server_response.h diff --git a/src/mqtt/client.h b/src/mqtt/client.h index 3019b13..ae386cd 100644 --- a/src/mqtt/client.h +++ b/src/mqtt/client.h @@ -38,9 +38,9 @@ namespace mqtt { class client : private callback { /** An arbitrary, but relatively long timeout */ - static const std::chrono::seconds DFLT_TIMEOUT; + PAHO_MQTTPP_EXPORT static const std::chrono::seconds DFLT_TIMEOUT; /** The default quality of service */ - static const int DFLT_QOS; // =1; + PAHO_MQTTPP_EXPORT static const int DFLT_QOS; // =1; /** The actual client */ async_client cli_; diff --git a/src/mqtt/connect_options.h b/src/mqtt/connect_options.h index 2e5588e..a2cd53e 100644 --- a/src/mqtt/connect_options.h +++ b/src/mqtt/connect_options.h @@ -32,6 +32,7 @@ #include "mqtt/string_collection.h" #include "mqtt/will_options.h" #include "mqtt/ssl_options.h" +#include "mqtt/platform.h" #include #include #include @@ -47,16 +48,16 @@ namespace mqtt { class connect_options { /** The default C struct for non-WebSocket connections */ - static const MQTTAsync_connectOptions DFLT_C_STRUCT; + PAHO_MQTTPP_EXPORT static const MQTTAsync_connectOptions DFLT_C_STRUCT; /** The default C struct for non-Websocket MQTT v5 connections */ - static const MQTTAsync_connectOptions DFLT_C_STRUCT5; + PAHO_MQTTPP_EXPORT static const MQTTAsync_connectOptions DFLT_C_STRUCT5; /** The default C struct for WebSocket connections */ - static const MQTTAsync_connectOptions DFLT_C_STRUCT_WS; + PAHO_MQTTPP_EXPORT static const MQTTAsync_connectOptions DFLT_C_STRUCT_WS; /** The default C struct for Websocket MQTT v5 connections */ - static const MQTTAsync_connectOptions DFLT_C_STRUCT5_WS; + PAHO_MQTTPP_EXPORT static const MQTTAsync_connectOptions DFLT_C_STRUCT5_WS; /** The underlying C connection options */ MQTTAsync_connectOptions opts_; @@ -585,7 +586,7 @@ using connect_options_ptr = connect_options::ptr_t; class connect_data { /** The default C struct */ - static const MQTTAsync_connectData DFLT_C_STRUCT; + PAHO_MQTTPP_EXPORT static const MQTTAsync_connectData DFLT_C_STRUCT; /** The underlying C connect data */ MQTTAsync_connectData data_; diff --git a/src/mqtt/export.h b/src/mqtt/export.h new file mode 100644 index 0000000..6a38db1 --- /dev/null +++ b/src/mqtt/export.h @@ -0,0 +1,45 @@ +///////////////////////////////////////////////////////////////////////////// +/// @file export.h +/// Library symbol export definitions, primarily for Windows MSVC DLL's +/// @date November 20, 2023 +/// @author Frank Pagliughi +///////////////////////////////////////////////////////////////////////////// + +/******************************************************************************* + * Copyright (c) 2023 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v20.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + * Frank Pagliughi - MQTT v5 support + *******************************************************************************/ + +#ifndef __mqtt_export_h +#define __mqtt_export_h + +#if defined(_WIN32) && defined(_MSC_VER) + #if defined(PAHO_MQTTPP_EXPORTS) + #define PAHO_MQTTPP_EXPORT __declspec(dllexport) + #elif defined(PAHO_MQTTPP_IMPORTS) + #define PAHO_MQTTPP_EXPORT __declspec(dllimport) + #else + #define PAHO_MQTTPP_EXPORT + #endif +#else + #if defined(PAHO_MQTTPP_EXPORTS) + #define PAHO_MQTTPP_EXPORT __attribute__ ((visibility ("default"))) + #else + #define PAHO_MQTTPP_EXPORT + #endif +#endif + +#endif // __mqtt_export_h + diff --git a/src/mqtt/message.h b/src/mqtt/message.h index 0024976..15b8d6a 100644 --- a/src/mqtt/message.h +++ b/src/mqtt/message.h @@ -29,6 +29,7 @@ #include "mqtt/buffer_ref.h" #include "mqtt/properties.h" #include "mqtt/exception.h" +#include "mqtt/platform.h" #include namespace mqtt { @@ -55,13 +56,13 @@ class message { public: /** The default QoS for a message */ - static const int DFLT_QOS; // =0 + PAHO_MQTTPP_EXPORT static const int DFLT_QOS; // =0 /** The default retained flag */ - static const bool DFLT_RETAINED; // =false + PAHO_MQTTPP_EXPORT static const bool DFLT_RETAINED; // =false private: /** Initializer for the C struct (from the C library) */ - static const MQTTAsync_message DFLT_C_STRUCT; + PAHO_MQTTPP_EXPORT static const MQTTAsync_message DFLT_C_STRUCT; /** The underlying C message struct */ MQTTAsync_message msg_; diff --git a/src/mqtt/platform.h b/src/mqtt/platform.h new file mode 100644 index 0000000..180611f --- /dev/null +++ b/src/mqtt/platform.h @@ -0,0 +1,30 @@ +///////////////////////////////////////////////////////////////////////////// +/// @file platform.h +/// Paho MQTT platform-specific code +/// @date Nov 19, 2023 +/// @author Frank Pagliughi +///////////////////////////////////////////////////////////////////////////// + +/******************************************************************************* + * Copyright (c) 2023 Frank Pagliughi + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v2.0 + * and Eclipse Distribution License v1.0 which accompany this distribution. + * + * The Eclipse Public License is available at + * http://www.eclipse.org/legal/epl-v20.html + * and the Eclipse Distribution License is available at + * http://www.eclipse.org/org/documents/edl-v10.php. + * + * Contributors: + * Frank Pagliughi - initial implementation and documentation + *******************************************************************************/ + +#ifndef __mqtt_platform_h +#define __mqtt_platform_h + +#include "mqtt/export.h" + +#endif // __mqtt_platform_h + diff --git a/src/mqtt/properties.h b/src/mqtt/properties.h index 3010416..0a073d8 100644 --- a/src/mqtt/properties.h +++ b/src/mqtt/properties.h @@ -6,7 +6,7 @@ ///////////////////////////////////////////////////////////////////////////// /******************************************************************************* - * Copyright (c) 2019 Frank Pagliughi + * Copyright (c) 2019-2023 Frank Pagliughi * * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v2.0 @@ -31,6 +31,7 @@ extern "C" { #include "mqtt/types.h" #include "mqtt/buffer_ref.h" #include "mqtt/exception.h" +#include "mqtt/platform.h" #include #include @@ -254,7 +255,7 @@ inline string_pair get(const property& prop) { class properties { /** The default C struct */ - static const MQTTProperties DFLT_C_STRUCT; + PAHO_MQTTPP_EXPORT static const MQTTProperties DFLT_C_STRUCT; /** The underlying C properties struct */ MQTTProperties props_; diff --git a/src/mqtt/ssl_options.h b/src/mqtt/ssl_options.h index 18ca03a..09bb97c 100644 --- a/src/mqtt/ssl_options.h +++ b/src/mqtt/ssl_options.h @@ -31,6 +31,7 @@ #include "mqtt/message.h" #include "mqtt/topic.h" #include "mqtt/types.h" +#include "mqtt/platform.h" #include #include @@ -64,7 +65,7 @@ public: private: /** The default C struct */ - static const MQTTAsync_SSLOptions DFLT_C_STRUCT ; + PAHO_MQTTPP_EXPORT static const MQTTAsync_SSLOptions DFLT_C_STRUCT ; /** The underlying C SSL options */ MQTTAsync_SSLOptions opts_; diff --git a/src/mqtt/subscribe_options.h b/src/mqtt/subscribe_options.h index 9432b71..3145db5 100644 --- a/src/mqtt/subscribe_options.h +++ b/src/mqtt/subscribe_options.h @@ -27,6 +27,7 @@ #include "MQTTAsync.h" #include "MQTTSubscribeOpts.h" #include "mqtt/types.h" +#include "mqtt/platform.h" namespace mqtt { @@ -53,17 +54,17 @@ public: using const_ptr_t = std::shared_ptr; /** Don't receive our own publications */ - static const bool SUBSCRIBE_NO_LOCAL; // =true; + PAHO_MQTTPP_EXPORT static const bool SUBSCRIBE_NO_LOCAL; // =true; /** Receive our own publications */ - static const bool SUBSCRIBE_LOCAL; // =false; + PAHO_MQTTPP_EXPORT static const bool SUBSCRIBE_LOCAL; // =false; /** * Retain flag is only set on publications sent by a broker if in * response to a subscribe request */ - static const bool NO_RETAIN_AS_PUBLISHED; // =false; + PAHO_MQTTPP_EXPORT static const bool NO_RETAIN_AS_PUBLISHED; // =false; /** Keep the retain flag as on the original publish message */ - static const bool RETAIN_AS_PUBLISHED; // =true; + PAHO_MQTTPP_EXPORT static const bool RETAIN_AS_PUBLISHED; // =true; /** The options for subscription retain handling */ enum RetainHandling { diff --git a/src/mqtt/will_options.h b/src/mqtt/will_options.h index fd22243..dbc3611 100644 --- a/src/mqtt/will_options.h +++ b/src/mqtt/will_options.h @@ -30,6 +30,7 @@ #include "mqtt/types.h" #include "mqtt/message.h" #include "mqtt/topic.h" +#include "mqtt/platform.h" namespace mqtt { @@ -49,13 +50,13 @@ class will_options { public: /** The default QoS for the LWT, if unspecified */ - static const int DFLT_QOS; // =0; + PAHO_MQTTPP_EXPORT static const int DFLT_QOS; // =0; /** The defalut retained flag for LWT, if unspecified */ - static const bool DFLT_RETAINED; // =false; + PAHO_MQTTPP_EXPORT static const bool DFLT_RETAINED; // =false; private: /** A default C struct to support re-initializing variables */ - static const MQTTAsync_willOptions DFLT_C_STRUCT; + PAHO_MQTTPP_EXPORT static const MQTTAsync_willOptions DFLT_C_STRUCT; /** The underlying C LWT options */ MQTTAsync_willOptions opts_; diff --git a/src/properties.cpp b/src/properties.cpp index 33ee811..f22d0cb 100644 --- a/src/properties.cpp +++ b/src/properties.cpp @@ -154,7 +154,8 @@ property& property::operator=(property&& rhs) ///////////////////////////////////////////////////////////////////////////// -const MQTTProperties properties::DFLT_C_STRUCT = MQTTProperties_initializer; +PAHO_MQTTPP_EXPORT const MQTTProperties properties::DFLT_C_STRUCT + = MQTTProperties_initializer; properties::properties() : props_{DFLT_C_STRUCT} { diff --git a/src/samples/CMakeLists.txt b/src/samples/CMakeLists.txt index 700dd96..3ca0a75 100644 --- a/src/samples/CMakeLists.txt +++ b/src/samples/CMakeLists.txt @@ -31,82 +31,66 @@ find_package(Threads REQUIRED) ## include directories #include_directories(${CMAKE_CURRENT_SOURCE_DIR}) -## binary files -add_executable(async_publish async_publish.cpp) -add_executable(async_publish_time async_publish_time.cpp) -add_executable(async_subscribe async_subscribe.cpp) -add_executable(async_consume async_consume.cpp) -add_executable(async_consume_v5 async_consume_v5.cpp) -add_executable(sync_publish sync_publish.cpp) -add_executable(sync_consume sync_consume.cpp) -add_executable(sync_consume_v5 sync_consume_v5.cpp) -add_executable(sync_reconnect sync_reconnect.cpp) -add_executable(data_publish data_publish.cpp) -add_executable(topic_publish topic_publish.cpp) -add_executable(rpc_math_cli rpc_math_cli.cpp) -add_executable(rpc_math_srvr rpc_math_srvr.cpp) -add_executable(mqttpp_chat mqttpp_chat.cpp) -add_executable(multithr_pub_sub multithr_pub_sub.cpp) -add_executable(ws_publish ws_publish.cpp) -add_executable(pub_speed_test pub_speed_test.cpp) - -## link binaries -target_link_libraries(async_publish ${PAHO_CPP_LIB}) -target_link_libraries(async_publish_time ${PAHO_CPP_LIB}) -target_link_libraries(async_subscribe ${PAHO_CPP_LIB}) -target_link_libraries(async_consume ${PAHO_CPP_LIB}) -target_link_libraries(async_consume_v5 ${PAHO_CPP_LIB}) -target_link_libraries(sync_publish ${PAHO_CPP_LIB}) -target_link_libraries(sync_consume ${PAHO_CPP_LIB}) -target_link_libraries(sync_consume_v5 ${PAHO_CPP_LIB}) -target_link_libraries(sync_reconnect ${PAHO_CPP_LIB}) -target_link_libraries(data_publish ${PAHO_CPP_LIB}) -target_link_libraries(topic_publish ${PAHO_CPP_LIB}) -target_link_libraries(rpc_math_cli ${PAHO_CPP_LIB}) -target_link_libraries(rpc_math_srvr ${PAHO_CPP_LIB}) -target_link_libraries(mqttpp_chat ${PAHO_CPP_LIB}) -target_link_libraries(multithr_pub_sub ${PAHO_CPP_LIB}) -target_link_libraries(ws_publish ${PAHO_CPP_LIB}) -target_link_libraries(pub_speed_test ${PAHO_CPP_LIB}) - -set(INSTALL_TARGETS - async_publish - async_publish_time - async_subscribe - async_consume - async_consume_v5 - sync_publish - sync_consume - sync_consume_v5 - sync_reconnect - data_publish - rpc_math_cli - rpc_math_srvr - mqttpp_chat - topic_publish - multithr_pub_sub - ws_publish - pub_speed_test +# The sample applications +set(EXECUTABLES + async_publish + async_publish_time + async_subscribe + async_consume + async_consume_v5 + sync_publish + sync_consume + sync_consume_v5 + sync_reconnect + data_publish + rpc_math_cli + rpc_math_srvr + mqttpp_chat + topic_publish + multithr_pub_sub + ws_publish + pub_speed_test ) -if(PAHO_WITH_SSL) - ## SSL binary files - add_executable(ssl_publish ssl_publish.cpp) +# These will only be built if SSL selected +set(SSL_EXECUTABLES + ssl_publish +) - ## link SSL binaries - target_link_libraries(ssl_publish ${PAHO_CPP_LIB}) - - set(INSTALL_TARGETS - ${INSTALL_TARGETS} - ssl_publish - ) - - add_definitions(-DOPENSSL) -endif() +## Build the samples +foreach(EXECUTABLE ${EXECUTABLES}) + add_executable(${EXECUTABLE} ${EXECUTABLE}.cpp) + target_link_libraries(${EXECUTABLE} ${PAHO_CPP_LIB}) + if(PAHO_BUILD_SHARED) + target_compile_definitions(${EXECUTABLE} PUBLIC PAHO_MQTTPP_IMPORTS) + if(MSVC AND PAHO_BUILD_STATIC) + target_link_libraries(${EXECUTABLE} ${LIBS_SYSTEM}) + endif() + endif() +endforeach() ## install binaries -install(TARGETS ${INSTALL_TARGETS} EXPORT PahoMqttCppSamples - RUNTIME DESTINATION bin - LIBRARY DESTINATION lib +install(TARGETS ${EXECUTABLES} EXPORT PahoMqttCppSamples + RUNTIME DESTINATION bin ) +## Build the SSL/TLS samples, if selected +if(PAHO_WITH_SSL) + foreach(EXECUTABLE ${SSL_EXECUTABLES}) + add_executable(${EXECUTABLE} ${EXECUTABLE}.cpp) + target_link_libraries(${EXECUTABLE} ${PAHO_CPP_LIB}) + if(PAHO_BUILD_SHARED) + target_compile_definitions(${EXECUTABLE} PUBLIC PAHO_MQTTPP_IMPORTS) + if(MSVC AND PAHO_BUILD_STATIC) + target_link_libraries(${EXECUTABLE} ${LIBS_SYSTEM}) + endif() + endif() + target_compile_definitions(${EXECUTABLE} PUBLIC OPENSSL) + endforeach() + + install(TARGETS ${SSL_EXECUTABLES} EXPORT PahoMqttCppSamples + RUNTIME DESTINATION bin + ) +endif() + + diff --git a/src/ssl_options.cpp b/src/ssl_options.cpp index 4ac0acd..845e0f2 100644 --- a/src/ssl_options.cpp +++ b/src/ssl_options.cpp @@ -24,7 +24,10 @@ namespace mqtt { ///////////////////////////////////////////////////////////////////////////// -const MQTTAsync_SSLOptions ssl_options::DFLT_C_STRUCT = MQTTAsync_SSLOptions_initializer; +PAHO_MQTTPP_EXPORT const MQTTAsync_SSLOptions ssl_options::DFLT_C_STRUCT + = MQTTAsync_SSLOptions_initializer; + +// -------------------------------------------------------------------------- ssl_options::ssl_options() : opts_(DFLT_C_STRUCT) { diff --git a/src/subscribe_options.cpp b/src/subscribe_options.cpp index 00f44fa..73679f3 100644 --- a/src/subscribe_options.cpp +++ b/src/subscribe_options.cpp @@ -22,11 +22,11 @@ namespace mqtt { ///////////////////////////////////////////////////////////////////////////// -const bool subscribe_options::SUBSCRIBE_NO_LOCAL = true; -const bool subscribe_options::SUBSCRIBE_LOCAL = false; +PAHO_MQTTPP_EXPORT const bool subscribe_options::SUBSCRIBE_NO_LOCAL = true; +PAHO_MQTTPP_EXPORT const bool subscribe_options::SUBSCRIBE_LOCAL = false; -const bool subscribe_options::NO_RETAIN_AS_PUBLISHED = false; -const bool subscribe_options::RETAIN_AS_PUBLISHED = true; +PAHO_MQTTPP_EXPORT const bool subscribe_options::NO_RETAIN_AS_PUBLISHED = false; +PAHO_MQTTPP_EXPORT const bool subscribe_options::RETAIN_AS_PUBLISHED = true; ///////////////////////////////////////////////////////////////////////////// // end namespace 'mqtt' diff --git a/src/will_options.cpp b/src/will_options.cpp index ea3dde5..8d7dbe0 100644 --- a/src/will_options.cpp +++ b/src/will_options.cpp @@ -22,10 +22,10 @@ namespace mqtt { -const int will_options::DFLT_QOS = 0; -const bool will_options::DFLT_RETAINED = false; +PAHO_MQTTPP_EXPORT const int will_options::DFLT_QOS = 0; +PAHO_MQTTPP_EXPORT const bool will_options::DFLT_RETAINED = false; -const MQTTAsync_willOptions will_options::DFLT_C_STRUCT = MQTTAsync_willOptions_initializer; +PAHO_MQTTPP_EXPORT const MQTTAsync_willOptions will_options::DFLT_C_STRUCT = MQTTAsync_willOptions_initializer; ///////////////////////////////////////////////////////////////////////////// diff --git a/test/unit/CMakeLists.txt b/test/unit/CMakeLists.txt index 0ddcbe2..1b5020a 100644 --- a/test/unit/CMakeLists.txt +++ b/test/unit/CMakeLists.txt @@ -67,6 +67,14 @@ message(STATUS "Using library for unit tests: ${PAHO_CPP_LIB}") target_link_libraries(unit_tests ${PAHO_CPP_LIB} Catch2::Catch2) +if(PAHO_BUILD_SHARED) + target_compile_definitions(unit_tests PUBLIC PAHO_MQTTPP_IMPORTS) + + if(MSVC AND PAHO_BUILD_STATIC) + target_link_libraries(unit_tests ${LIBS_SYSTEM}) + endif() +endif() + include(CTest) include(Catch)