Skip to content

Commit 68da71a

Browse files
authored
Addition of ssl lib for SSL/TLS. Ref #51 (#53)
1 parent 898ab72 commit 68da71a

File tree

5 files changed

+39
-8
lines changed

5 files changed

+39
-8
lines changed

CMakeLists.txt

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ project(mqttkdb C)
88

99
# Name of shared object
1010
set(MY_LIBRARY_NAME mqttkdb)
11+
set(MY_SSL_LIBRARY_NAME mqttkdb_ssl)
1112

1213
# Dispay settings
1314
message(STATUS "Generator : ${CMAKE_GENERATOR}")
@@ -31,12 +32,20 @@ add_library(${MY_LIBRARY_NAME} SHARED
3132
src/mqtt.c
3233
src/socketpair.c
3334
)
35+
add_library(${MY_SSL_LIBRARY_NAME} SHARED
36+
src/mqtt.c
37+
src/socketpair.c
38+
)
3439

3540
# Specify include directories
3641
target_include_directories (${MY_LIBRARY_NAME} PRIVATE
3742
${PROJECT_SOURCE_DIR}/include
3843
$ENV{MQTT_INSTALL_DIR}/include
3944
)
45+
target_include_directories (${MY_SSL_LIBRARY_NAME} PRIVATE
46+
${PROJECT_SOURCE_DIR}/include
47+
$ENV{MQTT_INSTALL_DIR}/include
48+
)
4049

4150
# Basic compile flag
4251
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -DKXVER=3")
@@ -50,6 +59,10 @@ find_library(MQTT3C_LIBRARY
5059
NAMES paho-mqtt3c
5160
HINTS "$ENV{MQTT_INSTALL_DIR}/lib/"
5261
)
62+
find_library(MQTT3CS_LIBRARY
63+
NAMES paho-mqtt3cs
64+
HINTS "$ENV{MQTT_INSTALL_DIR}/lib/"
65+
)
5366

5467
if (MSVC)
5568
# Get q dependency
@@ -72,14 +85,19 @@ if(APPLE)
7285
endif()
7386
set_target_properties(${MY_LIBRARY_NAME} PROPERTIES PREFIX "")
7487
set_target_properties(${MY_LIBRARY_NAME} PROPERTIES SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
88+
set_target_properties(${MY_SSL_LIBRARY_NAME} PROPERTIES PREFIX "")
89+
set_target_properties(${MY_SSL_LIBRARY_NAME} PROPERTIES SUFFIX ${CMAKE_SHARED_LIBRARY_SUFFIX})
90+
target_compile_definitions(${MY_SSL_LIBRARY_NAME} PRIVATE -DMQTT_SSL)
7591

7692
# Link flag
7793
IF(APPLE)
7894
set_target_properties(${MY_LIBRARY_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
95+
set_target_properties(${MY_SSL_LIBRARY_NAME} PROPERTIES LINK_FLAGS "-undefined dynamic_lookup")
7996
endif()
8097

8198
# Link dependent libraries
8299
target_link_libraries(${MY_LIBRARY_NAME} ${MQTT3C_LIBRARY} ${Q_LIBRARY})
100+
target_link_libraries(${MY_SSL_LIBRARY_NAME} ${MQTT3CS_LIBRARY} ${Q_LIBRARY})
83101

84102
##%% Installation %%##vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv#
85103

@@ -116,7 +134,15 @@ add_custom_command(TARGET ${MY_LIBRARY_NAME}
116134
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:${MY_LIBRARY_NAME}>" ${PROJECT_BINARY_DIR}/${CMAKE_PROJECT_NAME}/lib/${MY_LIBRARY_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
117135
DEPENDS ${MY_LIBRARY_NAME}
118136
)
137+
add_custom_command(TARGET ${MY_SSL_LIBRARY_NAME}
138+
POST_BUILD
139+
COMMAND ${CMAKE_COMMAND} -E copy "$<TARGET_FILE:${MY_SSL_LIBRARY_NAME}>" ${PROJECT_BINARY_DIR}/${CMAKE_PROJECT_NAME}/lib/${MY_SSL_LIBRARY_NAME}${CMAKE_SHARED_LIBRARY_SUFFIX}
140+
DEPENDS ${MY_SSL_LIBRARY_NAME}
141+
)
142+
143+
119144

120145
# Install at Release
121146
install(TARGETS ${MY_LIBRARY_NAME} DESTINATION "$ENV{QHOME}/${OSFLAG}${BITNESS}/" CONFIGURATIONS Release)
147+
install(TARGETS ${MY_SSL_LIBRARY_NAME} DESTINATION "$ENV{QHOME}/${OSFLAG}${BITNESS}/" CONFIGURATIONS Release)
122148
install(DIRECTORY "q/" DESTINATION "$ENV{QHOME}" CONFIGURATIONS Release)

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ MQTT is used commonly for constrained devices with low-bandwidth, high-latency o
4444
$ export DYLD_LIBRARY_PATH=/Users/jim/Eclipse-Paho-MQTT-C/lib/:$DYLD_LIBRARY_PATH
4545
4646
```
47-
- Windows: Add the `paho-mqtt3c.dll` to the kdb+ lib directory e.g. `C:\q\w64` for 64-bit.
47+
- Windows: Add the `paho-mqtt3c.dll` and `paho-mqtt3cs.dll` to the kdb+ lib directory e.g. `C:\q\w64` for 64-bit.
4848
3. Download the latest release of the mqtt interface from our [releases page](https://github.com/KxSystems/mqtt). To install shared library and q files, use:
4949

5050
# Linux/MacOS
@@ -65,7 +65,7 @@ MQTT is used commonly for constrained devices with low-bandwidth, high-latency o
6565
```bash
6666
6767
]$ mkdir paho_mqtt_c
68-
]$ tar xzf Eclipse-Paho-MQTT-C-1.3.8-Linux.tar.gz -C paho_mqtt_c/ --strip-components=1
68+
]$ tar xzf Eclipse-Paho-MQTT-C-1.3.11-Linux.tar.gz -C paho_mqtt_c/ --strip-components=1
6969
]$ cd paho_mqtt_c/
7070
paho_mqtt_c]$ export MQTT_INSTALL_DIR=$(pwd)
7171
@@ -102,11 +102,12 @@ MQTT is used commonly for constrained devices with low-bandwidth, high-latency o
102102
```bat
103103
104104
> mkdir paho_mqtt_c
105-
> 7z x eclipse-paho-mqtt-c-win64-1.3.8.zip -opaho_mqtt_c
105+
> 7z x eclipse-paho-mqtt-c-win64-1.3.11.zip -opaho_mqtt_c
106106
> cd paho_mqtt_c
107107
paho_mqtt_c> set MQTT_INSTALL_DIR=%cd%
108108
paho_mqtt_c> cd %QHOME%\w64
109109
w64> MKLINK paho-mqtt3c.dll %MQTT_INSTALL_DIR%\lib\paho-mqtt3c.dll
110+
w64> MKLINK paho-mqtt3cs.dll %MQTT_INSTALL_DIR%\lib\paho-mqtt3cs.dll
110111
111112
```
112113

