cmake: Pass installed include dir to mpgen #375

pull VijayabaskarR-06 wants to merge 1 commits into bitcoin-core:master from VijayabaskarR-06:fix-install-prefix changing 1 files +5 −1
  1. VijayabaskarR-06 commented at 9:05 AM on October 7, 2026: none

    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 !

  2. cmake: Pass installed include dir to mpgen
    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 #134
    7239a977c3
  3. DrahtBot commented at 9:05 AM on October 7, 2026: none

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--021abf342d371248e50ceaed478a90ca-->

    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 <code>&lt;!--meta-tag:bot-skip--&gt;</code> into the comment that the bot should ignore.

    <!--5faf32d7da4f0f540f40219e4f7537a3-->

  4. in cmake/TargetCapnpSources.cmake:84 in 7239a977c3
      77 | @@ -78,11 +78,15 @@ function(target_capnp_sources target include_prefix)
      78 |    endif()
      79 |  
      80 |    get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)
      81 | +  set(mpgen_import_paths ${mp_include_dir})
      82 | +  if(NOT mp_include_dir AND MPGEN_BINARY STREQUAL "Libmultiprocess::mpgen")
      83 | +    get_property(mpgen_import_paths TARGET Libmultiprocess::mpgen PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
      84 | +  endif()
    


    ryanofsky commented at 4:04 PM on November 3, 2026:

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

    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:

      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()
    
  5. in cmake/TargetCapnpSources.cmake:80 in 7239a977c3
      77 | @@ -78,11 +78,15 @@ function(target_capnp_sources target include_prefix)
      78 |    endif()
      79 |  
      80 |    get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)
    


    ryanofsky commented at 4:04 PM on November 3, 2026:

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

    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.


    ryanofsky commented at 8:45 PM on November 16, 2026:

    re: #375 (review) @VijayabaskarR-06 did you get a chance to look at this? I'm still fine with merging the current approach, but I think setting MP_INCLUDE_DIR in the package config would be cleaner, because MP_INCLUDE_DIR would then mean the same thing in every build and target_capnp_sources wouldn't need a special case for installed packages. If it doesn't work when you try it, or you'd rather keep the current version, that's ok too, just let me know.

  6. in cmake/TargetCapnpSources.cmake:83 in 7239a977c3
      77 | @@ -78,11 +78,15 @@ function(target_capnp_sources target include_prefix)
      78 |    endif()
      79 |  
      80 |    get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)
      81 | +  set(mpgen_import_paths ${mp_include_dir})
      82 | +  if(NOT mp_include_dir AND MPGEN_BINARY STREQUAL "Libmultiprocess::mpgen")
      83 | +    get_property(mpgen_import_paths TARGET Libmultiprocess::mpgen PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
    


    ryanofsky commented at 4:04 PM on November 3, 2026:

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

    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.

  7. in cmake/TargetCapnpSources.cmake:82 in 7239a977c3
      77 | @@ -78,11 +78,15 @@ function(target_capnp_sources target include_prefix)
      78 |    endif()
      79 |  
      80 |    get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)
      81 | +  set(mpgen_import_paths ${mp_include_dir})
      82 | +  if(NOT mp_include_dir AND MPGEN_BINARY STREQUAL "Libmultiprocess::mpgen")
    


    ryanofsky commented at 4:05 PM on November 3, 2026:

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

    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?

  8. ryanofsky approved
  9. ryanofsky commented at 4:21 PM on November 3, 2026: collaborator

    Code review ACK 7239a977c3000a3b075b6dd63a0c508106e7005e. 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.

  10. ryanofsky commented at 3:21 PM on November 13, 2026: 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).
  11. ryanofsky closed this on Nov 13, 2026

  12. ryanofsky reopened this on Nov 13, 2026

  13. hebasto commented at 7:27 PM on November 15, 2026: member

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

    Shouldn't mpgen.mk be adjusted as well?

  14. in cmake/TargetCapnpSources.cmake:89 in 7239a977c3
      85 |    set(generated_headers "")
      86 |    foreach(capnp_file IN LISTS TCS_UNPARSED_ARGUMENTS)
      87 |      add_custom_command(
      88 |        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
      89 | -      COMMAND ${MPGEN_BINARY} ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS} ${mp_include_dir}
      90 | +      COMMAND ${MPGEN_BINARY} ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS} ${mpgen_import_paths}
    


    ryanofsky commented at 8:06 PM on November 16, 2026:

    re: #375#pullrequestreview-5912458021

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

    Shouldn't mpgen.mk be adjusted as well?

    That'd be nice. The bug in #134 is in mpgen, not in cmake, so this PR is a partial workaround for it that could be extended to mpgen.mk. When mpgen isn't given an import path for mp/proxy.capnp, it looks under the install prefix compiled into it, so after cmake --install --prefix or moving the install, any build that runs mpgen fails, whatever build system it uses. #134 was reported through Bitcoin Core's cmake build, and this PR works around it in the cmake helper target_capnp_sources by passing the installed include directory. mpgen.mk is the equivalent helper for Make-based builds and has the same problem. It looks like a one-line fix there: the rule already runs $(MPGEN_PREFIX)/bin/mpgen, so MPGEN_PREFIX has to point at the actual install location, and the rule can pass the include directory under it:

    -	$(AM_V_GEN) $(MPGEN_PREFIX)/bin/mpgen '$(srcdir)' '$(srcdir)' $<
    +	$(AM_V_GEN) $(MPGEN_PREFIX)/bin/mpgen '$(srcdir)' '$(srcdir)' $< '$(MPGEN_PREFIX)/include'
    

    This assumes the include directory is include under the prefix, as the rule already assumes bin. I haven't tested it. @VijayabaskarR-06 it seems fine to add here or in a follow-up, whichever you prefer.

    Separately, since Bitcoin Core's autotools build was removed, mpgen.mk may not have any users left, so it could also be reasonable to drop it in a separate PR.

  15. ryanofsky approved

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin-core/libmultiprocess. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-11-17 18:30 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me