forked from wolfSSL/wolfMQTT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
CMakeLists.txt
168 lines (142 loc) · 4.55 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
# CMakeList.txt
#
# Copyright (C) 2006-2022 wolfSSL Inc.
#
# This file is part of wolfSSL. (formerly known as CyaSSL)
#
# Usage:
# $ mkdir build
# $ cd build
# $ cmake ..
# $ cmake --build .
#
# To build with debugging use:
# $ cmake .. -DCMAKE_BUILD_TYPE=Debug
#
# See "CMake" in README.md for more.
####################################################
# Project
####################################################
cmake_minimum_required(VERSION 3.16)
project(wolfMQTT VERSION 1.14.0 LANGUAGES C)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
set(MQTT_SOURCES
src/mqtt_client.c
src/mqtt_packet.c
src/mqtt_socket.c
)
# default to build shared library
option(BUILD_SHARED_LIBS "Build shared libraries (.dll/.so) instead of static ones (.lib/.a)" ON)
add_library(wolfmqtt ${MQTT_SOURCES})
if (WITH_WOLFSSL)
target_link_libraries(wolfmqtt PUBLIC wolfssl)
target_include_directories(wolfmqtt PUBLIC ${WITH_WOLFSSL}/include)
target_link_directories(wolfmqtt PUBLIC ${WITH_WOLFSSL}/lib)
target_compile_definitions(wolfmqtt PUBLIC
"ENABLE_MQTT_TLS"
)
elseif (WITH_WOLFSSL_TREE)
set(WOLFSSL_EXAMPLES "no" CACHE STRING "")
set(WOLFSSL_CRYPT_TESTS "no" CACHE STRING "")
add_subdirectory(${WITH_WOLFSSL_TREE} wolfssl)
target_link_libraries(wolfmqtt PUBLIC wolfssl)
target_compile_definitions(wolfmqtt PUBLIC
"ENABLE_MQTT_TLS"
)
else()
find_package(PkgConfig)
pkg_check_modules(WOLFSSL wolfssl)
if (WOLFSSL_FOUND)
target_compile_definitions(wolfmqtt PUBLIC
"ENABLE_MQTT_TLS"
)
target_link_libraries(wolfmqtt PUBLIC ${WOLFSSL_LIBRARIES})
target_include_directories(wolfmqtt PUBLIC ${WOLFSSL_INCLUDE_DIRS})
target_link_directories(wolfmqtt PUBLIC ${WOLFSSL_LIBRARY_DIRS})
target_compile_options(wolfmqtt PUBLIC ${WOLFSSL_CFLAGS_OTHER})
else()
# For support with vcpkg
find_package(wolfssl CONFIG)
if (wolfssl_FOUND)
target_compile_definitions(wolfmqtt PUBLIC
"ENABLE_MQTT_TLS"
)
target_link_libraries(wolfmqtt PUBLIC wolfssl)
endif()
endif()
endif()
# TODO: add options
# * tls
# * sn
# * nonblock
# * timeout
# * errorstrings
# * stdincap
# * v5
# * discb
# * mt
set(WOLFMQTT_EXAMPLES "yes" CACHE BOOL
"Build examples")
target_compile_definitions(wolfmqtt PRIVATE
"BUILDING_WOLFMQTT"
)
#TODO generate options file
configure_file(wolfmqtt/options.h.in wolfmqtt/options.h)
if(WIN32)
target_compile_definitions(wolfmqtt PRIVATE
"_WINDLL"
)
endif(WIN32)
target_include_directories(wolfmqtt
PUBLIC
$<INSTALL_INTERFACE:include>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
)
if (WOLFMQTT_EXAMPLES)
add_library(mqtt_test_lib STATIC
examples/mqttexample.c
examples/mqttnet.c
)
target_link_libraries(mqtt_test_lib wolfmqtt)
function(add_mqtt_example name src)
add_executable(${name}
examples/${src}
)
target_link_libraries(${name} wolfmqtt mqtt_test_lib)
endfunction()
add_mqtt_example(mqttclient mqttclient/mqttclient.c)
add_mqtt_example(mqttsimple mqttsimple/mqttsimple.c)
add_mqtt_example(nbclient nbclient/nbclient.c)
#add_mqtt_example(mqttuart mqttuart.c)
add_mqtt_example(multithread multithread/multithread.c)
add_mqtt_example(sn-client sn-client/sn-client.c)
add_mqtt_example(sn-client_qos-1 sn-client/sn-client_qos-1.c)
add_mqtt_example(sn-multithread sn-client/sn-multithread.c)
add_mqtt_example(awsiot aws/awsiot.c)
add_mqtt_example(wiot wiot/wiot.c)
add_mqtt_example(azureiothub azure/azureiothub.c)
add_mqtt_example(fwpush firmware/fwpush.c)
add_mqtt_example(fwclient firmware/fwclient.c)
endif()
####################################################
# Installation
####################################################
include(GNUInstallDirs)
install(TARGETS wolfmqtt
EXPORT wolfmqtt-targets
LIBRARY DESTINATION lib
ARCHIVE DESTINATION lib
RUNTIME DESTINATION bin
)
# Install the export set
install(EXPORT wolfmqtt-targets
DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/wolfmqtt
FILE wolfmqtt-config.cmake)
# Install the headers
install(DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/wolfmqtt/
DESTINATION include/wolfmqtt
FILES_MATCHING PATTERN "*.h")
install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/wolfmqtt/
DESTINATION include/wolfmqtt
FILES_MATCHING PATTERN "*.h")