-
Notifications
You must be signed in to change notification settings - Fork 730
/
CMakeLists.txt
177 lines (146 loc) · 5.34 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
cmake_minimum_required(VERSION 3.12...3.27)
PROJECT(sioclient
VERSION 3.1.0
)
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)
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++11
-D_WEBSOCKETPP_CPP11_STL_
-D_WEBSOCKETPP_CPP11_FUNCTIONAL_
-D_WEBSOCKETPP_CPP11_TYPE_TRAITS_
-D_WEBSOCKETPP_CPP11_CHRONO_
)
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"
)
add_library(sioclient ${ALL_SRC})
if(USE_SUBMODULES)
set(MODULE_INCLUDE_DIRS
${CMAKE_CURRENT_LIST_DIR}/lib/websocketpp
${CMAKE_CURRENT_LIST_DIR}/lib/rapidjson/include
${CMAKE_CURRENT_LIST_DIR}/lib/asio/asio/include
)
else()
find_package(websocketpp CONFIG REQUIRED)
find_package(asio CONFIG REQUIRED)
find_package(RapidJSON CONFIG REQUIRED)
target_link_libraries(sioclient PRIVATE websocketpp::websocketpp asio::asio rapidjson)
endif()
include(GNUInstallDirs)
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_11)
find_package(Threads REQUIRED)
target_link_libraries(sioclient PUBLIC Threads::Threads)
if(BUILD_SHARED_LIBS)
set_target_properties(sioclient
PROPERTIES
SOVERSION ${PROJECT_VERSION_MAJOR}
VERSION ${PROJECT_VERSION}
)
endif()
list(APPEND TARGET_LIBRARIES sioclient)
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_11)
target_link_libraries(sioclient_tls PRIVATE OpenSSL::SSL OpenSSL::Crypto)
if (NOT USE_SUBMODULES)
target_link_libraries(sioclient_tls PRIVATE websocketpp::websocketpp asio asio::asio rapidjson)
endif()
target_compile_definitions(sioclient_tls PRIVATE -DSIO_TLS)
target_link_libraries(sioclient_tls PUBLIC Threads::Threads)
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()