From 75cf04a6ed4870d2023f005a9f0a9ef3c81e9996 Mon Sep 17 00:00:00 2001 From: Cory Fields Date: Fri, 31 Jan 2025 17:16:21 +0000 Subject: [PATCH] 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. --- CMakeLists.txt | 2 ++ cmake/TargetCapnpSources.cmake | 14 +++++++++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index de8c95a4..995a657a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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") + include("cmake/compat_config.cmake") include("cmake/pthread_checks.cmake") include(GNUInstallDirs) diff --git a/cmake/TargetCapnpSources.cmake b/cmake/TargetCapnpSources.cmake index cdc86c69..0a094376 100644 --- a/cmake/TargetCapnpSources.cmake +++ b/cmake/TargetCapnpSources.cmake @@ -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 $) + 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 )