Files
bitcoin/cmake/TargetCapnpSources.cmake
Ryan Ofsky e886c65b6b Squashed 'src/ipc/libmultiprocess/' changes from 27c7e8e5a581..b4120d34bad2
b4120d34bad2 Merge bitcoin-core/libmultiprocess#192: doc: fix typos
6ecbdcd35a93 doc: fix typos
a11e6905c238 Merge bitcoin-core/libmultiprocess#186: Fix mptest failures in bitcoin CI
6f340a583f2b doc: fix DrahtBot LLM Linter error
c6f7fdf17350 type-context: revert client disconnect workaround
e09143d2ea2f proxy-types: fix UndefinedBehaviorSanitizer: null-pointer-use
84b292fcc4db mptest: fix MemorySanitizer: use-of-uninitialized-value
fe4a188803c6 proxy-io: fix race conditions in disconnect callback code
d8011c83608e proxy-io: fix race conditions in ProxyClientBase cleanup handler
97e82ce19c47 doc: Add note about Waiter::m_mutex and interaction with the EventLoop::m_mutex
81d58f5580e8 refactor: Rename ProxyClient cleanup_it variable
07230f259f55 refactor: rename ProxyClient<Thread>::m_cleanup_it
c0efaa5e8cb1 Merge chaincodelabs/libmultiprocess#187: ci: have bash scripts explicitly opt out of locale dependence.
0d986ff144cd mptest: fix race condition in TestSetup constructor
d2f6aa2e84ef ci: add thread sanitizer job
3a6db38e561f ci: rename configs to .bash
401e0ce1d9c3 ci: add copyright to bash scripts
e956467ae464 ci: export LC_ALL
8954cc0377d8 Merge chaincodelabs/libmultiprocess#184: Add CI jobs and fix clang-tidy and iwyu errors
757e13a75546 ci: add gnu32 cross-compiled 32-bit build
15bf349000eb doc: fix typo found by DrahtBot
1a598d5905f7 clang-tidy: drop 'bitcoin-*' check
cbb1e43fdc6e ci: test libc++ instead of libstdc++ in one job
76313450c2c4 type-context: disable clang-tidy UndefinedBinaryOperatorResult error
4896e7fe51ba proxy-types: fix clang-tidy EnumCastOutOfRange error
060a73926956 proxy-types: fix clang-tidy StackAddressEscape error
977d721020f6 ci: add github actions jobs testing gcc, clang-20, clang-tidy, and iwyu
0d5f1faae5da iwyu: fix add/remove include errors
753d2b10cc27 util: fix clang-tidy modernize-use-equals-default error
ae4f1dc2bb1a type-number: fix clang-tidy modernize-use-nullptr error
07a741bf6946 proxy-types: fix clang-tidy bugprone-use-after-move error
3673114bc9d9 proxy-types: fix clang-tidy bugprone-use-after-move error
422923f38485 proxy-types: fix clang-tidy bugprone-use-after-move error
c6784c6adefa mpgen: disable clang-tidy misc-no-recursion error
c5498aa11ba6 tidy: copy clang-tidy file from bitcoin core
258a617c1eec Merge chaincodelabs/libmultiprocess#160: refactor: EventLoop locking cleanups + client disconnect exception
84cf56a0b5f4 test: Test disconnects during IPC calls
949573da8411 Prevent IPC server crash if disconnected during IPC call
019839758085 Merge chaincodelabs/libmultiprocess#179: scripted-diff: Remove copyright year (ranges)
ea38392960e1 Prevent EventLoop async cleanup thread early exit during shutdown
616d9a75d20a doc: Document ProxyClientBase destroy_connection option
56fff76f940b Improve IPC client disconnected exceptions
9b8ed3dc5f87 refactor: Add clang thread safety annotations to EventLoop
52256e730f51 refactor: Remove DestructorCatcher and AsyncCallable
f24894794adf refactor: Drop addClient/removeClient methods
2b830e558e61 refactor: Use EventLoopRef instead of addClient/removeClient
315ff537fb65 refactor: Add ProxyContext EventLoop* member
9aaeec3678d3 proxy-io.h: Add EventLoopRef RAII class handle addClient/removeClient refcounting
f58c8d8ba2f0 proxy-io.h: Add more detailed EventLoop comment
5108445e5d16 test: Add test coverage for client & server disconnections
59030c68cb5f Merge chaincodelabs/libmultiprocess#181: type-function.h: Fix CustomBuildField overload
688140b1dffc test: Add coverage for type-function.h
8b96229da58e type-function.h: Fix CustomBuildField overload
fa2ff9a66842 scripted-diff: Remove copyright year (ranges)

git-subtree-dir: src/ipc/libmultiprocess
git-subtree-split: b4120d34bad2de28141c5770f6e8df8e54898987
2025-08-04 13:38:26 -04:00

116 lines
4.6 KiB
CMake

# 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
)
# Skip linting for capnp-generated files but keep it for mpgen-generated ones
set_source_files_properties(${capnp_file}.c++ PROPERTIES SKIP_LINTING TRUE) # Ignored before cmake 3.27
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()