polish CMake-aware installation

This commit is contained in:
David Bears 2026-08-22 13:21:59 -04:00
parent 51aebb6ee3
commit c4b6dceb03
No known key found for this signature in database
GPG Key ID: FB975E12C69F7177
7 changed files with 149 additions and 46 deletions

View File

@ -8,20 +8,17 @@
cmake_minimum_required(VERSION 3.15)
project(bitdht)
if(NOT DEFINED RS_DATA_DIR)
include(GNUInstallDirs)
set(RS_DATA_DIR "${CMAKE_INSTALL_DATADIR}/retroshare")
endif()
include(GNUInstallDirs)
set(BD_INSTALL_DATADIR "${CMAKE_INSTALL_DATADIR}/${PROJECT_NAME}")
set(BD_INSTALL_INCLUDEDIR "${CMAKE_INSTALL_INCLUDEDIR}/${PROJECT_NAME}")
add_library(${PROJECT_NAME})
add_library(${PROJECT_NAME}::${PROJECT_NAME} ALIAS ${PROJECT_NAME})
target_include_directories(
${PROJECT_NAME}
PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/src
)
set(BD_BOOT_FILE "${PROJECT_SOURCE_DIR}/src/bitdht/bdboot.txt")
if(WIN32)
target_compile_definitions(bitdht PRIVATE UNICODE _UNICODE)
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.
@ -29,7 +26,7 @@ if(WIN32)
CMAKE_CXX_COMPILER_ID STREQUAL "GNU" OR
CMAKE_CXX_COMPILER_ID STREQUAL "Clang"
)
target_compile_options(bitdht PRIVATE
target_compile_options(${PROJECT_NAME} PRIVATE
-Wno-error=incompatible-pointer-types
-Wno-error=int-conversion
-Wno-error=implicit-function-declaration
@ -38,18 +35,59 @@ if(WIN32)
endif()
add_library(bitdht:bitdht ALIAS bitdht)
add_subdirectory(src)
# TODO: some things to polish the cmake integration
# - install the library itself to support dynamic linking
# - install headers
# - install a config file
# - create a build-tree config file
# - config version files for install and build trees
### 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
)

View File

@ -0,0 +1,27 @@
# ------------------------------------------------------------------------ *\
# mk/cmake/bitdht-config.cmake.in
# This file is part of BitDHT
#
# Copyright (C) 2026 David Bears <dbear4q@gmail.com>
#
# 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 <https://www.gnu.org/licenses/>.
# ------------------------------------------------------------------------ */
@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}")

View File

@ -0,0 +1,24 @@
# ------------------------------------------------------------------------ *\
# mk/cmake/bitdht-config_redirects.cmake.in
# This file is part of BitDHT
#
# Copyright (C) 2026 David Bears <dbear4q@gmail.com>
#
# 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 <https://www.gnu.org/licenses/>.
# ------------------------------------------------------------------------ */
set(BD_BOOT_FILE "@BD_BOOT_FILE@")
include("${CMAKE_CURRENT_LIST_DIR}/bitdht-extra.cmake" OPTIONAL)
include("${CMAKE_CURRENT_LIST_DIR}/bitdhtExtra.cmake" OPTIONAL)

View File

@ -18,6 +18,11 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# ------------------------------------------------------------------------ */
target_sources(${PROJECT_NAME}
PUBLIC FILE_SET HEADERS
BASE_DIRS ${CMAKE_CURRENT_SOURCE_DIR}
)
add_subdirectory(bitdht)
add_subdirectory(udp)
add_subdirectory(util)

View File

@ -18,38 +18,41 @@
# along with this program. If not, see <https://www.gnu.org/licenses/>.
# ------------------------------------------------------------------------ */
target_sources(${PROJECT_NAME} PRIVATE
bdaccount.cc
target_sources(${PROJECT_NAME}
PUBLIC FILE_SET HEADERS FILES
bdaccount.h
bdconnection.cc
bdconnection.h
bdfilter.cc
bdfilter.h
bdfriendlist.cc
bdfriendlist.h
bdhash.cc
bdhash.h
bdhistory.cc
bdhistory.h
bdiface.h
bdmanager.cc
bdmanager.h
bdmsgs.cc
bdmsgs.h
bdnode.cc
bdnode.h
bdobj.cc
bdobj.h
bdpeer.cc
bdpeer.h
bdquery.cc
bdquery.h
bdquerymgr.cc
bdquerymgr.h
bdstddht.cc
bdstddht.h
bdstore.cc
bdstore.h
bencode.c
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
)

View File

@ -19,11 +19,14 @@
# ------------------------------------------------------------------------ */
target_sources(${PROJECT_NAME} PRIVATE
udpbitdht.cc
PUBLIC FILE_SET HEADERS FILES
udpbitdht.h
udplayer.cc
udplayer.h
udpproxylayer.h
udpstack.cc
udpstack.h
PRIVATE
udpbitdht.cc
udplayer.cc
udpstack.cc
)

View File

@ -19,16 +19,19 @@
# ------------------------------------------------------------------------ */
target_sources(${PROJECT_NAME} PRIVATE
bdbloom.cc
PUBLIC FILE_SET HEADERS FILES
bdbloom.h
bdfile.cc
bdfile.h
bdnet.cc
bdnet.h
bdrandom.cc
bdrandom.h
bdstring.cc
bdstring.h
bdthreads.cc
bdthreads.h
PRIVATE
bdbloom.cc
bdfile.cc
bdnet.cc
bdrandom.cc
bdstring.cc
bdthreads.cc
)