Skip to content
Merged
Show file tree
Hide file tree
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
15 changes: 12 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ include(CMakePushCheckState)
include(CTest)
include(CheckCXXSourceCompiles)
find_package(Boost)
find_package(CapnProto)
find_package(CapnProto REQUIRED)
find_package(Threads REQUIRED)

include("cmake/capnp_compat.cmake")

cmake_push_check_state()
set(CMAKE_REQUIRED_LIBRARIES Threads::Threads)
check_cxx_source_compiles("
Expand Down Expand Up @@ -73,8 +75,11 @@ install(TARGETS multiprocess EXPORT Multiprocess ARCHIVE DESTINATION lib PUBLIC_
add_executable(mpgen src/mp/gen.cpp)
target_include_directories(mpgen PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>)
target_include_directories(mpgen PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:include>)
target_link_libraries(mpgen PRIVATE CapnProto::capnp)
target_link_libraries(mpgen PRIVATE CapnProto::capnp-rpc)
target_link_libraries(mpgen PRIVATE -L${capnp_LIBRARY_DIRS} capnpc)
target_link_libraries(mpgen PRIVATE CapnProto::capnpc)
target_link_libraries(mpgen PRIVATE CapnProto::kj)
target_link_libraries(mpgen PRIVATE Threads::Threads)
target_link_libraries(mpgen PRIVATE multiprocess)
set_target_properties(mpgen PROPERTIES
INSTALL_RPATH_USE_LINK_PATH TRUE
Expand All @@ -89,7 +94,7 @@ install(FILES "include/mpgen.mk" DESTINATION "include")

install(EXPORT Multiprocess DESTINATION lib/cmake/Multiprocess)

if(BUILD_TESTING)
if(BUILD_TESTING AND TARGET CapnProto::kj-test)
add_custom_command(
OUTPUT
src/mp/test/foo.capnp.h
Expand Down Expand Up @@ -122,8 +127,12 @@ if(BUILD_TESTING)
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/src>
$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/src>
)
target_link_libraries(mptest PRIVATE CapnProto::capnp)
target_link_libraries(mptest PRIVATE CapnProto::capnp-rpc)
target_link_libraries(mptest PRIVATE CapnProto::kj)
target_link_libraries(mptest PRIVATE CapnProto::kj-async)
target_link_libraries(mptest PRIVATE CapnProto::kj-test)
target_link_libraries(mptest PRIVATE Threads::Threads)
target_link_libraries(mptest PRIVATE multiprocess)
set_target_properties(mptest PROPERTIES
CXX_STANDARD 14
Expand Down
60 changes: 60 additions & 0 deletions cmake/capnp_compat.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
# Copyright (c) 2019 The Bitcoin Core developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

# CMake target definitions for backwards compatibility with Ubuntu bionic
# capnproto 0.6.1 package (https://packages.ubuntu.com/bionic/libcapnp-dev)

include(CheckIncludeFileCXX)
include(CMakePushCheckState)

if (NOT DEFINED capnp_PREFIX AND DEFINED CAPNP_INCLUDE_DIRS)
get_filename_component(capnp_PREFIX "${CAPNP_INCLUDE_DIRS}" DIRECTORY)
endif()

if (NOT DEFINED CAPNPC_OUTPUT_DIR)
set(CAPNPC_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}")
endif()

if (NOT DEFINED CAPNP_LIB_CAPNPC AND DEFINED CAPNP_LIB_CAPNP-RPC)
string(REPLACE "-rpc" "c" CAPNP_LIB_CAPNPC "${CAPNP_LIB_CAPNP-RPC}")
endif()

if (NOT DEFINED CapnProto_capnpc_IMPORTED_LOCATION AND DEFINED CapnProto_capnp-rpc_IMPORTED_LOCATION)
string(REPLACE "-rpc" "c" CapnProto_capnpc_IMPORTED_LOCATION "${CapnProto_capnp-rpc_IMPORTED_LOCATION}")
endif()

if (NOT TARGET CapnProto::capnp AND DEFINED CAPNP_LIB_CAPNP)
add_library(CapnProto::capnp SHARED IMPORTED)
set_target_properties(CapnProto::capnp PROPERTIES IMPORTED_LOCATION "${CAPNP_LIB_CAPNP}")
endif()

if (NOT TARGET CapnProto::capnpc AND DEFINED CAPNP_LIB_CAPNPC)
add_library(CapnProto::capnpc SHARED IMPORTED)
set_target_properties(CapnProto::capnpc PROPERTIES IMPORTED_LOCATION "${CAPNP_LIB_CAPNPC}")
endif()

if (NOT TARGET CapnProto::capnpc AND DEFINED CapnProto_capnpc_IMPORTED_LOCATION)
add_library(CapnProto::capnpc SHARED IMPORTED)
set_target_properties(CapnProto::capnpc PROPERTIES IMPORTED_LOCATION "${CapnProto_capnpc_IMPORTED_LOCATION}")
endif()

if (NOT TARGET CapnProto::capnp-rpc AND DEFINED CAPNP_LIB_CAPNP-RPC)
add_library(CapnProto::capnp-rpc SHARED IMPORTED)
set_target_properties(CapnProto::capnp-rpc PROPERTIES IMPORTED_LOCATION "${CAPNP_LIB_CAPNP-RPC}")
endif()

if (NOT TARGET CapnProto::kj AND DEFINED CAPNP_LIB_KJ)
add_library(CapnProto::kj SHARED IMPORTED)
set_target_properties(CapnProto::kj PROPERTIES IMPORTED_LOCATION "${CAPNP_LIB_KJ}")
endif()

if (NOT TARGET CapnProto::kj-async AND DEFINED CAPNP_LIB_KJ-ASYNC)
add_library(CapnProto::kj-async SHARED IMPORTED)
set_target_properties(CapnProto::kj-async PROPERTIES IMPORTED_LOCATION "${CAPNP_LIB_KJ-ASYNC}")
endif()

cmake_push_check_state()
set(CMAKE_REQUIRED_INCLUDES ${CMAKE_REQUIRED_INCLUDES} ${capnp_INCLUDE_DIRS})
check_include_file_cxx("kj/filesystem.h" HAVE_KJ_FILESYSTEM)
cmake_pop_check_state()
1 change: 1 addition & 0 deletions include/mp/config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

#cmakedefine CMAKE_INSTALL_PREFIX "@CMAKE_INSTALL_PREFIX@"
#cmakedefine capnp_PREFIX "@capnp_PREFIX@"
#cmakedefine HAVE_KJ_FILESYSTEM

#cmakedefine HAVE_PTHREAD_GETNAME_NP @HAVE_PTHREAD_GETNAME_NP@
#cmakedefine HAVE_PTHREAD_THREADID_NP @HAVE_PTHREAD_THREADID_NP@
Expand Down
6 changes: 6 additions & 0 deletions src/mp/gen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -550,10 +550,16 @@ int main(int argc, char** argv)
exit(1);
}
std::vector<kj::StringPtr> import_paths;
#ifdef HAVE_KJ_FILESYSTEM
auto fs = kj::newDiskFilesystem();
auto cwd = fs->getCurrentPath();
#endif
for (const char* path : {CMAKE_INSTALL_PREFIX "/include", capnp_PREFIX "/include"}) {
#ifdef HAVE_KJ_FILESYSTEM
KJ_IF_MAYBE(dir, fs->getRoot().tryOpenSubdir(cwd.evalNative(path))) { import_paths.emplace_back(path); }
#else
import_paths.emplace_back(path);
#endif
}
for (size_t i = 4; i < argc; ++i) {
import_paths.push_back(argv[i]);
Expand Down