Skip to content

Commit 0c2ac4d

Browse files
committed
Merge #142: build: add option for external mpgen binary
75cf04a build: add option for external mpgen binary (Cory Fields) Pull request description: 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. ACKs for top commit: ryanofsky: Code review ACK 75cf04a Looks great! hebasto: Approach ACK 75cf04a. Tree-SHA512: dafcebc17f66a3e1b4ea11c453a1193f58874585d77ee50dcd59d8353171bdeaab49cf9968cd4e122fd7bf707e5ee153343d6bc9c4d2732fbb775559f53870d4
2 parents 1e06ff0 + 75cf04a commit 0c2ac4d

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

CMakeLists.txt

+2
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ if(Libmultiprocess_ENABLE_CLANG_TIDY)
2424
set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}")
2525
endif()
2626

27+
set(EXTERNAL_MPGEN "" CACHE STRING "Use the supplied mpgen binary rather than the one built internally")
28+
2729
include("cmake/compat_config.cmake")
2830
include("cmake/pthread_checks.cmake")
2931
include(GNUInstallDirs)

cmake/TargetCapnpSources.cmake

+11-3
Original file line numberDiff line numberDiff line change
@@ -60,15 +60,23 @@ function(target_capnp_sources target include_prefix)
6060
"IMPORT_PATHS" # multi_value_keywords
6161
)
6262

63-
if(NOT TARGET Libmultiprocess::mpgen)
64-
message(FATAL_ERROR "Target 'Libmultiprocess::mpgen' does not exist.")
63+
set(MPGEN_BINARY "")
64+
if(EXTERNAL_MPGEN)
65+
set(MPGEN_BINARY "${EXTERNAL_MPGEN}")
66+
if(NOT EXISTS "${MPGEN_BINARY}")
67+
message(FATAL_ERROR "EXTERNAL_MPGEN: \"${MPGEN_BINARY}\" does not exist.")
68+
endif()
69+
elseif(TARGET Libmultiprocess::multiprocess)
70+
set(MPGEN_BINARY $<TARGET_FILE:Libmultiprocess::mpgen>)
71+
else()
72+
message(FATAL_ERROR "No usable mpgen. Set EXTERNAL_MPGEN or enable the internal target.")
6573
endif()
6674

6775
set(generated_headers "")
6876
foreach(capnp_file IN LISTS TCS_UNPARSED_ARGUMENTS)
6977
add_custom_command(
7078
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
71-
COMMAND Libmultiprocess::mpgen ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS} ${MP_INCLUDE_DIR}
79+
COMMAND ${MPGEN_BINARY} ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS} ${MP_INCLUDE_DIR}
7280
DEPENDS ${capnp_file}
7381
VERBATIM
7482
)

0 commit comments

Comments
 (0)