jpayne@69
|
1 # Cap'n Proto CMake Package Configuration
|
jpayne@69
|
2 #
|
jpayne@69
|
3 # When configured and installed, this file enables client projects to find Cap'n Proto using
|
jpayne@69
|
4 # CMake's find_package() command. It adds imported targets in the CapnProto:: namespace, such as
|
jpayne@69
|
5 # CapnProto::kj, CapnProto::capnp, etc. (one target for each file in pkgconfig/*.pc.in), defines
|
jpayne@69
|
6 # the capnp_generate_cpp() function, and exposes some variables for compatibility with the original
|
jpayne@69
|
7 # FindCapnProto.cmake module.
|
jpayne@69
|
8 #
|
jpayne@69
|
9 # Example usage:
|
jpayne@69
|
10 # find_package(CapnProto)
|
jpayne@69
|
11 # capnp_generate_cpp(CAPNP_SRCS CAPNP_HDRS schema.capnp)
|
jpayne@69
|
12 # add_executable(foo main.cpp ${CAPNP_SRCS})
|
jpayne@69
|
13 # target_link_libraries(foo PRIVATE CapnProto::capnp)
|
jpayne@69
|
14 # target_include_directories(foo PRIVATE ${CMAKE_CURRENT_BINARY_DIR})
|
jpayne@69
|
15 #
|
jpayne@69
|
16 # If you are using RPC features, use 'CapnProto::capnp-rpc' in the target_link_libraries() call.
|
jpayne@69
|
17 #
|
jpayne@69
|
18 # Paths to `capnp` and `capnpc-c++` are exposed in the following variables:
|
jpayne@69
|
19 # CAPNP_EXECUTABLE
|
jpayne@69
|
20 # Path to the `capnp` tool (can be set to override).
|
jpayne@69
|
21 # CAPNPC_CXX_EXECUTABLE
|
jpayne@69
|
22 # Path to the `capnpc-c++` tool (can be set to override).
|
jpayne@69
|
23 #
|
jpayne@69
|
24 # For FindCapnProto.cmake compatibility, the following variables are also provided. Please prefer
|
jpayne@69
|
25 # using the imported targets in new CMake code.
|
jpayne@69
|
26 # CAPNP_INCLUDE_DIRS
|
jpayne@69
|
27 # Include directories for the library's headers.
|
jpayne@69
|
28 # CANP_LIBRARIES
|
jpayne@69
|
29 # The Cap'n Proto library paths.
|
jpayne@69
|
30 # CAPNP_LIBRARIES_LITE
|
jpayne@69
|
31 # Paths to only the 'lite' libraries.
|
jpayne@69
|
32 # CAPNP_DEFINITIONS
|
jpayne@69
|
33 # Compiler definitions required for building with the library.
|
jpayne@69
|
34 # CAPNP_FOUND
|
jpayne@69
|
35 # Set if the libraries have been located (prefer using CapnProto_FOUND in new code).
|
jpayne@69
|
36 #
|
jpayne@69
|
37 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@69
|
38
|
jpayne@69
|
39 set(CapnProto_VERSION 1.0.2)
|
jpayne@69
|
40
|
jpayne@69
|
41 set(CAPNP_EXECUTABLE $<TARGET_FILE:CapnProto::capnp_tool>
|
jpayne@69
|
42 CACHE FILEPATH "Location of capnp executable")
|
jpayne@69
|
43 set(CAPNPC_CXX_EXECUTABLE $<TARGET_FILE:CapnProto::capnpc_cpp>
|
jpayne@69
|
44 CACHE FILEPATH "Location of capnpc-c++ executable")
|
jpayne@69
|
45 set(CAPNP_INCLUDE_DIRECTORY "${CMAKE_CURRENT_LIST_DIR}/../../../include")
|
jpayne@69
|
46
|
jpayne@69
|
47 # work around http://public.kitware.com/Bug/view.php?id=15258
|
jpayne@69
|
48 if(NOT _IMPORT_PREFIX)
|
jpayne@69
|
49 set(_IMPORT_PREFIX ${PACKAGE_PREFIX_DIR})
|
jpayne@69
|
50 endif()
|
jpayne@69
|
51
|
jpayne@69
|
52 if (NO) # WITH_OPENSSL
|
jpayne@69
|
53 include(CMakeFindDependencyMacro)
|
jpayne@69
|
54 if (CMAKE_VERSION VERSION_LESS 3.9)
|
jpayne@69
|
55 # find_dependency() did not support COMPONENTS until CMake 3.9
|
jpayne@69
|
56 #
|
jpayne@69
|
57 # in practice, this call can be erroneous
|
jpayne@69
|
58 # if the user has only libcrypto installed, but not libssl
|
jpayne@69
|
59 find_dependency(OpenSSL)
|
jpayne@69
|
60 else()
|
jpayne@69
|
61 find_dependency(OpenSSL COMPONENTS Crypto SSL)
|
jpayne@69
|
62 endif()
|
jpayne@69
|
63 endif()
|
jpayne@69
|
64
|
jpayne@69
|
65 if (@WITH_ZLIB@) # WITH_ZLIB
|
jpayne@69
|
66 include(CMakeFindDependencyMacro)
|
jpayne@69
|
67 find_dependency(ZLIB)
|
jpayne@69
|
68 endif()
|
jpayne@69
|
69
|
jpayne@69
|
70 if (NO) # _WITH_LIBUCONTEXT
|
jpayne@69
|
71 set(forwarded_config_flags)
|
jpayne@69
|
72 if(CapnProto_FIND_QUIETLY)
|
jpayne@69
|
73 list(APPEND forwarded_config_flags QUIET)
|
jpayne@69
|
74 endif()
|
jpayne@69
|
75 if(CapnProto_FIND_REQUIRED)
|
jpayne@69
|
76 list(APPEND forwarded_config_flags REQUIRED)
|
jpayne@69
|
77 endif()
|
jpayne@69
|
78 # If the consuming project called find_package(CapnProto) with the QUIET or REQUIRED flags, forward
|
jpayne@69
|
79 # them to calls to find_package(PkgConfig) and pkg_check_modules(). Note that find_dependency()
|
jpayne@69
|
80 # would do this for us in the former case, but there is no such forwarding wrapper for
|
jpayne@69
|
81 # pkg_check_modules().
|
jpayne@69
|
82
|
jpayne@69
|
83 find_package(PkgConfig ${forwarded_config_flags})
|
jpayne@69
|
84 if(NOT ${PkgConfig_FOUND})
|
jpayne@69
|
85 # If we're here, the REQUIRED flag must not have been passed, else we would have had a fatal
|
jpayne@69
|
86 # error. Nevertheless, a diagnostic for this case is probably nice.
|
jpayne@69
|
87 if(NOT CapnProto_FIND_QUIETLY)
|
jpayne@69
|
88 message(WARNING "pkg-config cannot be found")
|
jpayne@69
|
89 endif()
|
jpayne@69
|
90 set(CapnProto_FOUND OFF)
|
jpayne@69
|
91 return()
|
jpayne@69
|
92 endif()
|
jpayne@69
|
93
|
jpayne@69
|
94 if (CMAKE_VERSION VERSION_LESS 3.6)
|
jpayne@69
|
95 # CMake >= 3.6 required due to the use of IMPORTED_TARGET
|
jpayne@69
|
96 message(SEND_ERROR "libucontext support requires CMake >= 3.6.")
|
jpayne@69
|
97 endif()
|
jpayne@69
|
98
|
jpayne@69
|
99 pkg_check_modules(libucontext IMPORTED_TARGET ${forwarded_config_flags} libucontext)
|
jpayne@69
|
100 endif()
|
jpayne@69
|
101
|
jpayne@69
|
102 include("${CMAKE_CURRENT_LIST_DIR}/CapnProtoTargets.cmake")
|
jpayne@69
|
103 include("${CMAKE_CURRENT_LIST_DIR}/CapnProtoMacros.cmake")
|
jpayne@69
|
104
|
jpayne@69
|
105
|
jpayne@69
|
106 # FindCapnProto.cmake provides dependency information via several CAPNP_-prefixed variables. New
|
jpayne@69
|
107 # code should not rely on these variables, but prefer linking directly to the imported targets we
|
jpayne@69
|
108 # now provide. However, we should still set these variables to ease the transition for projects
|
jpayne@69
|
109 # which currently depend on the find-module.
|
jpayne@69
|
110
|
jpayne@69
|
111 set(CAPNP_INCLUDE_DIRS ${CAPNP_INCLUDE_DIRECTORY})
|
jpayne@69
|
112
|
jpayne@69
|
113 # No need to list all libraries, just the leaves of the dependency tree.
|
jpayne@69
|
114 set(CAPNP_LIBRARIES_LITE CapnProto::capnp)
|
jpayne@69
|
115 set(CAPNP_LIBRARIES CapnProto::capnp-rpc CapnProto::capnp-json
|
jpayne@69
|
116 CapnProto::kj-http)
|
jpayne@69
|
117
|
jpayne@69
|
118 set(CAPNP_DEFINITIONS)
|
jpayne@69
|
119 if(TARGET CapnProto::capnp AND NOT TARGET CapnProto::capnp-rpc)
|
jpayne@69
|
120 set(CAPNP_DEFINITIONS -DCAPNP_LITE)
|
jpayne@69
|
121 endif()
|
jpayne@69
|
122
|
jpayne@69
|
123 set(CAPNP_FOUND ${CapnProto_FOUND})
|