diff --git a/CMakeLists.txt b/CMakeLists.txt index 4b4e8e534c..88c0024c2a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,28 +1,93 @@ # RetroShare decentralized communication platform # # Copyright (C) 2021-2022 Gioacchino Mazzurco +# Copyright (C) 2026 David Bears # # SPDX-License-Identifier: CC0-1.0 -cmake_minimum_required (VERSION 3.15) +cmake_minimum_required(VERSION 3.15) project(bitdht) -set( - RS_DATA_DIR - "${CMAKE_INSTALL_PREFIX}/share/retroshare" - CACHE STRING - "Path where to install RetroShare system wide data" ) +include(GNUInstallDirs) +set(BD_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}") +set(BD_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}") -file( - GLOB BITDHT_SOURCES - src/bitdht/*.c src/bitdht/*.cc src/udp/*.cc src/util/*.cc ) +add_library(${PROJECT_NAME}) +add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME}) -add_library(${PROJECT_NAME} ${BITDHT_SOURCES}) +set(BD_BOOT_FILE "${PROJECT_SOURCE_DIR}/src/bitdht/bdboot.txt") -target_include_directories( - ${PROJECT_NAME} - PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src ) +if(WIN32) + target_compile_definitions(${PROJECT_NAME} PRIVATE UNICODE _UNICODE) + + # Some files trip strict GCC >= 15 diagnostics that are now errors by + # default; downgrade them to warnings for now. + if( + CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR + CMAKE_CXX_COMPILER_ID STREQUAL "Clang" + ) + target_compile_options(${PROJECT_NAME} PRIVATE + -Wno-error=incompatible-pointer-types + -Wno-error=int-conversion + -Wno-error=implicit-function-declaration + ) + endif() +endif() + + +add_subdirectory(src) + + +### installation +install(TARGETS ${PROJECT_NAME} + EXPORT ${PROJECT_NAME}_export + COMPONENT ${PROJECT_NAME} + FILE_SET HEADERS DESTINATION "${BD_INSTALL_INCLUDEDIR}" +) install( - FILES src/bitdht/bdboot.txt - DESTINATION ${RS_DATA_DIR} ) + FILES "${BD_BOOT_FILE}" + DESTINATION "${BD_INSTALL_DATADIR}" + COMPONENT ${PROJECT_NAME} +) + +# config package for install tree +set(CONFIG_DIR "${CMAKE_INSTALL_LIBDIR}/cmake/${PROJECT_NAME}") +install(EXPORT ${PROJECT_NAME}_export + DESTINATION "${CONFIG_DIR}" + FILE ${PROJECT_NAME}-targets.cmake + NAMESPACE ${PROJECT_NAME}:: + COMPONENT ${PROJECT_NAME} +) +include(CMakePackageConfigHelpers) +set(BD_INSTALL_BOOT_FILE "${BD_INSTALL_DATADIR}/bdboot.txt") +configure_package_config_file(mk/cmake/${PROJECT_NAME}-config.cmake.in + cmake/${PROJECT_NAME}-config_installed.cmake + INSTALL_DESTINATION "${CONFIG_DIR}" + PATH_VARS BD_INSTALL_BOOT_FILE +) +install(FILES + "${CMAKE_CURRENT_BINARY_DIR}/cmake/${PROJECT_NAME}-config_installed.cmake" + DESTINATION "${CONFIG_DIR}" + RENAME ${PROJECT_NAME}-config.cmake + COMPONENT ${PROJECT_NAME} +) + +# config package for build tree +export(EXPORT ${PROJECT_NAME}_export + FILE cmake/${PROJECT_NAME}-targets.cmake + NAMESPACE ${PROJECT_NAME}:: +) +include(CMakePackageConfigHelpers) +set(PACKAGE_BD_INSTALL_BOOT_FILE "${BD_BOOT_FILE}") +configure_package_config_file(mk/cmake/${PROJECT_NAME}-config.cmake.in + cmake/${PROJECT_NAME}-config.cmake + INSTALL_DESTINATION cmake +) + +# config package for CMAKE_FIND_PACKAGE_REDIRECTS_DIR +configure_file( + mk/cmake/${PROJECT_NAME}-config_redirects.cmake.in + "${CMAKE_FIND_PACKAGE_REDIRECTS_DIR}/${PROJECT_NAME}-config.cmake" + @ONLY +) diff --git a/mk/cmake/bitdht-config.cmake.in b/mk/cmake/bitdht-config.cmake.in new file mode 100644 index 0000000000..a59be4540f --- /dev/null +++ b/mk/cmake/bitdht-config.cmake.in @@ -0,0 +1,27 @@ +# ------------------------------------------------------------------------ *\ +# mk/cmake/bitdht-config.cmake.in +# This file is part of BitDHT +# +# Copyright (C) 2026 David Bears +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . +# ------------------------------------------------------------------------ */ + +@PACKAGE_INIT@ + +include("${CMAKE_CURRENT_LIST_DIR}/bitdht-targets.cmake") + +set_and_check(BD_BOOT_FILE "@PACKAGE_BD_INSTALL_BOOT_FILE@") + +check_required_components("${CMAKE_FIND_PACKAGE_NAME}") diff --git a/mk/cmake/bitdht-config_redirects.cmake.in b/mk/cmake/bitdht-config_redirects.cmake.in new file mode 100644 index 0000000000..c98b631ded --- /dev/null +++ b/mk/cmake/bitdht-config_redirects.cmake.in @@ -0,0 +1,24 @@ +# ------------------------------------------------------------------------ *\ +# mk/cmake/bitdht-config_redirects.cmake.in +# This file is part of BitDHT +# +# Copyright (C) 2026 David Bears +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . +# ------------------------------------------------------------------------ */ + +set(BD_BOOT_FILE "@BD_BOOT_FILE@") + +include("${CMAKE_CURRENT_LIST_DIR}/bitdht-extra.cmake" OPTIONAL) +include("${CMAKE_CURRENT_LIST_DIR}/bitdhtExtra.cmake" OPTIONAL) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt new file mode 100644 index 0000000000..6605fd2350 --- /dev/null +++ b/src/CMakeLists.txt @@ -0,0 +1,28 @@ +# ------------------------------------------------------------------------ *\ +# src/CMakeLists.txt +# This file is part of BitDHT +# +# Copyright (C) 2026 David Bears +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . +# ------------------------------------------------------------------------ */ + +target_sources(${PROJECT_NAME} + PUBLIC FILE_SET HEADERS + BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR} +) + +add_subdirectory(bitdht) +add_subdirectory(udp) +add_subdirectory(util) diff --git a/src/bitdht/CMakeLists.txt b/src/bitdht/CMakeLists.txt new file mode 100644 index 0000000000..190d43a2ac --- /dev/null +++ b/src/bitdht/CMakeLists.txt @@ -0,0 +1,58 @@ +# ------------------------------------------------------------------------ *\ +# src/bitdht/CMakeLists.txt +# This file is part of BitDHT +# +# Copyright (C) 2026 David Bears +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . +# ------------------------------------------------------------------------ */ + +target_sources(${PROJECT_NAME} + PUBLIC FILE_SET HEADERS FILES + bdaccount.h + bdconnection.h + bdfilter.h + bdfriendlist.h + bdhash.h + bdhistory.h + bdiface.h + bdmanager.h + bdmsgs.h + bdnode.h + bdobj.h + bdpeer.h + bdquery.h + bdquerymgr.h + bdstddht.h + bdstore.h + bencode.h + + PRIVATE + bdaccount.cc + bdconnection.cc + bdfilter.cc + bdfriendlist.cc + bdhash.cc + bdhistory.cc + bdmanager.cc + bdmsgs.cc + bdnode.cc + bdobj.cc + bdpeer.cc + bdquery.cc + bdquerymgr.cc + bdstddht.cc + bdstore.cc + bencode.c +) diff --git a/src/udp/CMakeLists.txt b/src/udp/CMakeLists.txt new file mode 100644 index 0000000000..34110dc262 --- /dev/null +++ b/src/udp/CMakeLists.txt @@ -0,0 +1,32 @@ +# ------------------------------------------------------------------------ *\ +# src/udp/CMakeLists.txt +# This file is part of BitDHT +# +# Copyright (C) 2026 David Bears +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . +# ------------------------------------------------------------------------ */ + +target_sources(${PROJECT_NAME} PRIVATE + PUBLIC FILE_SET HEADERS FILES + udpbitdht.h + udplayer.h + udpproxylayer.h + udpstack.h + + PRIVATE + udpbitdht.cc + udplayer.cc + udpstack.cc +) diff --git a/src/util/CMakeLists.txt b/src/util/CMakeLists.txt new file mode 100644 index 0000000000..464cf15827 --- /dev/null +++ b/src/util/CMakeLists.txt @@ -0,0 +1,37 @@ +# ------------------------------------------------------------------------ *\ +# src/util/CMakeLists.txt +# This file is part of BitDHT +# +# Copyright (C) 2026 David Bears +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU Lesser General Public License as +# published by the Free Software Foundation, either version 3 of the +# License, or (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU Affero General Public License for more details. +# +# You should have received a copy of the GNU Lesser General Public License +# along with this program. If not, see . +# ------------------------------------------------------------------------ */ + +target_sources(${PROJECT_NAME} PRIVATE + PUBLIC FILE_SET HEADERS FILES + bdbloom.h + bdfile.h + bdnet.h + bdrandom.h + bdstring.h + bdthreads.h + + PRIVATE + bdbloom.cc + bdfile.cc + bdnet.cc + bdrandom.cc + bdstring.cc + bdthreads.cc +)