Skip to content
Open
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
6 changes: 5 additions & 1 deletion cmake/TargetCapnpSources.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,15 @@ function(target_capnp_sources target include_prefix)
endif()

get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In commit "cmake: Pass installed include dir to mpgen" (7239a97)

I'm ok with the current approach, but an alternative that seems cleaner if it works would be for the package config to set MP_INCLUDE_DIR itself. Then MP_INCLUDE_DIR would always be the directory containing mp/proxy.capnp, the include directory would be worked out where the package is found, and target_capnp_sources wouldn't need a special case for installed packages. Something like this at the end of Config.cmake.in, after the loop that includes the targets files:

if ("Bin" IN_LIST ${CMAKE_FIND_PACKAGE_NAME}_FIND_COMPONENTS)
  get_target_property(_mp_include_dir Libmultiprocess::mpgen INTERFACE_INCLUDE_DIRECTORIES)
  set_property(GLOBAL PROPERTY MP_INCLUDE_DIR "${_mp_include_dir}")
endif()

(or PATH_VARS CMAKE_INSTALL_INCLUDEDIR in configure_package_config_file and @PACKAGE_CMAKE_INSTALL_INCLUDEDIR@). It needs to be conditional on Bin, not Lib, because Bitcoin Core cross builds find the two components in different prefixes and proxy.capnp is installed with Bin. I haven't tried this, so there may be a reason it doesn't work, in which case the current approach is fine.

set(mpgen_import_paths ${mp_include_dir})
if(NOT mp_include_dir AND MPGEN_BINARY STREQUAL "Libmultiprocess::mpgen")

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In commit "cmake: Pass installed include dir to mpgen" (7239a97)

This fixes the case reported in #134, but MPGEN_EXECUTABLE and mpgen.mk users with a relocated install still get the compiled-in path, and the Cap'n Proto include path is still compiled in too. I think that's fine for this PR (the MPGEN_EXECUTABLE case can be worked around with IMPORT_PATHS), but maybe the description could say "Fixes the cmake case of #134" instead of "Fixes #134", so the issue stays open for the rest?

get_property(mpgen_import_paths TARGET Libmultiprocess::mpgen PROPERTY INTERFACE_INCLUDE_DIRECTORIES)

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In commit "cmake: Pass installed include dir to mpgen" (7239a97)

Note for reviewers: for the imported target this property comes from $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>, which the exported targets file makes relative to the package location, and proxy.capnp is installed to ${CMAKE_INSTALL_INCLUDEDIR}/mp in the same component. So the path always contains the file mpgen needs. It is also better than the compiled-in path when CMAKE_INSTALL_INCLUDEDIR isn't include, because mpgen hardcodes CMAKE_INSTALL_PREFIX "/include". mpgen still appends that compiled-in path after this one, which is harmless.

endif()
Comment on lines 80 to +84

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

In commit "cmake: Pass installed include dir to mpgen" (7239a97)

Suggestion (non-blocking): it wasn't obvious to me that an empty MP_INCLUDE_DIR is what identifies an installed package here, so it could be worth a comment. This applies with the current approach; if you switch to the one in the Config.cmake.in comment, a similar comment next to where MP_INCLUDE_DIR is set would still help:

Suggested change
get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)
set(mpgen_import_paths ${mp_include_dir})
if(NOT mp_include_dir AND MPGEN_BINARY STREQUAL "Libmultiprocess::mpgen")
get_property(mpgen_import_paths TARGET Libmultiprocess::mpgen PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
endif()
get_property(mp_include_dir GLOBAL PROPERTY MP_INCLUDE_DIR)
# MP_INCLUDE_DIR is only set when libmultiprocess is built from source in
# the same project. If it is empty, libmultiprocess is an installed package,
# so pass the include directory of the imported mpgen target. Otherwise
# mpgen would only search the include path compiled into it, which is wrong
# if the package was installed with a different --prefix or moved (#134).
set(mpgen_import_paths ${mp_include_dir})
if(NOT mp_include_dir AND MPGEN_BINARY STREQUAL "Libmultiprocess::mpgen")
get_property(mpgen_import_paths TARGET Libmultiprocess::mpgen PROPERTY INTERFACE_INCLUDE_DIRECTORIES)
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 ${MPGEN_BINARY} ${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} ${mpgen_import_paths}
DEPENDS ${capnp_file} ${MPGEN_BINARY}
VERBATIM
)
Expand Down
Loading