-
Notifications
You must be signed in to change notification settings - Fork 37
cmake: Introduce packages #96
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
d9ec22f
cmake: Add `LibmultiprocessMacros` module
hebasto bd2dfe2
cmake, refactor: Use `target_capnp_sources` for `mptest` target
hebasto 66643d8
cmake, refactor: Use `target_capnp_sources` for examples
hebasto 3b20e35
cmake: Configure `Libmultiprocess` package
hebasto 694b6b1
cmake: Configure `LibmultiprocessGen` package
hebasto 4e70ad4
cmake, refactor: Rename target export files
hebasto File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| @PACKAGE_INIT@ | ||
|
|
||
| include(CMakeFindDependencyMacro) | ||
| find_dependency(CapnProto) | ||
|
|
||
| include("${CMAKE_CURRENT_LIST_DIR}/LibmultiprocessTargets.cmake") | ||
|
|
||
| check_required_components(Libmultiprocess) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| @PACKAGE_INIT@ | ||
|
|
||
| include("${CMAKE_CURRENT_LIST_DIR}/LibmultiprocessGenTargets.cmake") | ||
| include("${CMAKE_CURRENT_LIST_DIR}/LibmultiprocessMacros.cmake") | ||
|
|
||
| check_required_components(LibmultiprocessGen) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,94 @@ | ||
| # 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 | ||
| ) | ||
|
|
||
| if(NOT TARGET Libmultiprocess::mpgen) | ||
| message(FATAL_ERROR "Target 'Libmultiprocess::mpgen' does not exist.") | ||
| endif() | ||
|
|
||
| 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 Libmultiprocess::mpgen ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS} | ||
| DEPENDS ${capnp_file} | ||
| VERBATIM | ||
| ) | ||
| 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++ | ||
| ) | ||
| 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}>) | ||
|
|
||
| if(TARGET Libmultiprocess::multiprocess) | ||
| target_link_libraries(${target} PRIVATE Libmultiprocess::multiprocess) | ||
| endif() | ||
| endfunction() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think there may be need to be some additional changes to this file to make the package "relocatable" according to https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#creating-relocatable-packages.
Specifically the PUBLIC include directory
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>on line 84 above and${CAPNP_INCLUDE_DIRECTORY}` on line 85 look like they will add include paths from the build system to the exported targets, and potentially cause problems in some build configurations. This might not be a problem for the bitcoin depends build, though, because it is building everything on one system.Possible fixes to replace the
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>line might be:$<INSTALL_INTERFACE:include>or$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/includeas suggested in https://cmake.org/cmake/help/latest/guide/importing-exporting/index.html#creating-relocatable-packagesINCLUDES DESTINATIONdirective described https://cmake.org/cmake/help/latest/manual/cmake-buildsystem.7.html#include-directories-and-usage-requirements which is apparently "equivalent to appending ${CMAKE_INSTALL_PREFIX}/include"Possible fix to replace the
${CAPNP_INCLUDE_DIRECTORY}line might be to changetarget_link_libraries(multiprocess PRIVATE CapnProto::capnp)fromPRIVATEtoPUBLIC, assuming that making capnproto a public dependency will cause cmake to propagate the necessary includes.