-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
273 lines (233 loc) · 8.99 KB
/
CMakeLists.txt
File metadata and controls
273 lines (233 loc) · 8.99 KB
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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
# This is a cmake script. Process it with the CMake gui or command line utility
# to produce makefiles / Visual Studio project files on Mac OS X and Windows.
#
# To configure the build options either use the CMake gui, or run the command
# line utility including the "-i" option.
cmake_minimum_required(VERSION 3.18)
set (VERSION 2.0.99)
project(mosquitto
VERSION ${VERSION}
DESCRIPTION "Eclipse Mosquitto"
LANGUAGES C CXX
)
set(CMAKE_C_STANDARD 99)
set(CMAKE_C_STANDARD_REQUIRED ON)
list(APPEND CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/cmake/")
add_definitions (-DCMAKE -DVERSION=\"${VERSION}\")
if(WIN32)
add_definitions("-D_CRT_SECURE_NO_WARNINGS")
add_definitions("-D_CRT_NONSTDC_NO_DEPRECATE")
endif()
if(APPLE)
set(CMAKE_MODULE_LINKER_FLAGS "${CMAKE_MODULE_LINKER_FLAGS} -undefined dynamic_lookup")
endif()
add_library(common-options INTERFACE)
if(NOT WIN32)
target_compile_options(common-options INTERFACE -Wall -Wextra -Wconversion)
endif()
include(CMakePushCheckState)
include(CheckIncludeFiles)
include(CheckLibraryExists)
include(CheckSourceCompiles)
include(GNUInstallDirs)
option(WITH_BUNDLED_DEPS "Build with bundled dependencies?" ON)
option(WITH_TLS "Include SSL/TLS support?" ON)
option(WITH_TLS_PSK "Include TLS-PSK support (requires WITH_TLS)?" ON)
option(WITH_TESTS "Enable tests" ON)
if(WITH_TESTS)
find_package(GTest REQUIRED)
include(GoogleTest)
enable_testing()
function(test_set_windows_path TEST_NAME)
if(WIN32)
set(PATHMOD
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libmosquitto_common>"
"PATH=path_list_prepend:$<TARGET_FILE_DIR:libmosquitto>"
"PATH=path_list_prepend:${VCPKG_INSTALLED_DIR}/${VCPKG_TARGET_TRIPLET}/bin"
)
set_property(TEST ${TEST_NAME} PROPERTY ENVIRONMENT_MODIFICATION "${PATHMOD}")
endif()
endfunction()
function(add_python_tests_from_current_directory2 PREFIX PY_TEST_FILES EXCLUDE_LIST)
foreach(PY_TEST_FILE ${PY_TEST_FILES})
get_filename_component(PY_TEST_NAME ${PY_TEST_FILE} NAME_WE)
if(${PY_TEST_NAME} IN_LIST EXCLUDE_LIST)
continue()
endif()
add_test(NAME ${PREFIX}-${PY_TEST_NAME} COMMAND python3 ${PY_TEST_FILE})
set_tests_properties(${PREFIX}-${PY_TEST_NAME}
PROPERTIES
ENVIRONMENT "BUILD_ROOT=${CMAKE_BINARY_DIR}"
)
test_set_windows_path(${PREFIX}-${PY_TEST_NAME})
endforeach()
endfunction()
function(add_python_tests_from_current_directory PREFIX EXCLUDE_LIST)
file(GLOB PY_TEST_FILES [0-9][0-9]-*.py)
add_python_tests_from_current_directory2("${PREFIX}" "${PY_TEST_FILES}" "${EXCLUDE_LIST}")
endfunction()
endif()
option(INC_MEMTRACK "Include memory tracking support?" ON)
if (WITH_TLS)
find_package(OpenSSL REQUIRED)
add_definitions("-DWITH_TLS")
# mosquitto uses OpenSSL 1.1 API, so set OPENSSL_API_COMPAT accordingly:
# https://www.openssl.org/docs/manmaster/man7/OPENSSL_API_COMPAT.html
# TODO: migrate off ENGINE API (deprecated since OpenSSL 3.0), see:
# https://www.openssl.org/docs/manmaster/man7/migration_guide.html#Engines-and-METHOD-APIs
add_definitions("-DOPENSSL_API_COMPAT=0x10100000L")
if (WITH_TLS_PSK)
add_definitions("-DWITH_TLS_PSK")
endif (WITH_TLS_PSK)
else()
set (OPENSSL_INCLUDE_DIR "")
endif()
option(WITH_UNIX_SOCKETS "Include Unix Domain Socket support?" ON)
if(WITH_UNIX_SOCKETS AND NOT WIN32)
add_definitions("-DWITH_UNIX_SOCKETS")
endif()
option(WITH_SOCKS "Include SOCKS5 support?" ON)
if(WITH_SOCKS)
add_definitions("-DWITH_SOCKS")
endif()
option(WITH_WEBSOCKETS "Include websockets support?" ON)
option(WITH_WEBSOCKETS_BUILTIN "Websockets support uses builtin library? Set OFF to use libwebsockets" ON)
option(WITH_SRV "Include SRV lookup support?" OFF)
option(WITH_STATIC_LIBRARIES "Build static versions of the libmosquitto/pp libraries?" OFF)
option(WITH_PIC "Build the static library with PIC (Position Independent Code) enabled archives?" OFF)
option(WITH_THREADING "Include threading support?" ON)
if(WITH_THREADING)
add_definitions("-DWITH_THREADING")
if(WIN32)
find_package(PThreads4W REQUIRED)
endif()
endif()
option(WITH_DLT "Include DLT support?" OFF)
message(STATUS "WITH_DLT = ${WITH_DLT}")
if(WITH_DLT)
find_package(PkgConfig)
pkg_check_modules(DLT "automotive-dlt >= 2.11" REQUIRED)
endif()
find_package(cJSON REQUIRED)
find_package(argon2)
find_package(edit)
if(ARGON2_FOUND)
# Disable until separate password handling thread is implemented
#add_definitions("-DWITH_ARGON2")
endif()
option(WITH_LTO "Build with link time optimizations (IPO) / interprocedural optimization (IPO) enabled." ON)
if(WITH_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT is_ipo_supported OUTPUT output)
if(is_ipo_supported)
set_property(TARGET common-options PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
else()
message(WARNING "LTO/IPO is not supported: ${output}")
endif()
endif()
# ========================================
# Include projects
# ========================================
option(WITH_CLIENTS "Build clients?" ON)
option(WITH_BROKER "Build broker?" ON)
option(WITH_APPS "Build apps?" ON)
option(WITH_PLUGINS "Build plugins?" ON)
option(DOCUMENTATION "Build documentation?" ON)
add_library(config-header INTERFACE)
target_sources(config-header INTERFACE config.h)
target_include_directories(config-header
INTERFACE
${mosquitto_SOURCE_DIR}
)
if(WITH_TLS)
target_include_directories(config-header
INTERFACE
"${OPENSSL_INCLUDE_DIR}"
)
endif()
add_subdirectory(libcommon)
add_subdirectory(lib)
if(WITH_CLIENTS)
add_subdirectory(client)
endif()
if(WITH_BROKER)
add_subdirectory(src)
endif()
if(WITH_APPS)
add_subdirectory(apps)
endif()
if(WITH_PLUGINS)
add_subdirectory(plugins)
endif()
if(DOCUMENTATION)
add_subdirectory(man)
endif()
# ========================================
# Install config file
# ========================================
if(WITH_BROKER)
install(FILES mosquitto.conf RENAME mosquitto.conf.example DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/mosquitto")
install(FILES aclfile.example pskfile.example pwfile.example DESTINATION "${CMAKE_INSTALL_SYSCONFDIR}/mosquitto")
endif()
# ========================================
# Install pkg-config files
# ========================================
configure_file(libmosquitto.pc.in libmosquitto.pc @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmosquitto.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
configure_file(libmosquittopp.pc.in libmosquittopp.pc @ONLY)
install(FILES "${CMAKE_CURRENT_BINARY_DIR}/libmosquittopp.pc" DESTINATION "${CMAKE_INSTALL_LIBDIR}/pkgconfig")
# ========================================
# Install headers
# ========================================
install(
FILES
${mosquitto_SOURCE_DIR}/include/mosquitto.h
${mosquitto_SOURCE_DIR}/include/mosquitto_broker.h
${mosquitto_SOURCE_DIR}/include/mosquitto_plugin.h
${mosquitto_SOURCE_DIR}/include/mosquittopp.h
${mosquitto_SOURCE_DIR}/include/mqtt_protocol.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}"
)
install(
FILES
${mosquitto_SOURCE_DIR}/include/mosquitto/broker.h
${mosquitto_SOURCE_DIR}/include/mosquitto/broker_control.h
${mosquitto_SOURCE_DIR}/include/mosquitto/broker_plugin.h
${mosquitto_SOURCE_DIR}/include/mosquitto/defs.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libcommon.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libcommon_base64.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libcommon_cjson.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libcommon_file.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libcommon_memory.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libcommon_password.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libcommon_properties.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libcommon_random.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libcommon_string.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libcommon_time.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libcommon_topic.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libcommon_utf8.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto_auth.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto_callbacks.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto_connect.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto_create_delete.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto_helpers.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto_loop.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto_message.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto_options.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto_publish.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto_socks.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto_subscribe.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto_tls.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto_unsubscribe.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquitto_will.h
${mosquitto_SOURCE_DIR}/include/mosquitto/libmosquittopp.h
${mosquitto_SOURCE_DIR}/include/mosquitto/mqtt_protocol.h
DESTINATION "${CMAKE_INSTALL_INCLUDEDIR}/mosquitto"
)
# ========================================
# Testing
# ========================================
if(WITH_TESTS)
add_subdirectory(test)
endif()