|
| 1 | +# Copyright (c) 2019 The Bitcoin Core developers |
| 2 | +# Distributed under the MIT software license, see the accompanying |
| 3 | +# file COPYING or http://www.opensource.org/licenses/mit-license.php. |
| 4 | + |
| 5 | +cmake_minimum_required(VERSION 3.12) |
| 6 | + |
| 7 | +project("Libmultiprocess" CXX) |
| 8 | +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 9 | + set(CMAKE_CXX_STANDARD 20) |
| 10 | + set(CMAKE_CXX_STANDARD_REQUIRED YES) |
| 11 | +endif() |
| 12 | + |
| 13 | +include("cmake/compat_find.cmake") |
| 14 | + |
| 15 | +find_package(CapnProto REQUIRED) |
| 16 | +find_package(Threads REQUIRED) |
| 17 | + |
| 18 | +option(Libmultiprocess_ENABLE_CLANG_TIDY "Run clang-tidy with the compiler." OFF) |
| 19 | +if(Libmultiprocess_ENABLE_CLANG_TIDY) |
| 20 | + find_program(CLANG_TIDY_EXECUTABLE NAMES clang-tidy) |
| 21 | + if(NOT CLANG_TIDY_EXECUTABLE) |
| 22 | + message(FATAL_ERROR "Libmultiprocess_ENABLE_CLANG_TIDY is ON but clang-tidy is not found.") |
| 23 | + endif() |
| 24 | + set(CMAKE_CXX_CLANG_TIDY "${CLANG_TIDY_EXECUTABLE}") |
| 25 | +endif() |
| 26 | + |
| 27 | +set(MPGEN_EXECUTABLE "" CACHE FILEPATH "If specified, should be full path to an external mpgen binary to use rather than the one built internally.") |
| 28 | + |
| 29 | +include("cmake/compat_config.cmake") |
| 30 | +include("cmake/pthread_checks.cmake") |
| 31 | +include(GNUInstallDirs) |
| 32 | + |
| 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. |
| 39 | +if(CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) |
| 40 | + set(MP_STANDALONE TRUE) |
| 41 | + include(CTest) |
| 42 | +else() |
| 43 | + set(MP_STANDALONE FALSE) |
| 44 | +endif() |
| 45 | + |
| 46 | +# Prevent include directories from parent project from leaking into this one. |
| 47 | +set_property(DIRECTORY PROPERTY INCLUDE_DIRECTORIES "") |
| 48 | + |
| 49 | +# Generated C++ preprocessor defines |
| 50 | +configure_file(include/mp/config.h.in "${CMAKE_CURRENT_BINARY_DIR}/include/mp/config.h") |
| 51 | + |
| 52 | +# Generated C++ Capn'Proto schema files |
| 53 | +capnp_generate_cpp(MP_PROXY_SRCS MP_PROXY_HDRS include/mp/proxy.capnp) |
| 54 | + |
| 55 | +# util library |
| 56 | +add_library(mputil OBJECT src/mp/util.cpp) |
| 57 | +target_include_directories(mputil PRIVATE |
| 58 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 59 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>) |
| 60 | +target_link_libraries(mputil PUBLIC CapnProto::kj) |
| 61 | + |
| 62 | +# libmultiprocess.a runtime library |
| 63 | +set(MP_PUBLIC_HEADERS |
| 64 | + ${MP_PROXY_HDRS} |
| 65 | + include/mp/proxy-io.h |
| 66 | + include/mp/proxy-types.h |
| 67 | + include/mp/proxy.h |
| 68 | + include/mp/type-char.h |
| 69 | + include/mp/type-chrono.h |
| 70 | + include/mp/type-context.h |
| 71 | + include/mp/type-data.h |
| 72 | + include/mp/type-decay.h |
| 73 | + include/mp/type-exception.h |
| 74 | + include/mp/type-function.h |
| 75 | + include/mp/type-interface.h |
| 76 | + include/mp/type-map.h |
| 77 | + include/mp/type-message.h |
| 78 | + include/mp/type-number.h |
| 79 | + include/mp/type-optional.h |
| 80 | + include/mp/type-pair.h |
| 81 | + include/mp/type-pointer.h |
| 82 | + include/mp/type-set.h |
| 83 | + include/mp/type-string.h |
| 84 | + include/mp/type-struct.h |
| 85 | + include/mp/type-threadmap.h |
| 86 | + include/mp/type-tuple.h |
| 87 | + include/mp/type-vector.h |
| 88 | + include/mp/type-void.h |
| 89 | + include/mp/util.h) |
| 90 | +add_library(multiprocess STATIC |
| 91 | + ${MP_PROXY_SRCS} |
| 92 | + ${MP_PUBLIC_HEADERS} |
| 93 | + src/mp/proxy.cpp |
| 94 | + $<TARGET_OBJECTS:mputil>) |
| 95 | +add_library(Libmultiprocess::multiprocess ALIAS multiprocess) |
| 96 | +target_include_directories(multiprocess PUBLIC |
| 97 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include> |
| 98 | + $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> |
| 99 | + $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) |
| 100 | +target_link_libraries(multiprocess PUBLIC CapnProto::capnp) |
| 101 | +target_link_libraries(multiprocess PUBLIC CapnProto::capnp-rpc) |
| 102 | +target_link_libraries(multiprocess PUBLIC CapnProto::kj) |
| 103 | +target_link_libraries(multiprocess PUBLIC CapnProto::kj-async) |
| 104 | +set_target_properties(multiprocess PROPERTIES |
| 105 | + PUBLIC_HEADER "${MP_PUBLIC_HEADERS}") |
| 106 | +install(TARGETS multiprocess EXPORT LibTargets |
| 107 | + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT lib |
| 108 | + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mp COMPONENT lib) |
| 109 | + |
| 110 | +# mpgen code generator |
| 111 | +add_executable(mpgen src/mp/gen.cpp $<TARGET_OBJECTS:mputil>) |
| 112 | +add_executable(Libmultiprocess::mpgen ALIAS mpgen) |
| 113 | +target_include_directories(mpgen PRIVATE $<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}/include>) |
| 114 | +target_include_directories(mpgen PUBLIC $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include> $<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>) |
| 115 | +target_link_libraries(mpgen PRIVATE CapnProto::capnp) |
| 116 | +target_link_libraries(mpgen PRIVATE CapnProto::capnp-rpc) |
| 117 | +target_link_libraries(mpgen PRIVATE CapnProto::capnpc) |
| 118 | +target_link_libraries(mpgen PRIVATE CapnProto::kj) |
| 119 | +target_link_libraries(mpgen PRIVATE Threads::Threads) |
| 120 | +set_target_properties(mpgen PROPERTIES |
| 121 | + INSTALL_RPATH_USE_LINK_PATH TRUE) |
| 122 | +set_target_properties(mpgen PROPERTIES |
| 123 | + PUBLIC_HEADER include/mp/proxy.capnp) |
| 124 | +install(TARGETS mpgen EXPORT BinTargets |
| 125 | + RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT bin |
| 126 | + PUBLIC_HEADER DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mp COMPONENT bin) |
| 127 | + |
| 128 | +# makefile include to invoke mpgen code generator, for downstream Make projects |
| 129 | +install(FILES "include/mpgen.mk" |
| 130 | + DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} COMPONENT bin) |
| 131 | + |
| 132 | +# pkg-config module to build against libmultiprocess library, for downstream autoconf projects |
| 133 | +configure_file(pkgconfig/libmultiprocess.pc.in "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/libmultiprocess.pc" @ONLY) |
| 134 | +install(FILES "${CMAKE_CURRENT_BINARY_DIR}/pkgconfig/libmultiprocess.pc" |
| 135 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT lib) |
| 136 | + |
| 137 | +# cmake include to invoke mpgen code generator, for downstream CMake projects |
| 138 | +install( |
| 139 | + FILES |
| 140 | + ${CMAKE_CURRENT_SOURCE_DIR}/cmake/TargetCapnpSources.cmake |
| 141 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess COMPONENT bin) |
| 142 | + |
| 143 | +# CMake target import files, for downstream CMake projects |
| 144 | +install(EXPORT BinTargets |
| 145 | + NAMESPACE Libmultiprocess:: |
| 146 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess COMPONENT bin) |
| 147 | +install(EXPORT LibTargets |
| 148 | + NAMESPACE Libmultiprocess:: |
| 149 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess COMPONENT lib) |
| 150 | + |
| 151 | +# CMake find_package config file, for downstream CMake projects |
| 152 | +include(CMakePackageConfigHelpers) |
| 153 | +configure_package_config_file( |
| 154 | + ${PROJECT_SOURCE_DIR}/cmake/Config.cmake.in |
| 155 | + LibmultiprocessConfig.cmake |
| 156 | + INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess |
| 157 | + NO_SET_AND_CHECK_MACRO) |
| 158 | +install( |
| 159 | + FILES |
| 160 | + ${CMAKE_CURRENT_BINARY_DIR}/LibmultiprocessConfig.cmake |
| 161 | + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/Libmultiprocess |
| 162 | + COMPONENT common) |
| 163 | + |
| 164 | +# Makefile targets to support "make install-bin" "make install-lib" |
| 165 | +add_custom_target(install-bin |
| 166 | + COMMAND ${CMAKE_COMMAND} -DCOMPONENT=bin -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake |
| 167 | + COMMAND ${CMAKE_COMMAND} -DCOMPONENT=common -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake |
| 168 | + VERBATIM) |
| 169 | +add_dependencies(install-bin mpgen) |
| 170 | +add_custom_target(install-lib |
| 171 | + COMMAND ${CMAKE_COMMAND} -DCOMPONENT=lib -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake |
| 172 | + COMMAND ${CMAKE_COMMAND} -DCOMPONENT=common -P ${CMAKE_CURRENT_BINARY_DIR}/cmake_install.cmake |
| 173 | + VERBATIM) |
| 174 | +add_dependencies(install-lib multiprocess) |
| 175 | + |
| 176 | +# Example and test subdirectories |
| 177 | +add_subdirectory(example EXCLUDE_FROM_ALL) |
| 178 | +add_subdirectory(test EXCLUDE_FROM_ALL) |
0 commit comments