Skip to content
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

build: add option for external mpgen binary #142

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

theuni
Copy link
Contributor

@theuni theuni commented Jan 31, 2025

The parent project or user can supply EXTERNAL_MPGEN, which will override the one set here. If not set, the internally built one is used instead.

This is useful for cross builds, especially when using libmultiprocess as a subdirectory. Parent projects can similarly define a cache var.

Note that the internal binary is still built, but it can be skipped by building the multiprocess target directly.

This is the simplest impl of this I could come up with. Trying to pass an optional option for the binary into target_capnp_sources is not very ergonomic with CMake, so I've opted for just using a global here instead.

It would probably make sense to disable the internal mpgen target if the external option is used, but that adds a good bit of complexity, so I haven't done it here. Happy to do it as a follow-up if desired.

This is useful for cross builds.

Note that the internal binary is still built, but it can be skipped by building
the multiprocess target directly.
@theuni
Copy link
Contributor Author

theuni commented Jan 31, 2025

Now that #140 has been merged, after this and #141 (or some solution for that problem), we can enable an in-tree built for libmultiprocess with no need for the target build in depends.

Copy link
Collaborator

@ryanofsky ryanofsky left a comment

Choose a reason for hiding this comment

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

Code review ACK 75cf04a Looks great!

I will probably merge this Monday unless it would help to have it merged sooner, in case @hebasto has feedback.

I think it is good that specifying EXTERNAL_MPGEN does not remove the mpgen build target. But if it is being built unnecessarily (doesn't seem like it is) that would be good to fix. In general I don't like options that enable and disable build targets (see #74), and think all targets that can be built should be available, built when needed, and not built when not needed. Defining targets conditionally turns cmakelists files into spaghetti and makes them more difficult to maintain, and harder to understand and use.

@ryanofsky
Copy link
Collaborator

ryanofsky commented Jan 31, 2025

I can also update the depends build in bitcoin/bitcoin#31741 to use this if you didn't already do that. (EDIT: nvm I see you have a branch already)

Copy link
Contributor

@hebasto hebasto left a comment

Choose a reason for hiding this comment

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

Approach ACK 75cf04a.

@@ -22,6 +22,8 @@ if(Libmultiprocess_ENABLE_CLANG_TIDY)
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}")
endif()

set(EXTERNAL_MPGEN "" CACHE STRING "Use the supplied mpgen binary rather than the one built internally")
Copy link
Contributor

Choose a reason for hiding this comment

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

  1. The value of EXTERNAL_MPGEN must be a full path to satisfy the if(EXIST...) condition. Why not make this more explicit by using the FILEPATH type and mentioning in the help string?

  2. As a user-facing cache variable, it should have a library-specific prefix, like this one:

    option(Libmultiprocess_ENABLE_CLANG_TIDY "Run clang-tidy with the compiler." OFF)

  3. style nit: A full stop at the end of the help string?

message(FATAL_ERROR "EXTERNAL_MPGEN: \"${MPGEN_BINARY}\" does not exist.")
endif()
elseif(TARGET Libmultiprocess::multiprocess)
set(MPGEN_BINARY $<TARGET_FILE:Libmultiprocess::mpgen>)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm fairly certain that a generation expression isn't necessary here:

Suggested change
set(MPGEN_BINARY $<TARGET_FILE:Libmultiprocess::mpgen>)
set(MPGEN_BINARY Libmultiprocess::mpgen)

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.

3 participants