5
5
# ---------------------------------------------------------------------------
6
6
# This file is part of the "sockpp" C++ socket library.
7
7
#
8
- # Copyright (c) 2017-2023 Frank Pagliughi
8
+ # Copyright (c) 2017-2024 Frank Pagliughi
9
9
# All rights reserved.
10
10
#
11
11
# Redistribution and use in source and binary forms, with or without
@@ -67,19 +67,34 @@ endif()
67
67
68
68
# --- Setting naming variables ---
69
69
70
- set (SOCKPP_SHARED_LIBRARY sockpp)
71
- set (SOCKPP_STATIC_LIBRARY sockpp-static )
72
- set (SOCKPP_OBJECT_LIBRARY sockpp-objs)
73
-
74
70
set (SOCKPP_INCLUDE_DIR ${PROJECT_SOURCE_DIR} /include )
75
71
set (SOCKPP_GENERATED_DIR ${CMAKE_CURRENT_BINARY_DIR} /generated )
76
72
73
+ # --- Collect the targets names ---
74
+
75
+ if (${SOCKPP_BUILD_SHARED} )
76
+ list (APPEND SOCKPP_TARGETS sockpp-shared)
77
+ endif ()
78
+
79
+ if (${SOCKPP_BUILD_STATIC} )
80
+ list (APPEND SOCKPP_TARGETS sockpp-static )
81
+ endif ()
82
+
83
+ if (NOT SOCKPP_TARGETS)
84
+ message (FATAL_ERROR "No targets are specified" )
85
+ endif ()
86
+
77
87
# --- Project uses C++17 ---
78
88
79
89
set (CMAKE_CXX_STANDARD 17)
80
90
set (CMAKE_CXX_STANDARD_REQUIRED ON )
81
91
set (CMAKE_CXX_EXTENSIONS OFF )
82
92
93
+ if (WIN32 )
94
+ set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON )
95
+ set (LIBS_SYSTEM ws2_32)
96
+ endif ()
97
+
83
98
# --- Generate a version header ---
84
99
85
100
configure_file (
@@ -92,125 +107,18 @@ configure_file(
92
107
93
108
add_subdirectory (src)
94
109
95
- # --- System libraries ---
96
-
97
- if (WIN32 )
98
- set (CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON )
99
- set (LIBS_SYSTEM ws2_32)
100
- endif ()
101
-
102
- # --- Collect the targets names ---
103
-
104
- if (${SOCKPP_BUILD_SHARED} )
105
- list (APPEND SOCKPP_TARGETS ${SOCKPP_SHARED_LIBRARY} )
106
- endif ()
107
-
108
- if (${SOCKPP_BUILD_STATIC} )
109
- list (APPEND SOCKPP_TARGETS ${SOCKPP_STATIC_LIBRARY} )
110
- endif ()
111
-
112
- # --- Create the libraries and export them ---
113
-
114
- if (NOT SOCKPP_TARGETS)
115
- message (FATAL_ERROR "No targets are specified" )
116
- endif ()
117
-
118
- if (${SOCKPP_BUILD_SHARED} )
119
- message (STATUS "Creating shared library: ${SOCKPP_SHARED_LIBRARY} " )
120
- add_library (${SOCKPP_SHARED_LIBRARY} SHARED $<TARGET_OBJECTS:${SOCKPP_OBJECT_LIBRARY} >)
121
-
122
- target_include_directories (${SOCKPP_SHARED_LIBRARY}
123
- PUBLIC
124
- $<BUILD_INTERFACE:${SOCKPP_INCLUDE_DIR} >
125
- $<INSTALL_INTERFACE:include >
126
- PRIVATE
127
- ${SOCKPP_GENERATED_DIR} /include
128
- )
129
-
130
- target_link_libraries (${SOCKPP_SHARED_LIBRARY} PUBLIC ${LIBS_SYSTEM} )
131
- if (SOCKPP_WITH_OPENSSL)
132
- target_link_libraries (${SOCKPP_SHARED_LIBRARY} PUBLIC OpenSSL::SSL OpenSSL::Crypto)
133
- endif ()
134
-
135
- set_target_properties (${SOCKPP_SHARED_LIBRARY} PROPERTIES
136
- VERSION ${PROJECT_VERSION}
137
- SOVERSION ${PROJECT_VERSION_MAJOR}
138
- )
139
-
140
- list (APPEND TARGET_FILES ${SOCKPP_SHARED_LIBRARY} )
141
-
142
- if (SOCKPP_WITH_OPENSSL)
143
- target_link_libraries (${SOCKPP_SHARED_LIBRARY}
144
- PUBLIC
145
- OpenSSL::SSL
146
- OpenSSL::Crypto
147
- )
148
- elseif (SOCKPP_WITH_MBEDTLS)
149
- target_link_libraries (${SOCKPP_SHARED_LIBRARY}
150
- PUBLIC
151
- MbedTLS::mbedtls
152
- MbedTLS::mbedcrypto
153
- MbedTLS::mbedx509
154
- )
155
- endif ()
156
- endif ()
157
-
158
- if (${SOCKPP_BUILD_STATIC} )
159
- message (STATUS "Creating static library: ${SOCKPP_STATIC_LIBRARY} " )
160
- add_library (${SOCKPP_STATIC_LIBRARY} STATIC $<TARGET_OBJECTS:${SOCKPP_OBJECT_LIBRARY} >)
161
-
162
- target_include_directories (${SOCKPP_STATIC_LIBRARY}
163
- PUBLIC
164
- $<BUILD_INTERFACE:${SOCKPP_INCLUDE_DIR} >
165
- $<INSTALL_INTERFACE:include >
166
- PRIVATE
167
- ${SOCKPP_GENERATED_DIR} /include
168
- )
169
-
170
- target_link_libraries (${SOCKPP_STATIC_LIBRARY} PUBLIC ${LIBS_SYSTEM} )
171
- if (SOCKPP_WITH_OPENSSL)
172
- target_link_libraries (${SOCKPP_STATIC_LIBRARY} PUBLIC OpenSSL::SSL OpenSSL::Crypto)
173
- endif ()
174
-
175
- # On *nix systems, the static library can have the same base filename
176
- # as the shared library, thus 'libsockpp.a' for the static lib.
177
- # On Windows they need different names to tell the static lib from the
178
- # DLL import library.
179
- if (UNIX )
180
- set_target_properties (${SOCKPP_STATIC_LIBRARY} PROPERTIES
181
- OUTPUT_NAME ${SOCKPP_SHARED_LIBRARY}
182
- )
183
- endif ()
184
-
185
- list (APPEND TARGET_FILES ${SOCKPP_STATIC_LIBRARY} )
186
-
187
- if (SOCKPP_WITH_OPENSSL)
188
- target_link_libraries (${SOCKPP_STATIC_LIBRARY}
189
- PUBLIC
190
- OpenSSL::SSL
191
- OpenSSL::Crypto
192
- )
193
- elseif (SOCKPP_WITH_MBEDTLS)
194
- target_link_libraries (${SOCKPP_STATIC_LIBRARY} PUBLIC
195
- MbedTLS::mbedtls
196
- MbedTLS::mbedcrypto
197
- MbedTLS::mbedx509
198
- )
199
- endif ()
200
- endif ()
201
-
202
110
# --- Install Targets ---
203
111
204
112
include (GNUInstallDirs)
205
113
206
- install (TARGETS ${TARGET_FILES }
207
- EXPORT sockpp-targets
114
+ install (TARGETS ${SOCKPP_TARGETS }
115
+ EXPORT Sockpp
208
116
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
209
117
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
210
118
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
211
119
)
212
120
213
- install (EXPORT sockpp-targets
121
+ install (EXPORT Sockpp
214
122
FILE
215
123
sockppTargets.cmake
216
124
NAMESPACE
@@ -222,13 +130,17 @@ install(EXPORT sockpp-targets
222
130
include (CMakePackageConfigHelpers)
223
131
224
132
write_basic_package_version_file(
225
- ${SOCKPP_GENERATED_DIR} /cmake/sockppConfigVersion.cmake
226
- VERSION ${PROJECT_VERSION}
227
- COMPATIBILITY AnyNewerVersion
133
+ ${SOCKPP_GENERATED_DIR} /cmake/sockppConfigVersion.cmake
134
+ VERSION ${PROJECT_VERSION}
135
+ COMPATIBILITY AnyNewerVersion
228
136
)
229
137
230
- install (DIRECTORY include / ${SOCKPP_GENERATED_DIR} /include /
231
- DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}
138
+ install (
139
+ DIRECTORY
140
+ include /
141
+ ${SOCKPP_GENERATED_DIR} /include /
142
+ DESTINATION
143
+ ${CMAKE_INSTALL_INCLUDEDIR}
232
144
)
233
145
234
146
install (
@@ -245,14 +157,6 @@ if(SOCKPP_BUILD_DOCUMENTATION)
245
157
add_subdirectory (doc )
246
158
endif ()
247
159
248
- # --- Default library for examples and unit tests ---
249
-
250
- if (SOCKPP_BUILD_SHARED)
251
- set (SOCKPP_LIB ${SOCKPP_SHARED_LIBRARY} )
252
- else ()
253
- set (SOCKPP_LIB ${SOCKPP_STATIC_LIBRARY} )
254
- endif ()
255
-
256
160
# --- Example applications ---
257
161
258
162
if (SOCKPP_BUILD_EXAMPLES)
0 commit comments