jpayne@68: # Cap'n Proto CMake Package Configuration jpayne@68: # jpayne@68: # When configured and installed, this file enables client projects to find Cap'n Proto using jpayne@68: # CMake's find_package() command. It adds imported targets in the CapnProto:: namespace, such as jpayne@68: # CapnProto::kj, CapnProto::capnp, etc. (one target for each file in pkgconfig/*.pc.in), defines jpayne@68: # the capnp_generate_cpp() function, and exposes some variables for compatibility with the original jpayne@68: # FindCapnProto.cmake module. jpayne@68: # jpayne@68: # Example usage: jpayne@68: # find_package(CapnProto) jpayne@68: # capnp_generate_cpp(CAPNP_SRCS CAPNP_HDRS schema.capnp) jpayne@68: # add_executable(foo main.cpp ${CAPNP_SRCS}) jpayne@68: # target_link_libraries(foo PRIVATE CapnProto::capnp) jpayne@68: # target_include_directories(foo PRIVATE ${CMAKE_CURRENT_BINARY_DIR}) jpayne@68: # jpayne@68: # If you are using RPC features, use 'CapnProto::capnp-rpc' in the target_link_libraries() call. jpayne@68: # jpayne@68: # Paths to `capnp` and `capnpc-c++` are exposed in the following variables: jpayne@68: # CAPNP_EXECUTABLE jpayne@68: # Path to the `capnp` tool (can be set to override). jpayne@68: # CAPNPC_CXX_EXECUTABLE jpayne@68: # Path to the `capnpc-c++` tool (can be set to override). jpayne@68: # jpayne@68: # For FindCapnProto.cmake compatibility, the following variables are also provided. Please prefer jpayne@68: # using the imported targets in new CMake code. jpayne@68: # CAPNP_INCLUDE_DIRS jpayne@68: # Include directories for the library's headers. jpayne@68: # CANP_LIBRARIES jpayne@68: # The Cap'n Proto library paths. jpayne@68: # CAPNP_LIBRARIES_LITE jpayne@68: # Paths to only the 'lite' libraries. jpayne@68: # CAPNP_DEFINITIONS jpayne@68: # Compiler definitions required for building with the library. jpayne@68: # CAPNP_FOUND jpayne@68: # Set if the libraries have been located (prefer using CapnProto_FOUND in new code). jpayne@68: # jpayne@68: set(CAPNP_PKG_CONFIG_FILES pkgconfig/capnp.pc pkgconfig/capnpc.pc pkgconfig/capnp-rpc.pc pkgconfig/capnp-json.pc pkgconfig/capnp-websocket.pc pkgconfig/kj.pc pkgconfig/kj-async.pc pkgconfig/kj-http.pc pkgconfig/kj-gzip.pc pkgconfig/kj-tls.pc pkgconfig/kj-test.pc ) jpayne@68: jpayne@68: set(CapnProto_VERSION 1.0.2) jpayne@68: jpayne@68: set(CAPNP_EXECUTABLE $ jpayne@68: CACHE FILEPATH "Location of capnp executable") jpayne@68: set(CAPNPC_CXX_EXECUTABLE $ jpayne@68: CACHE FILEPATH "Location of capnpc-c++ executable") jpayne@68: set(CAPNP_INCLUDE_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../../../include") jpayne@68: jpayne@68: # work around http://public.kitware.com/Bug/view.php?id=15258 jpayne@68: if(NOT _IMPORT_PREFIX) jpayne@68: set(_IMPORT_PREFIX ${PACKAGE_PREFIX_DIR}) jpayne@68: endif() jpayne@68: jpayne@68: if (NO) # WITH_OPENSSL jpayne@68: include(CMakeFindDependencyMacro) jpayne@68: if (CMAKE_VERSION VERSION_LESS 3.9) jpayne@68: # find_dependency() did not support COMPONENTS until CMake 3.9 jpayne@68: # jpayne@68: # in practice, this call can be erroneous jpayne@68: # if the user has only libcrypto installed, but not libssl jpayne@68: find_dependency(OpenSSL) jpayne@68: else() jpayne@68: find_dependency(OpenSSL COMPONENTS Crypto SSL) jpayne@68: endif() jpayne@68: endif() jpayne@68: jpayne@68: if (@WITH_ZLIB@) # WITH_ZLIB jpayne@68: include(CMakeFindDependencyMacro) jpayne@68: find_dependency(ZLIB) jpayne@68: endif() jpayne@68: jpayne@68: if (NO) # _WITH_LIBUCONTEXT jpayne@68: set(forwarded_config_flags) jpayne@68: if(CapnProto_FIND_QUIETLY) jpayne@68: list(APPEND forwarded_config_flags QUIET) jpayne@68: endif() jpayne@68: if(CapnProto_FIND_REQUIRED) jpayne@68: list(APPEND forwarded_config_flags REQUIRED) jpayne@68: endif() jpayne@68: # If the consuming project called find_package(CapnProto) with the QUIET or REQUIRED flags, forward jpayne@68: # them to calls to find_package(PkgConfig) and pkg_check_modules(). Note that find_dependency() jpayne@68: # would do this for us in the former case, but there is no such forwarding wrapper for jpayne@68: # pkg_check_modules(). jpayne@68: jpayne@68: find_package(PkgConfig ${forwarded_config_flags}) jpayne@68: if(NOT ${PkgConfig_FOUND}) jpayne@68: # If we're here, the REQUIRED flag must not have been passed, else we would have had a fatal jpayne@68: # error. Nevertheless, a diagnostic for this case is probably nice. jpayne@68: if(NOT CapnProto_FIND_QUIETLY) jpayne@68: message(WARNING "pkg-config cannot be found") jpayne@68: endif() jpayne@68: set(CapnProto_FOUND OFF) jpayne@68: return() jpayne@68: endif() jpayne@68: jpayne@68: if (CMAKE_VERSION VERSION_LESS 3.6) jpayne@68: # CMake >= 3.6 required due to the use of IMPORTED_TARGET jpayne@68: message(SEND_ERROR "libucontext support requires CMake >= 3.6.") jpayne@68: endif() jpayne@68: jpayne@68: pkg_check_modules(libucontext IMPORTED_TARGET ${forwarded_config_flags} libucontext) jpayne@68: endif() jpayne@68: jpayne@68: include("${CMAKE_CURRENT_LIST_DIR}/CapnProtoTargets.cmake") jpayne@68: include("${CMAKE_CURRENT_LIST_DIR}/CapnProtoMacros.cmake") jpayne@68: jpayne@68: jpayne@68: # FindCapnProto.cmake provides dependency information via several CAPNP_-prefixed variables. New jpayne@68: # code should not rely on these variables, but prefer linking directly to the imported targets we jpayne@68: # now provide. However, we should still set these variables to ease the transition for projects jpayne@68: # which currently depend on the find-module. jpayne@68: jpayne@68: set(CAPNP_INCLUDE_DIRS ${CAPNP_INCLUDE_DIRECTORY}) jpayne@68: jpayne@68: # No need to list all libraries, just the leaves of the dependency tree. jpayne@68: set(CAPNP_LIBRARIES_LITE CapnProto::capnp) jpayne@68: set(CAPNP_LIBRARIES CapnProto::capnp-rpc CapnProto::capnp-json jpayne@68: CapnProto::kj-http) jpayne@68: jpayne@68: set(CAPNP_DEFINITIONS) jpayne@68: if(TARGET CapnProto::capnp AND NOT TARGET CapnProto::capnp-rpc) jpayne@68: set(CAPNP_DEFINITIONS -DCAPNP_LITE) jpayne@68: endif() jpayne@68: jpayne@68: set(CAPNP_FOUND ${CapnProto_FOUND})