forked from socketio/socket.io-client-cpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCMakeLists.txt
More file actions
241 lines (200 loc) · 7.88 KB
/
CMakeLists.txt
File metadata and controls
241 lines (200 loc) · 7.88 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
cmake_minimum_required(VERSION 3.12...3.27)
PROJECT(sioclient
VERSION 3.2.0
)
# Export compile commands for IDEs (VSCode, CLion, etc.)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
option(BUILD_SHARED_LIBS "Build the shared library" OFF)
option(BUILD_UNIT_TESTS "Builds unit tests target" OFF)
option(USE_SUBMODULES "Use source in local submodules instead of system libraries" ON)
option(DISABLE_LOGGING "Do not print logging messages" OFF)
option(ENABLE_LTO "Enable link-time optimization in Release" ON)
option(ENABLE_SANITIZERS "Enable Address/UB sanitizers in Debug" OFF)
if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
set(DEFAULT_BUILD_TYPE "Release")
message(STATUS "Setting build type to '${DEFAULT_BUILD_TYPE}' as none was specified.")
set(CMAKE_BUILD_TYPE "${DEFAULT_BUILD_TYPE}" CACHE STRING "Choose the type of build." FORCE)
# Set the possible values of build type for cmake-gui
set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Release" "MinSizeRel" "RelWithDebInfo")
endif()
# Only do these if this is the main project, and not if it is included through add_subdirectory
if(CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME)
# Testing only available if this is the main app
# Note this needs to be done in the main CMakeLists
# since it calls enable_testing, which must be in the
# main CMakeLists.
include(CTest)
endif()
add_definitions(
# These will force ASIO to compile without Boost
-DBOOST_DATE_TIME_NO_LIB
-DBOOST_REGEX_NO_LIB
-DASIO_STANDALONE
# These will force sioclient to compile with C++20
-D_WEBSOCKETPP_CPP11_STL_
-D_WEBSOCKETPP_CPP11_FUNCTIONAL_
-D_WEBSOCKETPP_CPP11_TYPE_TRAITS_
-D_WEBSOCKETPP_CPP11_CHRONO_
)
# Suppress deprecation warnings from third-party libraries
# These are external dependencies we can't control
if(CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
add_compile_options(
-Wno-deprecated-declarations # Suppress OpenSSL 3.0 and std::iterator deprecations
)
endif()
if (DISABLE_LOGGING)
add_definitions(-DSIO_DISABLE_LOGGING)
endif()
set(ALL_SRC
"src/sio_client.cpp"
"src/sio_socket.cpp"
"src/internal/sio_client_impl.cpp"
"src/internal/sio_packet.cpp"
)
if(USE_SUBMODULES)
set(MODULE_INCLUDE_DIRS
${CMAKE_CURRENT_LIST_DIR}/lib/websocketpp
${CMAKE_CURRENT_LIST_DIR}/lib/simdjson/include
${CMAKE_CURRENT_LIST_DIR}/lib/asio/asio/include
)
else()
find_package(websocketpp CONFIG REQUIRED)
find_package(asio CONFIG REQUIRED)
find_package(simdjson CONFIG REQUIRED)
endif()
include(GNUInstallDirs)
# Build HTTP-only library (sioclient)
add_library(sioclient ${ALL_SRC})
target_include_directories(sioclient PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE
${MODULE_INCLUDE_DIRS}
)
target_compile_features(sioclient PUBLIC cxx_std_20)
find_package(Threads REQUIRED)
target_link_libraries(sioclient PUBLIC Threads::Threads)
if (NOT USE_SUBMODULES)
target_link_libraries(sioclient PRIVATE websocketpp::websocketpp asio asio::asio simdjson::simdjson)
endif()
# Add simdjson source file when using submodules
if(USE_SUBMODULES)
target_sources(sioclient PRIVATE ${CMAKE_CURRENT_LIST_DIR}/lib/simdjson/singleheader/simdjson.cpp)
endif()
# Apply build-type optimizations to HTTP library
if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(ENABLE_LTO)
include(CheckIPOSupported)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_err)
if(ipo_supported)
set_property(TARGET sioclient PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
message(STATUS "LTO enabled for sioclient")
else()
message(WARNING "LTO not supported: ${ipo_err}")
endif()
endif()
elseif(ENABLE_SANITIZERS AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(sioclient PRIVATE -fsanitize=address,undefined -fno-omit-frame-pointer)
target_link_options(sioclient PRIVATE -fsanitize=address,undefined)
message(STATUS "Sanitizers enabled (ASan/UBSan)")
endif()
if(BUILD_SHARED_LIBS)
set_target_properties(sioclient
PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION}
)
endif()
list(APPEND TARGET_LIBRARIES sioclient)
# Build HTTPS library with TLS support (sioclient_tls)
find_package(OpenSSL)
if(OPENSSL_FOUND)
add_library(sioclient_tls ${ALL_SRC})
target_include_directories(sioclient_tls PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
PRIVATE
${MODULE_INCLUDE_DIRS}
${OPENSSL_INCLUDE_DIR}
)
target_compile_features(sioclient_tls PUBLIC cxx_std_20)
target_compile_definitions(sioclient_tls PRIVATE -DSIO_TLS)
target_link_libraries(sioclient_tls PRIVATE OpenSSL::SSL OpenSSL::Crypto)
target_link_libraries(sioclient_tls PUBLIC Threads::Threads)
if (NOT USE_SUBMODULES)
target_link_libraries(sioclient_tls PRIVATE websocketpp::websocketpp asio asio::asio simdjson::simdjson)
endif()
# Add simdjson source file when using submodules
if(USE_SUBMODULES)
target_sources(sioclient_tls PRIVATE ${CMAKE_CURRENT_LIST_DIR}/lib/simdjson/singleheader/simdjson.cpp)
endif()
# Apply build-type optimizations to HTTPS library
if(CMAKE_BUILD_TYPE STREQUAL "Release")
if(ENABLE_LTO)
check_ipo_supported(RESULT ipo_supported OUTPUT ipo_err)
if(ipo_supported)
set_property(TARGET sioclient_tls PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE)
message(STATUS "LTO enabled for sioclient_tls")
else()
message(WARNING "LTO not supported: ${ipo_err}")
endif()
endif()
elseif(ENABLE_SANITIZERS AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_compile_options(sioclient_tls PRIVATE -fsanitize=address,undefined -fno-omit-frame-pointer)
target_link_options(sioclient_tls PRIVATE -fsanitize=address,undefined)
endif()
if(BUILD_SHARED_LIBS)
set_target_properties(sioclient_tls
PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION}
)
endif()
list(APPEND TARGET_LIBRARIES sioclient_tls)
endif()
export(PACKAGE sioclient)
file(GLOB ALL_HEADERS ${CMAKE_CURRENT_LIST_DIR}/src/*.h)
install(FILES ${ALL_HEADERS}
DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
)
install(TARGETS ${TARGET_LIBRARIES} EXPORT sioclientTargets
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
)
# === generate a CMake Config File ===
include(CMakePackageConfigHelpers)
set(ConfigPackageLocation ${CMAKE_INSTALL_LIBDIR}/cmake/sioclient)
string(REGEX REPLACE "([^;]+)" "find_dependency(\\1)" _find_dependency_calls "${_package_dependencies}")
string(REPLACE ";" "\n" _find_dependency_calls "${_find_dependency_calls}")
write_basic_package_version_file(
"${CMAKE_CURRENT_BINARY_DIR}/sioclient/sioclientConfigVersion.cmake"
VERSION ${sioclient_VERSION}
COMPATIBILITY AnyNewerVersion
)
export(EXPORT sioclientTargets
FILE "${CMAKE_CURRENT_BINARY_DIR}/sioclient/sioclientTargets.cmake"
NAMESPACE sioclient::
)
configure_package_config_file(sioclientConfig.cmake.in
"${CMAKE_CURRENT_BINARY_DIR}/sioclient/sioclientConfig.cmake"
INSTALL_DESTINATION "${ConfigPackageLocation}"
)
install(EXPORT sioclientTargets
NAMESPACE
sioclient::
DESTINATION
${ConfigPackageLocation}
)
install(
FILES
"${CMAKE_CURRENT_BINARY_DIR}/sioclient/sioclientConfig.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/sioclient/sioclientConfigVersion.cmake"
"${CMAKE_CURRENT_BINARY_DIR}/sioclient/sioclientTargets.cmake"
DESTINATION
${ConfigPackageLocation}
)
if((CMAKE_PROJECT_NAME STREQUAL PROJECT_NAME AND BUILD_TESTING) OR BUILD_UNIT_TESTS)
add_subdirectory(test)
endif()