diff --git a/CMakeLists.txt b/CMakeLists.txt index 035a8e43ab4..c798c2e01f4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -106,6 +106,11 @@ cmake_dependent_option(BUILD_WALLET_TOOL "Build bitcoin-wallet tool." ${BUILD_TE option(WITH_CCACHE "Attempt to use ccache for compiling." ON) +option(WITH_NATPMP "Enable NAT-PMP." OFF) +if(WITH_NATPMP) + find_package(NATPMP MODULE REQUIRED) +endif() + set(configure_warnings) include(CheckPIESupported) @@ -278,6 +283,8 @@ if(ENABLE_WALLET) message(" - descriptor wallets (SQLite) ...... ${WITH_SQLITE}") message(" - legacy wallets (Berkeley DB) ..... ${WITH_BDB}") endif() +message(" port mapping:") +message(" - using NAT-PMP .................... ${WITH_NATPMP}") message("Tests:") message(" test_bitcoin ........................ ${BUILD_TESTS}") message("") diff --git a/cmake/module/FindNATPMP.cmake b/cmake/module/FindNATPMP.cmake new file mode 100644 index 00000000000..930555232bd --- /dev/null +++ b/cmake/module/FindNATPMP.cmake @@ -0,0 +1,32 @@ +# Copyright (c) 2023-present The Bitcoin Core developers +# Distributed under the MIT software license, see the accompanying +# file COPYING or https://opensource.org/license/mit/. + +find_path(NATPMP_INCLUDE_DIR + NAMES natpmp.h +) + +find_library(NATPMP_LIBRARY + NAMES natpmp +) + +include(FindPackageHandleStandardArgs) +find_package_handle_standard_args(NATPMP + REQUIRED_VARS NATPMP_LIBRARY NATPMP_INCLUDE_DIR +) + +if(NATPMP_FOUND AND NOT TARGET NATPMP::NATPMP) + add_library(NATPMP::NATPMP UNKNOWN IMPORTED) + set_target_properties(NATPMP::NATPMP PROPERTIES + IMPORTED_LOCATION "${NATPMP_LIBRARY}" + INTERFACE_INCLUDE_DIRECTORIES "${NATPMP_INCLUDE_DIR}" + ) + set_property(TARGET NATPMP::NATPMP PROPERTY + INTERFACE_COMPILE_DEFINITIONS USE_NATPMP=1 $<$:NATPMP_STATICLIB> + ) +endif() + +mark_as_advanced( + NATPMP_INCLUDE_DIR + NATPMP_LIBRARY +) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index feac9c4b0c7..75eb01400c4 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -268,6 +268,7 @@ target_link_libraries(bitcoin_node Boost::headers $ $ + $ )