Skip to content

cmake: Pass installed include dir to mpgen - #375

Open
VijayabaskarR-06 wants to merge 1 commit into
bitcoin-core:masterfrom
VijayabaskarR-06:fix-install-prefix
Open

VijayabaskarR-06 wants to merge 1 commit into
bitcoin-core:masterfrom
VijayabaskarR-06:fix-install-prefix

Conversation

@VijayabaskarR-06

Copy link
Copy Markdown

Fixes #134.

mpgen was looking for proxy.capnp using the path from when libmultiprocess was built. If the library was installed with a different prefix then the downstream builds failed with Import failed: /mp/proxy.capnp.

This change passes the installed include path from Libmultiprocess::mpgen to mpgen so it can find the file after installation.

Subdirectory builds and builds using MPGEN_EXECUTABLE are unchanged.

I tested this with Bitcoin Core's bitcoin_ipc target. It works with this change and also compared it with main !

mpgen finds /mp/proxy.capnp using the CMAKE_INSTALL_PREFIX that was set
when it was built. If libmultiprocess is installed somewhere else, for
example with `cmake --install build --prefix ~/.local`, or the install is
moved, code generation fails with "Import failed: /mp/proxy.capnp".

When target_capnp_sources uses the imported Libmultiprocess::mpgen
target, pass its include directory to mpgen as an import path. That path
comes from the installed package location, so it is correct wherever
the package ends up. Builds that use libmultiprocess as a subdirectory
already pass MP_INCLUDE_DIR and are unchanged.

Fixes bitcoin-core#134
@DrahtBot

DrahtBot commented Oct 7, 2026 •

Copy link
Copy Markdown

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline and AI policy for information on the review process.

Type Reviewers
ACK ryanofsky

If your review is incorrectly listed, please copy-paste <!--meta-tag:bot-skip--> into the comment that the bot should ignore.

@ryanofsky ryanofsky left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK 7239a97. Thanks for the fix! This makes target_capnp_sources work with packages installed with cmake --install --prefix or moved after installing, which was one of the workarounds suggested in #134 (comment).

I'm happy with the current approach, but left a suggestion for an alternative that seems cleaner if it works: setting MP_INCLUDE_DIR in the package config, so target_capnp_sources doesn't need a special case. Also left a suggested code comment and a question about whether #134 should stay open. All non-blocking.

Comment on lines 80 to +84
get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)
set(mpgen_import_paths ${mp_include_dir})
if(NOT mp_include_dir AND MPGEN_BINARY STREQUAL "Libmultiprocess::mpgen")
get_property(mpgen_import_paths TARGET Libmultiprocess::mpgen PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
endif()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "cmake: Pass installed include dir to mpgen" (7239a97)

Suggestion (non-blocking): it wasn't obvious to me that an empty MP_INCLUDE_DIR is what identifies an installed package here, so it could be worth a comment. This applies with the current approach; if you switch to the one in the Config.cmake.in comment, a similar comment next to where MP_INCLUDE_DIR is set would still help:

Suggested change
get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)
set(mpgen_import_paths ${mp_include_dir})
if(NOT mp_include_dir AND MPGEN_BINARY STREQUAL "Libmultiprocess::mpgen")
get_property(mpgen_import_paths TARGET Libmultiprocess::mpgen PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
endif()
get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)
# MP_INCLUDE_DIR is only set when libmultiprocess is built from source in
# the same project. If it is empty, libmultiprocess is an installed package,
# so pass the include directory of the imported mpgen target. Otherwise
# mpgen would only search the include path compiled into it, which is wrong
# if the package was installed with a different --prefix or moved (#134).
set(mpgen_import_paths ${mp_include_dir})
if(NOT mp_include_dir AND MPGEN_BINARY STREQUAL "Libmultiprocess::mpgen")
get_property(mpgen_import_paths TARGET Libmultiprocess::mpgen PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
endif()

@@ -78,11 +78,15 @@ function(target_capnp_sources target include_prefix)
endif()

get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "cmake: Pass installed include dir to mpgen" (7239a97)

I'm ok with the current approach, but an alternative that seems cleaner if it works would be for the package config to set MP_INCLUDE_DIR itself. Then MP_INCLUDE_DIR would always be the directory containing mp/proxy.capnp, the include directory would be worked out where the package is found, and target_capnp_sources wouldn't need a special case for installed packages. Something like this at the end of Config.cmake.in, after the loop that includes the targets files:

if ("Bin" IN_LIST ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
  get_target_property(_mp_include_dir Libmultiprocess::mpgen INTERFACE_INCLUDE_DIRECTORIES)
  set_property(GLOBAL PROPERTY MP_INCLUDE_DIR "${_mp_include_dir}")
endif()

(or PATH_VARS CMAKE_INSTALL_INCLUDEDIR in configure_package_config_file and @PACKAGE_CMAKE_INSTALL_INCLUDEDIR@). It needs to be conditional on Bin, not Lib, because Bitcoin Core cross builds find the two components in different prefixes and proxy.capnp is installed with Bin. I haven't tried this, so there may be a reason it doesn't work, in which case the current approach is fine.

get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)
set(mpgen_import_paths ${mp_include_dir})
if(NOT mp_include_dir AND MPGEN_BINARY STREQUAL "Libmultiprocess::mpgen")
get_property(mpgen_import_paths TARGET Libmultiprocess::mpgen PROPERTY INTERFACE_INCLUDE_DIRECTORIES)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "cmake: Pass installed include dir to mpgen" (7239a97)

Note for reviewers: for the imported target this property comes from $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>, which the exported targets file makes relative to the package location, and proxy.capnp is installed to ${CMAKE_INSTALL_INCLUDEDIR}/mp in the same component. So the path always contains the file mpgen needs. It is also better than the compiled-in path when CMAKE_INSTALL_INCLUDEDIR isn't include, because mpgen hardcodes CMAKE_INSTALL_PREFIX "/include". mpgen still appends that compiled-in path after this one, which is harmless.


get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)
set(mpgen_import_paths ${mp_include_dir})
if(NOT mp_include_dir AND MPGEN_BINARY STREQUAL "Libmultiprocess::mpgen")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In commit "cmake: Pass installed include dir to mpgen" (7239a97)

This fixes the case reported in #134, but MPGEN_EXECUTABLE and mpgen.mk users with a relocated install still get the compiled-in path, and the Cap'n Proto include path is still compiled in too. I think that's fine for this PR (the MPGEN_EXECUTABLE case can be worked around with IMPORT_PATHS), but maybe the description could say "Fixes the cmake case of #134" instead of "Fixes #134", so the issue stays open for the rest?

@ryanofsky

Copy link
Copy Markdown
Collaborator

Closing and reopening to get a fresh CI run. The two failing jobs aren't caused by this PR, and GitHub no longer allows re-running them because the runs are more than 30 days old:

  • build • openbsd fails with '__COUNTER__' is a C2y extension [-Werror,-Wc2y-extensions] in every test file that uses KJ_TEST. The OpenBSD VM image moved to OpenBSD 8.0 with Clang 22, which warns about this, and #381 fixed it in the CI config after this run.
  • ASan + UBSan failed during setup, before anything was built, when curl couldn't resolve apt.llvm.org (exit code 6).

@ryanofsky ryanofsky closed this Nov 13, 2026
@ryanofsky ryanofsky reopened this Nov 13, 2026

@hebasto hebasto left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The presence of include/mpgen.mk implies that the project still supports non-CMake integration.

Shouldn't mpgen.mk be adjusted as well?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Installing in ${HOME}/.local causes build error

4 participants