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

Merged
merged 1 commit into from
Feb 3, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
build: add option for external mpgen binary
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 committed Jan 31, 2025
commit 75cf04a6ed4870d2023f005a9f0a9ef3c81e9996
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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
Member

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:https://github.com/chaincodelabs/libmultiprocess/blob/1e06ff07cdeadc78b2c022750f7b5cbc88d56b1d/CMakeLists.txt#L18

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


include("cmake/compat_config.cmake")
include("cmake/pthread_checks.cmake")
include(GNUInstallDirs)
14 changes: 11 additions & 3 deletions cmake/TargetCapnpSources.cmake
Original file line number Diff line number Diff line change
@@ -60,15 +60,23 @@ function(target_capnp_sources target include_prefix)
"IMPORT_PATHS" # multi_value_keywords
)

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

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)

else()
message(FATAL_ERROR "No usable mpgen. Set EXTERNAL_MPGEN or enable the internal target.")
endif()

set(generated_headers "")
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} ${MP_INCLUDE_DIR}
COMMAND ${MPGEN_BINARY} ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS} ${MP_INCLUDE_DIR}
DEPENDS ${capnp_file}
VERBATIM
)