From 620f297f311718f3d186b716676779e046e3255c Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Wed, 3 Jun 2026 17:04:59 -0400 Subject: [PATCH 1/2] cmake: make target_capnp_sources use CURRENT dirs TargetCapnpSources.cmake computed the build-side include directory by computing file(RELATIVE_PATH) from CMAKE_SOURCE_DIR to include_prefix and appending the result to CMAKE_BINARY_DIR. This assumes include_prefix is inside CMAKE_SOURCE_DIR, which holds when master is the top-level cmake project but breaks when it is added as a subdirectory of an external project (e.g. the support branch) whose source root is elsewhere. In that case the relative path contains ".." and the resulting build_include_prefix points to a nonexistent directory instead of CMAKE_CURRENT_BINARY_DIR where the generated headers actually live. Fix by anchoring on CMAKE_CURRENT_SOURCE_DIR / CMAKE_CURRENT_BINARY_DIR instead of the top-level CMAKE_SOURCE_DIR/BINARY_DIR. Since cmake mirrors source-tree structure into the binary tree, the mapping is equivalent for any include_prefix inside CMAKE_SOURCE_DIR, and correct for paths outside it. Also update docstring and example to use CMAKE_CURRENT_SOURCE_DIR. Co-Authored-By: Claude Sonnet 4.6 --- cmake/TargetCapnpSources.cmake | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/cmake/TargetCapnpSources.cmake b/cmake/TargetCapnpSources.cmake index abcca70f..fe4bca9a 100644 --- a/cmake/TargetCapnpSources.cmake +++ b/cmake/TargetCapnpSources.cmake @@ -27,10 +27,8 @@ Arguments: #include - 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. + Pass ${CMAKE_CURRENT_SOURCE_DIR} or a subdirectory of it to include files + relative to the current source directory (the typical usage). Additional Unnamed Arguments: @@ -46,9 +44,9 @@ Optional Keyword Arguments: 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}" + target_capnp_sources(my_library "${CMAKE_CURRENT_SOURCE_DIR}" lib/schema1.capnp lib/schema2.capnp - IMPORT_PATHS ${CMAKE_SOURCE_DIR}/include) + IMPORT_PATHS ${CMAKE_CURRENT_SOURCE_DIR}/include) #]=] @@ -98,8 +96,8 @@ function(target_capnp_sources target include_prefix) # 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}) + set(build_include_prefix ${CMAKE_CURRENT_BINARY_DIR}) + file(RELATIVE_PATH relative_path ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix}) if(relative_path) string(APPEND build_include_prefix "/" "${relative_path}") endif() From 615a94fe3a213380eb50cde82e4b4d718bf63dd5 Mon Sep 17 00:00:00 2001 From: Ryan Ofsky Date: Thu, 4 Jun 2026 14:49:18 -0400 Subject: [PATCH 2/2] cmake: document ONLY_CAPNP option in target_capnp_sources The ONLY_CAPNP keyword was parsed but not mentioned in the function's docstring. Add a description explaining what it does and when to use it. Suggested by hebasto in https://github.com/bitcoin-core/libmultiprocess/pull/289#pullrequestreview-4427856835 Co-Authored-By: Claude Sonnet 4.6 --- cmake/TargetCapnpSources.cmake | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/cmake/TargetCapnpSources.cmake b/cmake/TargetCapnpSources.cmake index fe4bca9a..f04a9657 100644 --- a/cmake/TargetCapnpSources.cmake +++ b/cmake/TargetCapnpSources.cmake @@ -41,6 +41,13 @@ Optional Keyword Arguments: IMPORT_PATHS: Specifies additional directories to search for imported `.capnp` files. + ONLY_CAPNP: If specified, only the Cap'n Proto serialization files + (`.capnp.h`, `.capnp.c++`) are generated and compiled. The mpgen proxy + files (`.capnp.proxy-client.c++`, `.capnp.proxy-server.c++`, + `.capnp.proxy-types.c++`, etc.) are skipped. Useful when you need + Cap'n Proto serialization without the multiprocess RPC proxy + infrastructure. + Example: # Assuming `my_library` is a target and `lib/` contains `.capnp` schema # files with imports from `include/`.