@@ -140,25 +140,70 @@ if (NOT MSVC)
140
140
set (OPENDHT_PROXY_OPENSSL OFF )
141
141
endif ()
142
142
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 )
143
+ include_directories (src/compat/msvc )
144
+
145
+ set (CMAKE_MAP_IMPORTED_CONFIG_RELWITHDEBINFO RELEASE)
146
+
147
+ pkg_search_module(GnuTLS REQUIRED IMPORTED_TARGET GnuTLS)
148
+ include_directories (${GnuTLS_INCLUDEDIR} )
149
+ link_directories (${GnuTLS_LIBDIR} )
150
+
151
+ pkg_search_module(nettle REQUIRED IMPORTED_TARGET nettle)
152
+ include_directories (${nettle_INCLUDEDIR} )
153
+ link_directories (${nettle_LIBDIR} )
154
+
155
+ find_package (msgpack-cxx CONFIG REQUIRED)
156
+ get_target_property (MSGPACK_INCLUDEDIR msgpack-cxx INTERFACE_INCLUDE_DIRECTORIES )
157
+ include_directories (${MSGPACK_INCLUDEDIR} )
158
+
159
+ find_package (unofficial-argon2 CONFIG REQUIRED)
160
+ get_target_property (ARGON2_INCLUDEDIR unofficial::argon2::libargon2 INTERFACE_INCLUDE_DIRECTORIES )
161
+ include_directories (${ARGON2_INCLUDEDIR} )
162
+
163
+ set (argon2_lib ", libargon2" )
164
+
165
+ find_package (jsoncpp CONFIG REQUIRED)
166
+ get_target_property (JSONCPP_LIB JsonCpp::JsonCpp INTERFACE_LINK_LIBRARIES)
167
+ get_target_property (JSONCPP_INCLUDEDIR ${JSONCPP_LIB} INTERFACE_INCLUDE_DIRECTORIES )
168
+ include_directories (${JSONCPP_INCLUDEDIR} )
169
+
170
+ set (jsoncpp_lib ", jsoncpp" )
171
+
172
+ find_package (fmt CONFIG REQUIRED)
173
+ get_target_property (FMT_INCLUDEDIR fmt::fmt-header-only INTERFACE_INCLUDE_DIRECTORIES )
174
+ include_directories (${FMT_INCLUDEDIR} )
175
+
147
176
list (APPEND opendht_SOURCES
148
177
src/base64.h
149
178
src/base64.cpp
150
179
)
151
180
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 ()
181
+
182
+ if (OPENDHT_HTTP OR OPENDHT_PEER_DISCOVERY)
183
+ find_package (asio CONFIG REQUIRED)
184
+ get_target_property (ASIO_INCLUDEDIR asio INTERFACE_INCLUDE_DIRECTORIES )
185
+ include_directories (${ASIO_INCLUDEDIR} )
186
+ endif ()
187
+
188
+ if (OPENDHT_HTTP)
189
+ find_package (restinio CONFIG REQUIRED)
190
+ get_target_property (RESTINIO_INCLUDEDIR restinio::restinio INTERFACE_INCLUDE_DIRECTORIES )
191
+ include_directories (${RESTINIO_INCLUDEDIR} )
192
+
193
+ find_package (llhttp CONFIG REQUIRED)
194
+ get_target_property (LLHTTP_INCLUDEDIR llhttp::llhttp_static INTERFACE_INCLUDE_DIRECTORIES )
195
+ include_directories (${LLHTTP_INCLUDEDIR} )
196
+ set (http_lib "-lllhttp" )
197
+
198
+ if (OPENDHT_PROXY_OPENSSL)
199
+ find_package (OpenSSL REQUIRED)
200
+ get_target_property (OPENSSL_INCLUDEDIR OpenSSL::SSL INTERFACE_INCLUDE_DIRECTORIES )
201
+ include_directories (${OPENSSL_INCLUDEDIR} )
202
+ set (openssl_lib ", openssl" )
203
+ endif ()
204
+ else ()
205
+ set (OPENDHT_PROXY_OPENSSL OFF )
206
+ endif ()
162
207
endif ()
163
208
164
209
if (OPENDHT_HTTP OR OPENDHT_PEER_DISCOVERY)
@@ -182,7 +227,7 @@ else ()
182
227
-DGNUTLS_INTERNAL_BUILD)
183
228
set (DISABLE_MSC_WARNINGS "/wd4101 /wd4244 /wd4267 /wd4273 /wd4804 /wd4834 /wd4996" )
184
229
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${DISABLE_MSC_WARNINGS} " )
185
- set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP" )
230
+ set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /MP /bigobj " )
186
231
endif ()
187
232
set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMSGPACK_NO_BOOST -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT" )
188
233
@@ -204,7 +249,7 @@ include_directories (
204
249
# Install dirs
205
250
include (GNUInstallDirs)
206
251
set (prefix ${CMAKE_INSTALL_PREFIX} )
207
- set (exec_prefix "\ $ {prefix}" )
252
+ set (exec_prefix "${prefix} " )
208
253
set (libdir "${CMAKE_INSTALL_FULL_LIBDIR} " )
209
254
set (includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR} " )
210
255
set (bindir "${CMAKE_INSTALL_FULL_BINDIR} " )
@@ -326,69 +371,36 @@ if (MSVC)
326
371
endif ()
327
372
328
373
# 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
374
373
- add_library (opendht
374
- ${opendht_SOURCES}
375
- ${opendht_HEADERS}
376
- ${obj_libs}
375
+ add_library (opendht ${opendht_SOURCES} ${opendht_HEADERS} )
376
+
377
+ target_include_directories (opendht
378
+ PUBLIC
379
+ "$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR} >"
380
+ "$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR} >"
377
381
)
378
- set_target_properties (opendht PROPERTIES OUTPUT_NAME "opendht" )
379
382
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 ()
383
+ set_target_properties (opendht PROPERTIES OUTPUT_NAME "opendht" )
384
+
386
385
if (MSVC )
386
+ target_link_libraries (opendht PUBLIC PkgConfig::GnuTLS JsonCpp::JsonCpp fmt::fmt-header-only PRIVATE PkgConfig::nettle unofficial::argon2::libargon2)
387
+ if (OPENDHT_HTTP)
388
+ target_link_libraries (opendht PUBLIC llhttp::llhttp_static)
389
+ if (OPENDHT_PROXY_OPENSSL)
390
+ target_link_libraries (opendht PUBLIC OpenSSL::SSL OpenSSL::Crypto)
391
+ endif ()
392
+ endif ()
387
393
if (OPENDHT_STATIC)
388
394
target_link_libraries (opendht PUBLIC ${Win32_STATIC_LIBRARIES} ${Win32_IMPORT_LIBRARIES} )
389
- set_target_properties (opendht PROPERTIES OUTPUT_NAME "libopendht" )
395
+ set_target_properties (opendht PROPERTIES OUTPUT_NAME "libopendht" )
390
396
endif ()
391
397
else ()
398
+ if (APPLE )
399
+ target_link_libraries (opendht PRIVATE "-framework CoreFoundation" "-framework Security" )
400
+ endif ()
401
+ if (NOT HAVE_MSGPACKCXX)
402
+ target_link_libraries (opendht PUBLIC ${MSGPACK_TARGET} )
403
+ endif ()
392
404
target_link_libraries (opendht
393
405
PRIVATE
394
406
PkgConfig::argon2
@@ -415,9 +427,9 @@ else()
415
427
endif ()
416
428
417
429
if (BUILD_SHARED_LIBS )
418
- set_target_properties (opendht PROPERTIES IMPORT_SUFFIX "_import.lib" )
419
430
set_target_properties (opendht PROPERTIES SOVERSION ${opendht_VERSION_MAJOR} VERSION ${opendht_VERSION} )
420
431
target_compile_definitions (opendht PRIVATE OPENDHT_BUILD)
432
+ target_compile_definitions (opendht PRIVATE opendht_EXPORTS)
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