Install Exports for custom `install-{lib,bin}` targets #79

pull hebasto wants to merge 2 commits into bitcoin-core:master from hebasto:220917-export changing 1 files +17 −12
  1. hebasto commented at 8:36 AM on September 17, 2022: member

    This is a follow up of chaincodelabs/libmultiprocess#74 and addresses https://github.com/chaincodelabs/libmultiprocess/pull/74#pullrequestreview-1106150689:

    The only downside of the current implementation is that new install-lib and install-bin targets do not export the underlying targets.

    Can confirm neither of the new install commands create $PREFIX/cmake/Multiprocess/Multiprocess.cmake and $PREFIX/lib/cmake/Multiprocess/Multiprocess-debug.cmake files.

    Probably should update install() EXPORT Multiprocess arguments to EXPORT libmultiprocess-bin and EXPORT libmultiprocess-lib so the two installs can be independent. And maybe there is a way to get the new install-bin and install-lib commands to actually export these targets.

  2. in CMakeLists.txt:85 in 78bfa2a281 outdated
      81 | +install(TARGETS multiprocess EXPORT libmultiprocess-lib
      82 |    ARCHIVE DESTINATION lib COMPONENT lib
      83 |    PUBLIC_HEADER DESTINATION include/mp COMPONENT lib)
      84 |  install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/libmultiprocess.pc"
      85 |    DESTINATION "lib/pkgconfig" COMPONENT lib)
      86 | +install(EXPORT libmultiprocess-lib DESTINATION lib/cmake/Multiprocess)
    


    ryanofsky commented at 7:38 PM on September 19, 2022:

    In commit "Install Exports for custom install-{lib,bin} targets" (78bfa2a2812fe56b172ca4f16e7c332d0e03f103)

    Could you add COMPONENT lib to this command? It looks like that would allow dropping Unspecified install command below.


    ryanofsky commented at 7:47 PM on September 19, 2022:

    In commit "Install Exports for custom install-{lib,bin} targets" (78bfa2a2812fe56b172ca4f16e7c332d0e03f103)

    Could you change lib/cmake/Multiprocess to ${CMAKE_INSTALL_LIBDIR}/cmake?

    I know Multiprocess subdirectory was used before this PR, but I think that directory name is a little misleading because it doesn't match the project name. Also, there is not really a point in creating a subdirectory since this is just exporting targets, not a full cmake package (https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#creating-packages, https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure)


    hebasto commented at 2:12 PM on January 27, 2023:

    Thanks! Updated.


    hebasto commented at 2:14 PM on January 27, 2023:

    Could you change lib/cmake/Multiprocess to ${CMAKE_INSTALL_LIBDIR}/cmake?

    Done in a new "Use GNUInstallDirs module" commit.

    I know Multiprocess subdirectory was used before this PR, but I think that directory name is a little misleading because it doesn't match the project name. Also, there is not really a point in creating a subdirectory since this is just exporting targets, not a full cmake package (https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#creating-packages, https://cmake.org/cmake/help/latest/command/find_package.html#config-mode-search-procedure)

    Thanks! Updated.

  3. in CMakeLists.txt:88 in 78bfa2a281 outdated
      84 |  install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/libmultiprocess.pc"
      85 |    DESTINATION "lib/pkgconfig" COMPONENT lib)
      86 | +install(EXPORT libmultiprocess-lib DESTINATION lib/cmake/Multiprocess)
      87 |  add_custom_target(install-lib
      88 |    COMMAND ${CMAKE_COMMAND} -DCOMPONENT=lib -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
      89 | +  COMMAND ${CMAKE_COMMAND} -DCOMPONENT=Unspecified -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake
    


    ryanofsky commented at 7:48 PM on September 19, 2022:

    In commit "Install Exports for custom install-{lib,bin} targets" (78bfa2a2812fe56b172ca4f16e7c332d0e03f103)

    I think this could be dropped adding COMPONENT lib to install(EXPORT) command above


    hebasto commented at 2:15 PM on January 27, 2023:

    Thanks! Updated.

  4. in CMakeLists.txt:109 in 78bfa2a281 outdated
     105 | +install(TARGETS mpgen EXPORT libmultiprocess-bin
     106 |    RUNTIME DESTINATION bin COMPONENT bin
     107 |    PUBLIC_HEADER DESTINATION include/mp COMPONENT bin)
     108 |  install(FILES "include/mpgen.mk"
     109 |    DESTINATION "include" COMPONENT bin)
     110 | +install(EXPORT libmultiprocess-bin DESTINATION lib/cmake/Multiprocess)
    


    ryanofsky commented at 7:49 PM on September 19, 2022:

    In commit "Install Exports for custom install-{lib,bin} targets" (78bfa2a2812fe56b172ca4f16e7c332d0e03f103)

    Similar to above, could you add COMPONENT bin and change DESTINATION lib/cmake/Multiprocess to DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake?


    hebasto commented at 2:15 PM on January 27, 2023:

    Thanks! Updated.

  5. ryanofsky approved
  6. ryanofsky commented at 8:02 PM on September 19, 2022: collaborator

    Thanks for following up. I think PR is an improvement over status quo, but I suggested a few tweaks that might make it better.

    Additionally, it could be good to add NAMESPACE Libmultiprocess:: to install commands to scope exported targets under the cmake project name.

    Later, it might also be good to turn the install into a full cmake package (https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#creating-a-package-configuration-file) so if a bitcoin cmake build is added, it could use find_package instead of include and take advantage of cmake package detection & versioning features.

  7. Use `GNUInstallDirs` module 54bd57fb3b
  8. hebasto force-pushed on Jan 27, 2023
  9. hebasto commented at 2:12 PM on January 27, 2023: member

    Updated 78bfa2a2812fe56b172ca4f16e7c332d0e03f103 -> d795e969dd7c913c937a4f97d78115072feb6cb4 (pr79.01 -> pr79.02):

  10. hebasto force-pushed on Jan 27, 2023
  11. hebasto commented at 3:41 PM on January 27, 2023: member

    Additionally, it could be good to add NAMESPACE Libmultiprocess:: to install commands to scope exported targets under the cmake project name.

    Done.

  12. hebasto commented at 4:14 PM on January 28, 2023: member

    Later, it might also be good to turn the install into a full cmake package (https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#creating-a-package-configuration-file) so if a bitcoin cmake build is added, it could use find_package instead of include and take advantage of cmake package detection & versioning features.

    FWIW, here is a branch with a proof of concept -- https://github.com/hebasto/libmultiprocess/commits/230128-export.DEMO.

    And here is its use case -- https://github.com/hebasto/bitcoin/commits/230128-cmake.MP.DEMO.

    The problem to be solved is the handling of all dependencies (capnp, kj etc) via config files...

  13. ryanofsky commented at 7:46 PM on February 14, 2023: collaborator

    Reviewed dae3ff8827e4803f601c764ac4664815b14251b9 and confirmed that install-bin and install-lib now lib/cmake/libmultiprocess-bin.cmake and lib/cmake/libmultiprocess-bin.cmake files respectively, containing exported targets from the project. The only thing I think it would be good to do still is make the target namespace name libmultiprocess the same as the cmake project name Libmultiprocess.

  14. Install Exports for custom `install-{lib,bin}` targets 2dda7536b5
  15. in CMakeLists.txt:88 in dae3ff8827 outdated
      84 |    ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib
      85 |    PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mp COMPONENT lib)
      86 |  install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/libmultiprocess.pc"
      87 |    DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT lib)
      88 | +install(EXPORT libmultiprocess-lib
      89 | +  NAMESPACE libmultiprocess::
    


    ryanofsky commented at 7:49 PM on February 14, 2023:

    In commit "Install Exports for custom install-{lib,bin} targets" (dae3ff8827e4803f601c764ac4664815b14251b9)

    Could you change NAMESPACE libmultiprocess:: to NAMESPACE Libmultiprocess:: here and below? Seems better not to use different namespace and project names unnecessarily, and from https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html, it seems like the convention for both is to use uppercase


    hebasto commented at 8:00 PM on February 14, 2023:

    Thanks! Updated.

  16. hebasto force-pushed on Feb 14, 2023
  17. hebasto commented at 7:59 PM on February 14, 2023: member

    Updated dae3ff8827e4803f601c764ac4664815b14251b9 -> 2dda7536b5f4192de0fc06c16157f1ad90f5d762 (pr79.03 -> pr79.04, diff):

  18. ryanofsky approved
  19. ryanofsky commented at 8:43 PM on February 14, 2023: collaborator

    Code review ACK 2dda7536b5f4192de0fc06c16157f1ad90f5d762. Only change since last review is changing namespace prefix to match project name as suggested (thanks!)

  20. ryanofsky merged this on Feb 14, 2023
  21. ryanofsky closed this on Feb 14, 2023

  22. hebasto deleted the branch on Feb 15, 2023
  23. in CMakeLists.txt:86 in 54bd57fb3b outdated
      84 | -  PUBLIC_HEADER DESTINATION include/mp COMPONENT lib)
      85 | +  ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib
      86 | +  PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mp COMPONENT lib)
      87 |  install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/libmultiprocess.pc"
      88 | -  DESTINATION "lib/pkgconfig" COMPONENT lib)
      89 | +  DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT lib)
    


    ryanofsky commented at 11:18 AM on November 20, 2023:

    In commit "Use GNUInstallDirs module" (54bd57fb3b064c7f3d556b015e8f64fd8d234c19)

    I think this change is right, but it did seem to cause a problem with a depends build that fanquake is fixing in https://github.com/bitcoin/bitcoin/pull/28846 commit https://github.com/bitcoin/bitcoin/pull/28846/commits/156366f10aa38c612e26a1f93d8503786f3d3a34

    On fedora, replacing lib with ${CMAKE_INSTALL_LIBDIR} here causes the pkgconfig file to be installed in lib64/ instead of lib/, which seems right and makes sense according to explanations given https://cmake.org/cmake/help/latest/module/GNUInstallDirs.html and https://github.com/Kitware/CMake/blob/master/Modules/GNUInstallDirs.cmake

    But this is incompatible with the depends build that hardcodes the lib/ directory: https://github.com/bitcoin/bitcoin/blob/d752349029ec7a76f1fd440db2ec2e458d0f3c99/depends/config.site.in#L91, so hardcoding lib again in https://github.com/bitcoin/bitcoin/pull/28846 is needed after this change.


    hebasto commented at 2:52 PM on November 20, 2023:

    Right. The current Bitcoin Core depends build system will handle any other package built and installed with CMake in this flawed way. A generic fix for it looks quite reasonable.


    ryanofsky commented at 3:05 PM on November 20, 2023:

    Right. The current Bitcoin Core depends build system will handle any other package built and installed with CMake in this flawed way.

    The depends system definitely has a bug because it will install the library in "lib64" on some platforms, but look for it in "lib" regardless of the platform. But the approach isn't really flawed, is it? It seems reasonable for the depends system to just always install the library in "lib" and always look for it there.


    hebasto commented at 3:21 PM on November 20, 2023:

    I'm fine with either approach. But in the light of the upcoming migration from Autotools to CMake, the forced installation to the lib subdirectory looks useless.

  24. fanquake referenced this in commit 68823aa3c0 on Dec 4, 2023
  25. fanquake referenced this in commit 1a90ac42e2 on Dec 4, 2023
  26. fanquake referenced this in commit 6293a3f5a2 on Dec 5, 2023
  27. fanquake referenced this in commit 506634d79d on Dec 12, 2023
  28. fanquake referenced this in commit 54f6756e52 on Dec 13, 2023
  29. ryanofsky referenced this in commit 0f9605b026 on Jan 11, 2024
  30. ryanofsky commented at 7:06 PM on January 11, 2024: collaborator

    Just to follow up, it turns out this change caused two regressions:

    1 - A problem in the bitcoin core "depends" build when the bitcoin core autoconf script could not find the libmultiprocess.pc file because it was installed to "lib64" not "lib" (https://github.com/chaincodelabs/libmultiprocess/pull/79#discussion_r1399049836). This was fixed in depends in https://github.com/bitcoin/bitcoin/pull/28846.

    2 - A second problem fixed in #90 where the libmultiprocess.pc points to "lib" not 'lib64" resulting in link errors when the libmultiprocess libary is installed in "lib64" and can't be found. The fix for the previous problem masked this issue in the depends build by making the depends build always install to "lib." But outside of the depends build, link errors could still happen. #90 fixes the problem by updating libmultiprocess.pc to point to the correct location.

  31. ryanofsky referenced this in commit 2cbbd09d8b on Jan 11, 2024
  32. janus referenced this in commit 7fdb87163a on Apr 6, 2024
  33. PastaPastaPasta referenced this in commit 3b9b711672 on Oct 3, 2024
  34. PastaPastaPasta referenced this in commit 8fa4d81209 on Oct 3, 2024
  35. PastaPastaPasta referenced this in commit be07bbe87e on Oct 4, 2024
  36. bitcoin-core locked this on Jun 25, 2025
Contributors

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-04-20 19:30 UTC

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