-
Notifications
You must be signed in to change notification settings - Fork 107
/
CMakeLists.txt
185 lines (159 loc) · 6.53 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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
CMAKE_MINIMUM_REQUIRED (VERSION 3.13.0)
PROJECT (mqtt_cpp_iface VERSION 13.2.1)
SET(CMAKE_CXX_STANDARD 14)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
# Don't use GNU extensions
SET(CMAKE_CXX_EXTENSIONS OFF)
MESSAGE (STATUS "Setting minimum C++ standard to C++14")
OPTION(MQTT_BUILD_EXAMPLES "Enable building example applications" ON)
OPTION(MQTT_BUILD_TESTS "Enable building test applications" ON)
OPTION(MQTT_ALWAYS_SEND_REASON_CODE "Always send a reason code, even if the standard says it may be optionally omitted." ON)
OPTION(MQTT_USE_STATIC_BOOST "Statically link with boost libraries" OFF)
OPTION(MQTT_USE_STATIC_OPENSSL "Statically link with openssl libraries" OFF)
OPTION(MQTT_USE_TLS "Enable building TLS code" OFF)
OPTION(MQTT_USE_WS "Enable building WebSockets code" OFF)
OPTION(MQTT_USE_STR_CHECK "Enable UTF8 String check" ON)
OPTION(MQTT_USE_LOG "Enable building logging code" OFF)
OPTION(MQTT_STD_VARIANT "Use std::variant from C++17 instead of boost::variant" OFF)
OPTION(MQTT_STD_OPTIONAL "Use std::optional from C++17 instead of boost::optional" OFF)
OPTION(MQTT_STD_STRING_VIEW "Use std::string_view from C++17 instead of boost::string_view" OFF)
OPTION(MQTT_STD_ANY "Use std::any from C++17 instead of boost::any" OFF)
OPTION(MQTT_STD_SHARED_PTR_ARRAY "Use std::shared_ptr<char[]> from C++17 instead of boost::shared_ptr<char[]>" OFF)
OPTION(MQTT_DISABLE_LIBSTDCXX_TUPLE_ANY_WORKAROUND "std::tuple<std::any> workaround for libstdc++" OFF)
IF (POLICY CMP0074)
CMAKE_POLICY(SET CMP0074 NEW)
ENDIF ()
IF (MQTT_USE_TLS)
MESSAGE (STATUS "TLS enabled")
ELSE ()
MESSAGE (STATUS "TLS disabled")
ENDIF ()
IF (MQTT_USE_WS)
MESSAGE (STATUS "WebSocket enabled")
ELSE ()
MESSAGE (STATUS "WebSocket disabled")
ENDIF ()
IF (MQTT_ALWAYS_SEND_REASON_CODE)
MESSAGE (STATUS "Always send reason code enabled")
ELSE ()
MESSAGE (STATUS "Always send reason code disabled")
ENDIF ()
IF (MQTT_USE_STR_CHECK)
MESSAGE (STATUS "UTF8String check enabled")
ELSE ()
MESSAGE (STATUS "UTF8String check disabled")
ENDIF ()
IF (MQTT_STD_VARIANT)
MESSAGE (STATUS "Using std::variant instead of boost::variant. Enables C++17!!!")
ELSE ()
MESSAGE (STATUS "Using boost::variant instead of std::variant")
ENDIF ()
IF (MQTT_STD_OPTIONAL)
MESSAGE (STATUS "Using std::optional instead of boost::optional. Enables C++17!!!")
ELSE ()
MESSAGE (STATUS "Using boost::optional instead of std::optional")
ENDIF ()
IF (MQTT_STD_STRING_VIEW)
MESSAGE (STATUS "Using std::string_view instead of boost::string_view. Enables C++17!!!")
ELSE ()
MESSAGE (STATUS "Using boost::string_view instead of std::string_view")
ENDIF ()
IF (MQTT_STD_ANY)
MESSAGE (STATUS "Using std::any instead of boost::any. Enables C++17!!!")
ELSE ()
MESSAGE (STATUS "Using boost::any instead of std::any")
ENDIF ()
IF (MQTT_STD_SHARED_PTR_ARRAY)
MESSAGE (STATUS "Using std::shared_ptr<char []> instead of boost::shared_ptr<char []>. Enables C++17!!!")
ELSE ()
MESSAGE (STATUS "Using boost::shared_ptr<char []> instead of std::shared_ptr<char []>")
ENDIF ()
IF (MQTT_DISABLE_LIBSTDCXX_TUPLE_ANY_WORKAROUND)
MESSAGE (STATUS "std::tuple<std::any> workaround for libstdc++ disabled")
ELSE ()
MESSAGE (STATUS "std::tuple<std::any> workaround for libstdc++ enabled")
ENDIF ()
IF ( MQTT_STD_VARIANT
OR MQTT_STD_OPTIONAL
OR MQTT_STD_ANY
OR MQTT_STD_STRING_VIEW
OR MQTT_STD_SHARED_PTR_ARRAY)
SET(CMAKE_CXX_STANDARD 17)
SET(CMAKE_CXX_STANDARD_REQUIRED ON)
MESSAGE (STATUS "Setting minimum C++ standard to C++17!!!")
ENDIF ()
IF ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
SET (CMAKE_CXX_FLAGS "/bigobj ${CMAKE_CXX_FLAGS}")
ENDIF ()
IF (MQTT_USE_STATIC_BOOST)
MESSAGE (STATUS "Staticly linking with Boost")
SET (Boost_USE_STATIC_LIBS TRUE)
ELSE ()
MESSAGE (STATUS "Dynamically linking with Boost")
SET (Boost_USE_STATIC_LIBS FALSE)
ENDIF ()
IF (MQTT_USE_STATIC_OPENSSL)
MESSAGE (STATUS "Staticly linking with Openssl")
SET (OPENSSL_USE_STATIC_LIBS TRUE)
ELSE ()
MESSAGE (STATUS "Dynamically linking with Openssl")
SET (OPENSSL_USE_STATIC_LIBS FALSE)
ENDIF ()
SET (Boost_USE_MULTITHREADED ON)
FIND_PACKAGE (Threads REQUIRED)
SET (MQTT_BOOST_COMPONENTS)
IF (MQTT_USE_LOG)
MESSAGE (STATUS "Logging enabled")
SET (MQTT_BOOST_COMPONENTS log filesystem thread program_options)
ELSE ()
MESSAGE (STATUS "Logging disabled")
SET (MQTT_BOOST_COMPONENTS program_options)
ENDIF ()
FIND_PACKAGE (Boost 1.74.0 REQUIRED COMPONENTS ${MQTT_BOOST_COMPONENTS})
IF (MQTT_NO_TS_EXECUTORS AND ((Boost_MAJOR_VERSION LESS 1) OR (Boost_MINOR_VERSION LESS 74)))
MESSAGE(FATAL_ERROR "Boost version 1.74.0 or later is required for use with standard executors")
ENDIF ()
IF (MQTT_USE_TLS)
FIND_PACKAGE (OpenSSL REQUIRED)
SET (MQTT_DEPENDS_OPENSSL "FIND_DEPENDENCY (OpenSSL)")
IF (MQTT_USE_STATIC_OPENSSL)
FIND_PACKAGE (ZLIB REQUIRED)
SET (MQTT_DEPENDS_ZLIB "FIND_DEPENDENCY (ZLIB)")
ENDIF ()
ENDIF ()
ADD_SUBDIRECTORY (include)
IF (MQTT_BUILD_TESTS)
MESSAGE(STATUS "Tests enabled")
ENABLE_TESTING ()
ADD_SUBDIRECTORY (test)
ENDIF ()
IF (MQTT_BUILD_EXAMPLES)
MESSAGE(STATUS "Examples enabled")
ADD_SUBDIRECTORY (example)
ENDIF ()
# Doxygen
FIND_PACKAGE (Doxygen)
IF (DOXYGEN_FOUND)
LIST (APPEND Doxyfile_CONTENT
COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_SOURCE_DIR}/Doxyfile ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
COMMAND ${CMAKE_COMMAND} -E echo "FILE_PATTERNS = *.hpp" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
COMMAND ${CMAKE_COMMAND} -E echo "OUTPUT_DIRECTORY = doc" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
COMMAND ${CMAKE_COMMAND} -E echo "PROJECT_NAME = \"mqtt_cpp\"" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
COMMAND ${CMAKE_COMMAND} -E echo "EXTRACT_ALL = YES" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
COMMAND ${CMAKE_COMMAND} -E echo "RECURSIVE = YES" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
COMMAND ${CMAKE_COMMAND} -E echo "PREDEFINED = _DOXYGEN_" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
COMMAND ${CMAKE_COMMAND} -E echo "INPUT = ${CMAKE_CURRENT_SOURCE_DIR}/include" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
)
IF (DOXYGEN_DOT_FOUND)
LIST (APPEND Doxyfile_CONTENT
COMMAND ${CMAKE_COMMAND} -E echo "HAVE_DOT = YES" >> ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
)
ENDIF ()
ADD_CUSTOM_TARGET (
doxygen
${Doxyfile_CONTENT}
COMMAND ${DOXYGEN_EXECUTABLE} ${CMAKE_CURRENT_BINARY_DIR}/Doxyfile
VERBATIM
)
ENDIF ()
include(cmake/createcmakeconfig.cmake)