Skip to content

Commit 35944ff

Browse files
committed
Merge #168: Switch MP_INCLUDE_DIR to global property
a77c8e1 Switch `MP_INCLUDE_DIR` to global property (Hennadii Stepanov) Pull request description: This PR automates handling of `MP_INCLUDE_DIR` in the `target_capnp_sources` function, removing the need to manually propagate it across directories for both this project and downstream projects. ACKs for top commit: ryanofsky: Code review ACK a77c8e1 Tree-SHA512: b1a1c367105210f0b4d957919c503f701f9b88200372383277234ce9950bd8effa893210d3863ef9250dcdcdc58ec1aac75164848bafe8eac233704f7340fdc5
2 parents f35df6b + a77c8e1 commit 35944ff

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

CMakeLists.txt

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ include("cmake/compat_config.cmake")
3030
include("cmake/pthread_checks.cmake")
3131
include(GNUInstallDirs)
3232

33-
# Set convenience variables for subdirectories.
34-
set(MP_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
33+
# Set MP_INCLUDE_DIR as a global property so target_capnp_sources function can
34+
# use it, and its callers don't need to specify the include directory manually
35+
# to avoid "error: Import failed: /mp/proxy.capnp" failures from capnproto.
36+
set_property(GLOBAL PROPERTY MP_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include")
37+
38+
# Set a convenience variable for subdirectories.
3539
if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
3640
set(MP_STANDALONE TRUE)
3741
include(CTest)
3842
else()
39-
# Set MP_INCLUDE_DIR for parent directories too, so target_capnp_sources calls
40-
# in parent directories can use it and not need to specify include directories
41-
# manually or see capnproto error "error: Import failed: /mp/proxy.capnp"
42-
set(MP_INCLUDE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/include" PARENT_SCOPE)
4343
set(MP_STANDALONE FALSE)
4444
endif()
4545

cmake/TargetCapnpSources.cmake

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,12 @@ function(target_capnp_sources target include_prefix)
7272
message(FATAL_ERROR "No usable mpgen. Set MPGEN_EXECUTABLE or enable the internal target.")
7373
endif()
7474

75+
get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)
7576
set(generated_headers "")
7677
foreach(capnp_file IN LISTS TCS_UNPARSED_ARGUMENTS)
7778
add_custom_command(
7879
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
79-
COMMAND ${MPGEN_BINARY} ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS} ${MP_INCLUDE_DIR}
80+
COMMAND ${MPGEN_BINARY} ${CMAKE_CURRENT_SOURCE_DIR} ${include_prefix} ${CMAKE_CURRENT_SOURCE_DIR}/${capnp_file} ${TCS_IMPORT_PATHS} ${mp_include_dir}
8081
DEPENDS ${capnp_file}
8182
VERBATIM
8283
)
@@ -97,7 +98,7 @@ function(target_capnp_sources target include_prefix)
9798
if(relative_path)
9899
string(APPEND build_include_prefix "/" "${relative_path}")
99100
endif()
100-
target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${build_include_prefix}> ${MP_INCLUDE_DIR})
101+
target_include_directories(${target} PUBLIC $<BUILD_INTERFACE:${build_include_prefix}> ${mp_include_dir})
101102

102103
if(TARGET Libmultiprocess::multiprocess)
103104
target_link_libraries(${target} PRIVATE Libmultiprocess::multiprocess)

0 commit comments

Comments
 (0)