Adrien Béraud | 53bc445 | 2023-07-12 11:15:13 -0400 | [diff] [blame] | 1 | cmake_minimum_required(VERSION 3.16) |
Adrien Béraud | d50178b | 2023-07-09 21:41:12 -0400 | [diff] [blame] | 2 | project(dhtnet |
| 3 | VERSION 0.0.1 |
| 4 | LANGUAGES CXX |
| 5 | DESCRIPTION "A C++ library for NAT traversal and secure communication") |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 6 | |
| 7 | set(CMAKE_CXX_STANDARD 17) |
| 8 | set(CMAKE_CXX_STANDARD_REQUIRED ON) |
Adrien Béraud | efe2737 | 2023-05-27 18:56:29 -0400 | [diff] [blame] | 9 | include(CTest) |
Adrien Béraud | 665d111 | 2023-06-01 19:03:57 -0400 | [diff] [blame] | 10 | include(GNUInstallDirs) |
Adrien Béraud | a4030cd | 2023-06-21 09:35:40 -0400 | [diff] [blame] | 11 | set (prefix ${CMAKE_INSTALL_PREFIX}) |
| 12 | set (exec_prefix "\${prefix}") |
| 13 | set (libdir "${CMAKE_INSTALL_FULL_LIBDIR}") |
| 14 | set (includedir "${CMAKE_INSTALL_FULL_INCLUDEDIR}") |
Adrien Béraud | d50178b | 2023-07-09 21:41:12 -0400 | [diff] [blame] | 15 | set (VERSION ${CMAKE_PROJECT_VERSION}) |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 16 | |
| 17 | find_package (PkgConfig REQUIRED) |
Adrien Béraud | 66bb3c6 | 2023-07-12 19:08:13 -0400 | [diff] [blame^] | 18 | find_package(msgpackc-cxx QUIET CONFIG NAMES msgpackc-cxx msgpack) |
Adrien Béraud | dbb0686 | 2023-07-08 09:18:39 -0400 | [diff] [blame] | 19 | if(msgpackc-cxx_FOUND) |
| 20 | add_library(msgpack-cxx ALIAS msgpackc-cxx) |
| 21 | else() |
Adrien Béraud | 66bb3c6 | 2023-07-12 19:08:13 -0400 | [diff] [blame^] | 22 | find_package(msgpack-cxx CONFIG REQUIRED) |
Adrien Béraud | dbb0686 | 2023-07-08 09:18:39 -0400 | [diff] [blame] | 23 | endif() |
| 24 | |
Adrien Béraud | efe2737 | 2023-05-27 18:56:29 -0400 | [diff] [blame] | 25 | find_package(fmt) |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 26 | pkg_check_modules (opendht REQUIRED IMPORTED_TARGET opendht>=2.6.0) |
| 27 | pkg_check_modules (pjproject REQUIRED IMPORTED_TARGET libpjproject) |
| 28 | |
| 29 | set (CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DMSGPACK_NO_BOOST -DMSGPACK_DISABLE_LEGACY_NIL -DMSGPACK_DISABLE_LEGACY_CONVERT") |
| 30 | |
| 31 | # Sources |
| 32 | list (APPEND dhtnet_SOURCES |
| 33 | src/connectionmanager.cpp |
| 34 | src/ice_transport.cpp |
| 35 | src/multiplexed_socket.cpp |
| 36 | src/peer_connection.cpp |
| 37 | src/string_utils.cpp |
| 38 | src/fileutils.cpp |
| 39 | src/security/tls_session.cpp |
| 40 | src/security/certstore.cpp |
| 41 | src/security/threadloop.cpp |
Morteza Namvar | 5f63952 | 2023-07-04 17:08:58 -0400 | [diff] [blame] | 42 | src/upnp/upnp_context.cpp |
| 43 | src/upnp/upnp_control.cpp |
| 44 | src/upnp/protocol/mapping.cpp |
| 45 | src/upnp/upnp_context.cpp |
| 46 | src/upnp/upnp_control.cpp |
| 47 | src/upnp/protocol/igd.cpp |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 48 | ) |
| 49 | |
| 50 | list (APPEND dhtnet_HEADERS |
Adrien Béraud | 149f29e | 2023-07-05 14:47:49 -0400 | [diff] [blame] | 51 | include/connectionmanager.h |
| 52 | include/multiplexed_socket.h |
| 53 | include/tls_session.h |
| 54 | include/certstore.h |
| 55 | include/ice_options.h |
Adrien Béraud | 6de3f88 | 2023-07-06 12:56:29 -0400 | [diff] [blame] | 56 | include/ice_transport.h |
Adrien Béraud | cb121f8 | 2023-07-08 09:18:39 -0400 | [diff] [blame] | 57 | include/ice_transport_factory.h |
Adrien Béraud | aa8c442 | 2023-07-07 11:40:36 -0400 | [diff] [blame] | 58 | include/ice_socket.h |
Adrien Béraud | 149f29e | 2023-07-05 14:47:49 -0400 | [diff] [blame] | 59 | include/fileutils.h |
| 60 | include/string_utils.h |
| 61 | include/ip_utils.h |
| 62 | include/upnp/mapping.h |
| 63 | include/upnp/upnp_context.h |
| 64 | include/upnp/upnp_control.h |
Adrien Béraud | 612b55b | 2023-05-29 10:42:04 -0400 | [diff] [blame] | 65 | ) |
| 66 | |
| 67 | add_library(dhtnet ${dhtnet_SOURCES}) |
Adrien Béraud | dbb0686 | 2023-07-08 09:18:39 -0400 | [diff] [blame] | 68 | target_link_libraries(dhtnet PUBLIC PkgConfig::opendht PkgConfig::pjproject fmt::fmt msgpack-cxx) |
Adrien Béraud | 665d111 | 2023-06-01 19:03:57 -0400 | [diff] [blame] | 69 | target_include_directories(dhtnet PUBLIC |
| 70 | $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 71 | $<INSTALL_INTERFACE:include> |
| 72 | ) |
| 73 | target_compile_definitions(dhtnet PUBLIC PJ_AUTOCONF=1) |
Adrien Béraud | b96f10f | 2023-07-05 14:27:14 -0400 | [diff] [blame] | 74 | set_target_properties(dhtnet PROPERTIES PUBLIC_HEADER "${CMAKE_CURRENT_SOURCE_DIR}/include/${dhtnet_HEADERS}") |
Adrien Béraud | a4030cd | 2023-06-21 09:35:40 -0400 | [diff] [blame] | 75 | |
| 76 | configure_file(dhtnet.pc.in dhtnet.pc @ONLY) |
| 77 | |
Adrien Béraud | a4030cd | 2023-06-21 09:35:40 -0400 | [diff] [blame] | 78 | # Install targets |
Adrien Béraud | 149f29e | 2023-07-05 14:47:49 -0400 | [diff] [blame] | 79 | install(DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/ DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/dhtnet) |
Adrien Béraud | ab6b8b1 | 2023-06-21 09:46:54 -0400 | [diff] [blame] | 80 | install (FILES ${CMAKE_CURRENT_BINARY_DIR}/dhtnet.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig) |
Adrien Béraud | a4030cd | 2023-06-21 09:35:40 -0400 | [diff] [blame] | 81 | |
Adrien Béraud | efe2737 | 2023-05-27 18:56:29 -0400 | [diff] [blame] | 82 | if (BUILD_TESTING AND NOT MSVC) |
| 83 | pkg_search_module(Cppunit REQUIRED IMPORTED_TARGET cppunit) |
| 84 | add_executable(tests_certstore tests/certstore.cpp) |
| 85 | target_link_libraries(tests_certstore PRIVATE dhtnet fmt::fmt PkgConfig::Cppunit) |
| 86 | add_test(NAME tests_certstore COMMAND tests_certstore) |
| 87 | |
| 88 | add_executable(tests_connectionManager tests/connectionManager.cpp) |
| 89 | target_link_libraries(tests_connectionManager PRIVATE dhtnet fmt::fmt PkgConfig::Cppunit) |
| 90 | add_test(NAME tests_connectionManager COMMAND tests_connectionManager) |
| 91 | |
| 92 | #add_executable(tests_fileutils tests/testFileutils.cpp) |
| 93 | #target_link_libraries(tests_fileutils PRIVATE dhtnet fmt::fmt PkgConfig::Cppunit) |
| 94 | #add_test(NAME tests_fileutils COMMAND tests_fileutils) |
| 95 | |
| 96 | #add_executable(tests_stringutils tests/testString_utils.cpp) |
| 97 | #target_link_libraries(tests_stringutils PRIVATE dhtnet fmt::fmt PkgConfig::Cppunit) |
| 98 | #add_test(NAME tests_stringutils COMMAND tests_stringutils) |
Adrien Béraud | a4030cd | 2023-06-21 09:35:40 -0400 | [diff] [blame] | 99 | endif() |