mirror of
https://github.com/bitcoin/bitcoin.git
synced 2026-06-04 18:22:57 +02:00
Squashed 'src/ipc/libmultiprocess/' content from commit 35944ffd23fa
git-subtree-dir: src/ipc/libmultiprocess git-subtree-split: 35944ffd23fa26652b82210351d50e896ce16c8f
This commit is contained in:
33
cmake/Config.cmake.in
Normal file
33
cmake/Config.cmake.in
Normal file
@@ -0,0 +1,33 @@
|
||||
@PACKAGE_INIT@
|
||||
|
||||
# CMake find_package compatible package file, for downstream CMake projects
|
||||
#
|
||||
# Based on https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#adding-components
|
||||
|
||||
set(_Libmultiprocess_supported_components Bin Lib)
|
||||
|
||||
# If no components specified, include all components.
|
||||
list(LENGTH ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS_len)
|
||||
if(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS_len EQUAL 0)
|
||||
set(${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS ${_Libmultiprocess_supported_components})
|
||||
endif()
|
||||
|
||||
if ("Bin" IN_LIST ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/TargetCapnpSources.cmake")
|
||||
endif()
|
||||
|
||||
if ("Lib" IN_LIST ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
|
||||
# Setting FOUND_LIBATOMIC is needed on debian & ubuntu systems to work around bug in
|
||||
# their capnproto packages. See compat_find.cmake for a more complete explanation.
|
||||
set(FOUND_LIBATOMIC TRUE)
|
||||
include(CMakeFindDependencyMacro)
|
||||
find_dependency(CapnProto)
|
||||
endif()
|
||||
|
||||
foreach(_comp ${${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS})
|
||||
if (NOT _comp IN_LIST _Libmultiprocess_supported_components)
|
||||
set(${CMAKE_FIND_PACKAGE_NAME}_FOUND False)
|
||||
set(${CMAKE_FIND_PACKAGE_NAME}_NOT_FOUND_MESSAGE "Unsupported component: ${_comp}")
|
||||
endif()
|
||||
include("${CMAKE_CURRENT_LIST_DIR}/${_comp}Targets.cmake")
|
||||
endforeach()
|
||||
113
cmake/TargetCapnpSources.cmake
Normal file
113
cmake/TargetCapnpSources.cmake
Normal file
@@ -0,0 +1,113 @@
|
||||
# Copyright (c) 2024-present The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or https://opensource.org/license/mit/.
|
||||
|
||||
#[=[
|
||||
|
||||
target_capnp_sources
|
||||
--------------------
|
||||
|
||||
This function adds build steps to generate C++ files from Cap'n Proto files
|
||||
and build them as part of a specified target.
|
||||
|
||||
Arguments:
|
||||
|
||||
target: The name of the CMake target (e.g., a library or executable) to
|
||||
which the generated source files will be added. This target must already
|
||||
be defined elsewhere in the CMake scripts.
|
||||
|
||||
include_prefix: Absolute path indicating what portion of capnp source paths
|
||||
should be used in relative #include statements in the generated C++
|
||||
files. For example, if the .capnp path is /home/src/lib/schema.capnp
|
||||
and include_prefix is /home/src, generated includes look like:
|
||||
|
||||
#include <lib/schema.capnp.h>
|
||||
|
||||
And if include_prefix is /home/src/lib, generated includes look like:
|
||||
|
||||
#include <schema.capnp.h>
|
||||
|
||||
The specified include_prefix should be ${CMAKE_SOURCE_DIR} or a
|
||||
subdirectory of it to include files relative to the project root. It can
|
||||
be ${CMAKE_CURRENT_SOURCE_DIR} to include files relative to the current
|
||||
source directory.
|
||||
|
||||
Additional Unnamed Arguments:
|
||||
|
||||
After `target` and `include_prefix`, all unnamed arguments are treated as
|
||||
paths to `.capnp` schema files. These should be paths relative to
|
||||
${CMAKE_CURRENT_SOURCE_DIR}.
|
||||
|
||||
Optional Keyword Arguments:
|
||||
|
||||
IMPORT_PATHS: Specifies additional directories to search for imported
|
||||
`.capnp` files.
|
||||
|
||||
Example:
|
||||
# Assuming `my_library` is a target and `lib/` contains `.capnp` schema
|
||||
# files with imports from `include/`.
|
||||
target_capnp_sources(my_library "${CMAKE_SOURCE_DIR}"
|
||||
lib/schema1.capnp lib/schema2.capnp
|
||||
IMPORT_PATHS ${CMAKE_SOURCE_DIR}/include)
|
||||
|
||||
#]=]
|
||||
|
||||
function(target_capnp_sources target include_prefix)
|
||||
cmake_parse_arguments(PARSE_ARGV 2
|
||||
"TCS" # prefix
|
||||
"" # options
|
||||
"" # one_value_keywords
|
||||
"IMPORT_PATHS" # multi_value_keywords
|
||||
)
|
||||
|
||||
set(MPGEN_BINARY "")
|
||||
if(MPGEN_EXECUTABLE)
|
||||
set(MPGEN_BINARY "${MPGEN_EXECUTABLE}")
|
||||
if(NOT EXISTS "${MPGEN_BINARY}")
|
||||
message(FATAL_ERROR "MPGEN_EXECUTABLE: \"${MPGEN_BINARY}\" does not exist.")
|
||||
endif()
|
||||
elseif(TARGET Libmultiprocess::multiprocess)
|
||||
set(MPGEN_BINARY Libmultiprocess::mpgen)
|
||||
else()
|
||||
message(FATAL_ERROR "No usable mpgen. Set MPGEN_EXECUTABLE or enable the internal target.")
|
||||
endif()
|
||||
|
||||
get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)
|
||||
set(generated_headers "")
|
||||
foreach(capnp_file IN LISTS TCS_UNPARSED_ARGUMENTS)
|
||||
add_custom_command(
|
||||
OUTPUT ${capnp_file}.c++ ${capnp_file}.h ${capnp_file}.proxy-client.c++ ${capnp_file}.proxy-types.h ${capnp_file}.proxy-server.c++ ${capnp_file}.proxy-types.c++ ${capnp_file}.proxy.h
|
||||
COMMAND ${MPGEN_BINARY} ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS} ${mp_include_dir}
|
||||
DEPENDS ${capnp_file}
|
||||
VERBATIM
|
||||
)
|
||||
target_sources(${target} PRIVATE
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.c++
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-client.c++
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-server.c++
|
||||
${CMAKE_CURRENT_BINARY_DIR}/${capnp_file}.proxy-types.c++
|
||||
)
|
||||
|
||||
list(APPEND generated_headers ${capnp_file}.h)
|
||||
endforeach()
|
||||
|
||||
# Translate include_prefix from a source path to a binary path and add it as a
|
||||
# target include directory.
|
||||
set(build_include_prefix ${CMAKE_BINARY_DIR})
|
||||
file(RELATIVE_PATH relative_path ${CMAKE_SOURCE_DIR} ${include_prefix})
|
||||
if(relative_path)
|
||||
string(APPEND build_include_prefix "/" "${relative_path}")
|
||||
endif()
|
||||
target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${build_include_prefix}> ${mp_include_dir})
|
||||
|
||||
if(TARGET Libmultiprocess::multiprocess)
|
||||
target_link_libraries(${target} PRIVATE Libmultiprocess::multiprocess)
|
||||
endif()
|
||||
|
||||
# Add a custom target that can be specified as a dependency of c++ targets
|
||||
# that include generated headers. It can be necessary to specify these
|
||||
# dependencies explicitly because while cmake detect dependencies of non
|
||||
# generated files on generated headers, it does not reliably detect
|
||||
# dependencies of generated headers on other generated headers.
|
||||
add_custom_target("${target}_headers" DEPENDS ${generated_headers})
|
||||
endfunction()
|
||||
59
cmake/compat_config.cmake
Normal file
59
cmake/compat_config.cmake
Normal file
@@ -0,0 +1,59 @@
|
||||
# Copyright (c) 2019 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
# compat_config.cmake -- compatibility workarounds meant to be included after
|
||||
# cmake find_package() calls are made, before configuring the ebuild
|
||||
|
||||
# Define capnp_PREFIX if not defined to avoid issue on macos
|
||||
# https://github.com/bitcoin-core/libmultiprocess/issues/26
|
||||
|
||||
if (NOT DEFINED capnp_PREFIX AND DEFINED CAPNP_INCLUDE_DIRS)
|
||||
get_filename_component(capnp_PREFIX "${CAPNP_INCLUDE_DIRS}" DIRECTORY)
|
||||
endif()
|
||||
|
||||
if (NOT DEFINED CAPNPC_OUTPUT_DIR)
|
||||
set(CAPNPC_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
|
||||
endif()
|
||||
|
||||
# CMake target definitions for backwards compatibility with Ubuntu bionic
|
||||
# capnproto 0.6.1 package (https://packages.ubuntu.com/bionic/libcapnp-dev)
|
||||
# https://github.com/bitcoin-core/libmultiprocess/issues/27
|
||||
|
||||
if (NOT DEFINED CAPNP_LIB_CAPNPC AND DEFINED CAPNP_LIB_CAPNP-RPC)
|
||||
string(REPLACE "-rpc" "c" CAPNP_LIB_CAPNPC "${CAPNP_LIB_CAPNP-RPC}")
|
||||
endif()
|
||||
|
||||
if (NOT DEFINED CapnProto_capnpc_IMPORTED_LOCATION AND DEFINED CapnProto_capnp-rpc_IMPORTED_LOCATION)
|
||||
string(REPLACE "-rpc" "c" CapnProto_capnpc_IMPORTED_LOCATION "${CapnProto_capnp-rpc_IMPORTED_LOCATION}")
|
||||
endif()
|
||||
|
||||
if (NOT TARGET CapnProto::capnp AND DEFINED CAPNP_LIB_CAPNP)
|
||||
add_library(CapnProto::capnp SHARED IMPORTED)
|
||||
set_target_properties(CapnProto::capnp PROPERTIES IMPORTED_LOCATION "${CAPNP_LIB_CAPNP}")
|
||||
endif()
|
||||
|
||||
if (NOT TARGET CapnProto::capnpc AND DEFINED CAPNP_LIB_CAPNPC)
|
||||
add_library(CapnProto::capnpc SHARED IMPORTED)
|
||||
set_target_properties(CapnProto::capnpc PROPERTIES IMPORTED_LOCATION "${CAPNP_LIB_CAPNPC}")
|
||||
endif()
|
||||
|
||||
if (NOT TARGET CapnProto::capnpc AND DEFINED CapnProto_capnpc_IMPORTED_LOCATION)
|
||||
add_library(CapnProto::capnpc SHARED IMPORTED)
|
||||
set_target_properties(CapnProto::capnpc PROPERTIES IMPORTED_LOCATION "${CapnProto_capnpc_IMPORTED_LOCATION}")
|
||||
endif()
|
||||
|
||||
if (NOT TARGET CapnProto::capnp-rpc AND DEFINED CAPNP_LIB_CAPNP-RPC)
|
||||
add_library(CapnProto::capnp-rpc SHARED IMPORTED)
|
||||
set_target_properties(CapnProto::capnp-rpc PROPERTIES IMPORTED_LOCATION "${CAPNP_LIB_CAPNP-RPC}")
|
||||
endif()
|
||||
|
||||
if (NOT TARGET CapnProto::kj AND DEFINED CAPNP_LIB_KJ)
|
||||
add_library(CapnProto::kj SHARED IMPORTED)
|
||||
set_target_properties(CapnProto::kj PROPERTIES IMPORTED_LOCATION "${CAPNP_LIB_KJ}")
|
||||
endif()
|
||||
|
||||
if (NOT TARGET CapnProto::kj-async AND DEFINED CAPNP_LIB_KJ-ASYNC)
|
||||
add_library(CapnProto::kj-async SHARED IMPORTED)
|
||||
set_target_properties(CapnProto::kj-async PROPERTIES IMPORTED_LOCATION "${CAPNP_LIB_KJ-ASYNC}")
|
||||
endif()
|
||||
20
cmake/compat_find.cmake
Normal file
20
cmake/compat_find.cmake
Normal file
@@ -0,0 +1,20 @@
|
||||
# Copyright (c) 2024 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
# compat_find.cmake -- compatibility workarounds meant to be included before
|
||||
# cmake find_package() calls are made
|
||||
|
||||
# Set FOUND_LIBATOMIC to work around bug in debian capnproto package that is
|
||||
# debian-specific and does not happpen upstream. Debian includes a patch
|
||||
# https://sources.debian.org/patches/capnproto/1.0.1-4/07_libatomic.patch/ which
|
||||
# uses check_library_exists(atomic __atomic_load_8 ...) and it fails because the
|
||||
# symbol name conflicts with a compiler instrinsic as described
|
||||
# https://github.com/bitcoin-core/libmultiprocess/issues/68#issuecomment-1135150171.
|
||||
# This could be fixed by improving the check_library_exists function as
|
||||
# described in the github comment, or by changing the debian patch to check for
|
||||
# the symbol a different way, but simplest thing to do is work around the
|
||||
# problem by setting FOUND_LIBATOMIC. This problem has probably not
|
||||
# been noticed upstream because it only affects CMake packages depending on
|
||||
# capnproto, not autoconf packages.
|
||||
set(FOUND_LIBATOMIC TRUE)
|
||||
41
cmake/pthread_checks.cmake
Normal file
41
cmake/pthread_checks.cmake
Normal file
@@ -0,0 +1,41 @@
|
||||
# Copyright (c) 2024 The Bitcoin Core developers
|
||||
# Distributed under the MIT software license, see the accompanying
|
||||
# file COPYING or http://www.opensource.org/licenses/mit-license.php.
|
||||
|
||||
# Define HAVE_PTHREAD_* variables depending on what pthread functions are
|
||||
# available.
|
||||
|
||||
include(CMakePushCheckState)
|
||||
include(CheckCXXSourceCompiles)
|
||||
|
||||
cmake_push_check_state()
|
||||
set(CMAKE_REQUIRED_LIBRARIES Threads::Threads)
|
||||
check_cxx_source_compiles("
|
||||
#include <pthread.h>
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
char thread_name[16];
|
||||
return pthread_getname_np(pthread_self(), thread_name, sizeof(thread_name));
|
||||
}"
|
||||
HAVE_PTHREAD_GETNAME_NP)
|
||||
|
||||
check_cxx_source_compiles("
|
||||
#include <cstdint>
|
||||
#include <pthread.h>
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
uint64_t tid;
|
||||
pthread_threadid_np(NULL, &tid);
|
||||
return 0;
|
||||
}"
|
||||
HAVE_PTHREAD_THREADID_NP)
|
||||
|
||||
check_cxx_source_compiles("
|
||||
#include <pthread.h>
|
||||
#include <pthread_np.h>
|
||||
int main(int argc, char** argv)
|
||||
{
|
||||
return pthread_getthreadid_np();
|
||||
}"
|
||||
HAVE_PTHREAD_GETTHREADID_NP)
|
||||
cmake_pop_check_state()
|
||||
Reference in New Issue
Block a user