@@ -20,7 +20,6 @@ set (VERSION "${opendht_VERSION}")
20
20
21
21
# Options
22
22
option (BUILD_SHARED_LIBS "Build shared library" ON )
23
- CMAKE_DEPENDENT_OPTION (OPENDHT_STATIC "Build static library" OFF BUILD_SHARED_LIBS ON )
24
23
option (OPENDHT_PYTHON "Build Python bindings" OFF )
25
24
option (OPENDHT_TOOLS "Build DHT tools" ON )
26
25
option (OPENDHT_SYSTEMD "Install systemd module" OFF )
@@ -140,25 +139,70 @@ if (NOT MSVC)
140
139
set (OPENDHT_PROXY_OPENSSL OFF )
141
140
endif ()
142
141
else ()
143
- set (WIN32_DEP_DIR ${PROJECT_SOURCE_DIR} /../)
144
- include_directories (${WIN32_DEP_DIR} /../msvc /include ) # SMP gnutls
145
- include_directories (${WIN32_DEP_DIR} /argon2/include )
146
- include_directories (${WIN32_DEP_DIR} /jsoncpp/include )
142
+ include_directories (src/compat/msvc )
143
+
144
+ set (CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE)
145
+
146
+ pkg_search_module(GnuTLS REQUIRED IMPORTED_TARGET GnuTLS)
147
+ include_directories (${GnuTLS_INCLUDEDIR} )
148
+ link_directories (${GnuTLS_LIBDIR} )
149
+
150
+ pkg_search_module(nettle REQUIRED IMPORTED_TARGET nettle)
151
+ include_directories (${nettle_INCLUDEDIR} )
152
+ link_directories (${nettle_LIBDIR} )
153
+
154
+ find_package (msgpack-cxx CONFIG REQUIRED)
155
+ get_target_property (MSGPACK_INCLUDEDIR msgpack-cxx INTERFACE_INCLUDE_DIRECTORIES )
156
+ include_directories (${MSGPACK_INCLUDEDIR} )
157
+
158
+ find_package (unofficial-argon2 CONFIG REQUIRED)
159
+ get_target_property (ARGON2_INCLUDEDIR unofficial::argon2::libargon2 INTERFACE_INCLUDE_DIRECTORIES )
160
+ include_directories (${ARGON2_INCLUDEDIR} )
161
+
162
+ set (argon2_lib ", libargon2" )
163
+
164
+ find_package (jsoncpp CONFIG REQUIRED)
165
+ get_target_property (JSONCPP_LIB JsonCpp::JsonCpp INTERFACE_LINK_LIBRARIES)
166
+ get_target_property (JSONCPP_INCLUDEDIR ${JSONCPP_LIB} INTERFACE_INCLUDE_DIRECTORIES )
167
+ include_directories (${JSONCPP_INCLUDEDIR} )
168
+
169
+ set (jsoncpp_lib ", jsoncpp" )
170
+
171
+ find_package (fmt CONFIG REQUIRED)
172
+ get_target_property (FMT_INCLUDEDIR fmt::fmt-header-only INTERFACE_INCLUDE_DIRECTORIES )
173
+ include_directories (${FMT_INCLUDEDIR} )
174
+
147
175
list (APPEND opendht_SOURCES
148
176
src/base64.h
149
177
src/base64.cpp
150
178
)
151
179
add_definitions (-DOPENDHT_JSONCPP)
152
- include_directories (${WIN32_DEP_DIR} /msgpack-c/include )
153
- if (OPENDHT_HTTP OR OPENDHT_PEER_DISCOVERY)
154
- include_directories (
155
- ${WIN32_DEP_DIR} /asio/asio/include
156
- ${WIN32_DEP_DIR} /openssl/include
157
- ${WIN32_DEP_DIR} /restinio/dev
158
- ${WIN32_DEP_DIR} /fmt/include
159
- ${WIN32_DEP_DIR} /http_parser
160
- )
161
- endif ()
180
+
181
+ if (OPENDHT_HTTP OR OPENDHT_PEER_DISCOVERY)
182
+ find_package (asio CONFIG REQUIRED)
183
+ get_target_property (ASIO_INCLUDEDIR asio INTERFACE_INCLUDE_DIRECTORIES )
184
+ include_directories (${ASIO_INCLUDEDIR} )
185
+ endif ()
186
+
187
+ if (OPENDHT_HTTP)
188
+ find_package (restinio CONFIG REQUIRED)
189
+ get_target_property (RESTINIO_INCLUDEDIR restinio::restinio INTERFACE_INCLUDE_DIRECTORIES )
190
+ include_directories (${RESTINIO_INCLUDEDIR} )
191
+
192
+ find_package (llhttp CONFIG REQUIRED)
193
+ get_target_property (LLHTTP_INCLUDEDIR llhttp::llhttp_static INTERFACE_INCLUDE_DIRECTORIES )
194
+ include_directories (${LLHTTP_INCLUDEDIR} )
195
+ set (http_lib "-lllhttp" )
196
+
197
+ if (OPENDHT_PROXY_OPENSSL)
198
+ find_package (OpenSSL REQUIRED)
199
+ get_target_property (OPENSSL_INCLUDEDIR OpenSSL::SSL INTERFACE_INCLUDE_DIRECTORIES )
200
+ include_directories (${OPENSSL_INCLUDEDIR} )
201
+ set (openssl_lib ", openssl" )
202
+ endif ()
203
+ else ()
204
+ set (OPENDHT_PROXY_OPENSSL OFF )
205
+ endif ()
162
206
endif ()
163
207
164
208
if (OPENDHT_HTTP OR OPENDHT_PEER_DISCOVERY)
@@ -182,7 +226,7 @@ else ()
182
226
-DGNUTLS_INTERNAL_BUILD)
183
227
set (DISABLE_MSC_WARNINGS "/wd4101 /wd4244 /wd4267 /wd4273 /wd4804 /wd4834 /wd4996" )
184
228
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DISABLE_MSC_WARNINGS} " )
185
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP" )
229
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /bigobj " )
186
230
endif ()
187
231
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMSGPACK_NO_BOOST -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT" )
188
232
@@ -204,7 +248,7 @@ include_directories (
204
248
# Install dirs
205
249
include (GNUInstallDirs)
206
250
set (prefix ${CMAKE_INSTALL_PREFIX} )
207
- set (exec_prefix "\ $ {prefix}" )
251
+ set (exec_prefix "${prefix} " )
208
252
set (libdir "${CMAKE_INSTALL_FULL_LIBDIR} " )
209
253
set (includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR} " )
210
254
set (bindir "${CMAKE_INSTALL_FULL_BINDIR} " )
@@ -326,69 +370,36 @@ if (MSVC)
326
370
endif ()
327
371
328
372
# Targets
329
- if (MSVC )
330
- if (OPENDHT_STATIC)
331
- if (OPENDHT_TOOLS)
332
- function (add_obj_lib name libfile)
333
- add_library (${name} OBJECT IMPORTED )
334
- set_property (TARGET ${name} PROPERTY IMPORTED_OBJECTS ${libfile} )
335
- endfunction ()
336
- add_obj_lib (win32_json ${WIN32_DEP_DIR} /../msvc /lib/x64/lib_json.lib)
337
- add_obj_lib (win32_gnutls ${WIN32_DEP_DIR} /../msvc /lib/x64/libgnutls.lib)
338
- add_obj_lib (win32_argon2 ${WIN32_DEP_DIR} /argon2/vs2015/Argon2Ref/vs2015/build /Argon2Ref.lib)
339
- list (APPEND obj_libs
340
- $<TARGET_OBJECTS:win32_json>
341
- $<TARGET_OBJECTS:win32_gnutls>
342
- $<TARGET_OBJECTS:win32_argon2>
343
- )
344
- if (OPENDHT_HTTP)
345
- add_obj_lib (win32_fmt ${WIN32_DEP_DIR} /fmt/msvc /Release/fmt.lib)
346
- add_obj_lib (win32_http_parser ${WIN32_DEP_DIR} /http_parser/x64/Release/http-parser.lib)
347
- add_obj_lib (win32_ssl ${WIN32_DEP_DIR} /openssl/libssl_static.lib)
348
- add_obj_lib (win32_crypto ${WIN32_DEP_DIR} /openssl/libcrypto_static.lib)
349
- list (APPEND obj_libs
350
- $<TARGET_OBJECTS:win32_fmt>
351
- $<TARGET_OBJECTS:win32_http_parser>
352
- $<TARGET_OBJECTS:win32_ssl>
353
- $<TARGET_OBJECTS:win32_crypto>
354
- )
355
- endif ()
356
- else ()
357
- list (APPEND win32_Libs
358
- ${PROJECT_SOURCE_DIR} /../../msvc /lib/x64/libgnutls.lib
359
- ${PROJECT_SOURCE_DIR} /../../msvc /lib/x64/lib_json.lib
360
- ${PROJECT_SOURCE_DIR} /../argon2/vs2015/Argon2Ref/vs2015/build /Argon2Ref.lib
361
- )
362
- list (APPEND win32_Libs
363
- ${PROJECT_SOURCE_DIR} /../fmt/msvc /Release/fmt.lib
364
- ${PROJECT_SOURCE_DIR} /../http_parser/x64/Release/http-parser.lib
365
- ${PROJECT_SOURCE_DIR} /../openssl/libssl.lib
366
- ${PROJECT_SOURCE_DIR} /../openssl/libcrypto.lib
367
- )
368
- endif ()
369
- set (CMAKE_STATIC_LINKER_FLAGS "${CMAKE_STATIC_LINKER_FLAGS} /ignore:4006" )
370
- endif ()
371
- endif ()
372
373
373
- add_library (opendht
374
- ${opendht_SOURCES}
375
- ${opendht_HEADERS}
376
- ${obj_libs}
374
+ add_library (opendht ${opendht_SOURCES} ${opendht_HEADERS} )
375
+
376
+ target_include_directories (opendht
377
+ PUBLIC
378
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} >"
379
+ "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >"
377
380
)
378
- set_target_properties (opendht PROPERTIES OUTPUT_NAME "opendht" )
379
381
380
- if (NOT HAVE_MSGPACKCXX)
381
- target_link_libraries (opendht PUBLIC ${MSGPACK_TARGET} )
382
- endif ()
383
- if (APPLE )
384
- target_link_libraries (opendht PRIVATE "-framework CoreFoundation" "-framework Security" )
385
- endif ()
382
+ set_target_properties (opendht PROPERTIES OUTPUT_NAME "opendht" )
383
+
386
384
if (MSVC )
387
- if (OPENDHT_STATIC)
385
+ target_link_libraries (opendht PUBLIC PkgConfig::GnuTLS JsonCpp::JsonCpp fmt::fmt-header-only PRIVATE PkgConfig::nettle unofficial::argon2::libargon2)
386
+ if (OPENDHT_HTTP)
387
+ target_link_libraries (opendht PUBLIC llhttp::llhttp_static)
388
+ if (OPENDHT_PROXY_OPENSSL)
389
+ target_link_libraries (opendht PUBLIC OpenSSL::SSL OpenSSL::Crypto)
390
+ endif ()
391
+ endif ()
392
+ if (NOT BUILD_SHARED_LIBS )
388
393
target_link_libraries (opendht PUBLIC ${Win32_STATIC_LIBRARIES} ${Win32_IMPORT_LIBRARIES} )
389
- set_target_properties (opendht PROPERTIES OUTPUT_NAME "libopendht" )
394
+ set_target_properties (opendht PROPERTIES OUTPUT_NAME "libopendht" )
390
395
endif ()
391
396
else ()
397
+ if (APPLE )
398
+ target_link_libraries (opendht PRIVATE "-framework CoreFoundation" "-framework Security" )
399
+ endif ()
400
+ if (NOT HAVE_MSGPACKCXX)
401
+ target_link_libraries (opendht PUBLIC ${MSGPACK_TARGET} )
402
+ endif ()
392
403
target_link_libraries (opendht
393
404
PRIVATE
394
405
PkgConfig::argon2
@@ -415,9 +426,10 @@ else()
415
426
endif ()
416
427
417
428
if (BUILD_SHARED_LIBS )
418
- set_target_properties (opendht PROPERTIES IMPORT_SUFFIX "_import.lib" )
419
429
set_target_properties (opendht PROPERTIES SOVERSION ${opendht_VERSION_MAJOR} VERSION ${opendht_VERSION} )
420
- target_compile_definitions (opendht PRIVATE OPENDHT_BUILD)
430
+ target_compile_definitions (opendht PRIVATE opendht_EXPORTS)
431
+ else ()
432
+ target_compile_definitions (opendht PRIVATE OPENDHT_STATIC) # to build library with default class attributes
421
433
endif ()
422
434
install (TARGETS opendht DESTINATION ${CMAKE_INSTALL_LIBDIR} EXPORT opendht)
423
435
@@ -455,6 +467,7 @@ write_basic_package_version_file("${CMAKE_CURRENT_BINARY_DIR}/opendhtConfigVersi
455
467
VERSION ${opendht_VERSION}
456
468
COMPATIBILITY AnyNewerVersion
457
469
)
470
+
458
471
# PkgConfig module
459
472
configure_file (
460
473
opendht.pc.in
@@ -467,6 +480,9 @@ install (DIRECTORY include DESTINATION ${CMAKE_INSTALL_PREFIX})
467
480
install (FILES ${CMAKE_CURRENT_BINARY_DIR} /opendht.pc DESTINATION ${CMAKE_INSTALL_LIBDIR} /pkgconfig)
468
481
install (EXPORT opendht DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/opendht FILE opendhtConfig.cmake)
469
482
install (FILES ${CMAKE_CURRENT_BINARY_DIR} /opendhtConfigVersion.cmake DESTINATION ${CMAKE_INSTALL_LIBDIR} /cmake/opendht)
483
+ if (MSVC AND BUILD_SHARED_LIBS )
484
+ install (FILES $<TARGET_PDB_FILE:opendht> CONFIGURATIONS "RelWithDebInfo" "Debug" DESTINATION ${CMAKE_INSTALL_LIBDIR} )
485
+ endif ()
470
486
471
487
# Unit tests
472
488
if (BUILD_TESTING AND NOT MSVC )
0 commit comments