docker_linux/Dockerfile.alpine

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ RUN apk add --update && \
4545
apk del make && \
4646
apk del wget && \
4747
apk del build-base && \
48-
rm -rf /source/mqtt_build.sh /source/paho.mqtt.c /source/v1.3.9* /source/mqtt/CmakeLists.txt
48+
rm -rf /source/mqtt_build.sh /source/paho.mqtt.c /source/v1.3.11* /source/mqtt/CmakeLists.txt
4949

5050
## Update this section here to add kdb+
5151
#COPY q/k4.lic /q/
@@ -57,4 +57,4 @@ RUN apk add --update && \
5757

5858
WORKDIR /source
5959

60-
ENTRYPOINT ["/bin/sh"]
60+
ENTRYPOINT ["/bin/sh"]

docker_linux/build_libpaho.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
cd /source
44

5-
wget https://github.com/eclipse/paho.mqtt.c/archive/refs/tags/v1.3.9.tar.gz
6-
tar xvf v1.3.9.tar.gz -C ./paho.mqtt.c --strip-components=1
5+
wget https://github.com/eclipse/paho.mqtt.c/archive/refs/tags/v1.3.11.tar.gz
6+
tar xvf v1.3.11.tar.gz -C ./paho.mqtt.c --strip-components=1
77

88
cd paho.mqtt.c
99

@@ -25,4 +25,4 @@ mkdir /source/mqtt/cmake
2525
cd /source/mqtt/cmake
2626
cmake ..
2727
make
28-
make install
28+
make install

src/mqtt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
#include <winsock2.h>
33
#include <windows.h>
44
#pragma comment(lib,"ws2_32.lib")
5+
#ifdef MQTT_SSL
6+
#pragma comment(lib,"paho-mqtt3cs.lib")
7+
#else
58
#pragma comment(lib,"paho-mqtt3c.lib")
9+
#endif
610
#pragma comment(lib,"q.lib")
711
#define EXP __declspec(dllexport)
812
static SOCKET spair[2];

0 commit comments

Comments
 (0)