Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 1 | %YAML 1.2 |
| 2 | --- | |
| 3 | # GRPC global cmake file |
| 4 | # This currently builds C and C++ code. |
| 5 | # This file has been automatically generated from a template file. |
| 6 | # Please look at the templates directory instead. |
| 7 | # This file can be regenerated from the template by running |
| 8 | # tools/buildgen/generate_projects.sh |
Nicolas "Pixel" Noble | b360c8a | 2016-07-02 00:54:28 +0200 | [diff] [blame] | 9 | # |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 10 | # Copyright 2015, Google Inc. |
| 11 | # All rights reserved. |
| 12 | # |
| 13 | # Redistribution and use in source and binary forms, with or without |
| 14 | # modification, are permitted provided that the following conditions are |
| 15 | # met: |
| 16 | # |
| 17 | # * Redistributions of source code must retain the above copyright |
| 18 | # notice, this list of conditions and the following disclaimer. |
| 19 | # * Redistributions in binary form must reproduce the above |
| 20 | # copyright notice, this list of conditions and the following disclaimer |
| 21 | # in the documentation and/or other materials provided with the |
| 22 | # distribution. |
| 23 | # * Neither the name of Google Inc. nor the names of its |
| 24 | # contributors may be used to endorse or promote products derived from |
| 25 | # this software without specific prior written permission. |
| 26 | # |
| 27 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 28 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 29 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 30 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 31 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 32 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 33 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 34 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 35 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 36 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 37 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 38 | |
| 39 | <%! |
Yuchen Zeng | e02cbeb | 2017-01-19 16:33:30 -0800 | [diff] [blame] | 40 | |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 41 | import re |
Yuchen Zeng | e02cbeb | 2017-01-19 16:33:30 -0800 | [diff] [blame] | 42 | |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 43 | proto_re = re.compile('(.*)\\.proto') |
Yuchen Zeng | e02cbeb | 2017-01-19 16:33:30 -0800 | [diff] [blame] | 44 | |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 45 | def proto_replace_ext(filename, ext): |
| 46 | m = proto_re.match(filename) |
| 47 | if not m: |
| 48 | return filename |
| 49 | return '${_gRPC_PROTO_GENS_DIR}/' + m.group(1) + ext |
Yuchen Zeng | e02cbeb | 2017-01-19 16:33:30 -0800 | [diff] [blame] | 50 | |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 51 | def get_deps(target_dict): |
| 52 | deps = [] |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 53 | if target_dict.get('baselib', False): |
| 54 | deps.append("${_gRPC_BASELIB_LIBRARIES}") |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 55 | if target_dict.get('build', None) in ['protoc']: |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 56 | deps.append("${_gRPC_PROTOBUF_PROTOC_LIBRARIES}") |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 57 | if target_dict.get('secure', False): |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 58 | deps.append("${_gRPC_SSL_LIBRARIES}") |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 59 | if target_dict.language == 'c++': |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 60 | deps.append("${_gRPC_PROTOBUF_LIBRARIES}") |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 61 | if target_dict['name'] in ['grpc']: |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 62 | deps.append("${_gRPC_ZLIB_LIBRARIES}") |
Yuchen Zeng | 8076d2b | 2016-08-25 13:23:13 -0700 | [diff] [blame] | 63 | deps.append("${_gRPC_CARES_LIBRARIES}") |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 64 | deps.append("${_gRPC_ALLTARGETS_LIBRARIES}") |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 65 | for d in target_dict.get('deps', []): |
| 66 | deps.append(d) |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 67 | if target_dict.build == 'test' and target_dict.language == 'c++': |
| 68 | deps.append("${_gRPC_GFLAGS_LIBRARIES}") |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 69 | return deps |
Yuchen Zeng | 1492f6c | 2017-02-02 12:42:54 -0800 | [diff] [blame] | 70 | |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 71 | def get_platforms_condition_begin(platforms): |
| 72 | if all(platform in platforms for platform in ['linux', 'mac', 'posix', 'windows']): |
| 73 | return '' |
| 74 | cond = ' OR '.join(['_gRPC_PLATFORM_%s' % platform.upper() for platform in platforms]) |
| 75 | return 'if(%s)\n' % cond |
Yuchen Zeng | 1492f6c | 2017-02-02 12:42:54 -0800 | [diff] [blame] | 76 | |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 77 | def get_platforms_condition_end(platforms): |
| 78 | if not get_platforms_condition_begin(platforms): |
| 79 | return '' |
| 80 | return 'endif()\n' |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 81 | %> |
| 82 | |
| 83 | cmake_minimum_required(VERSION 2.8) |
| 84 | |
Tamas Berghammer | df6a44c | 2016-06-22 13:38:55 +0100 | [diff] [blame] | 85 | set(PACKAGE_NAME "grpc") |
Craig Tiller | 83c4789 | 2016-09-13 11:14:43 -0700 | [diff] [blame] | 86 | set(PACKAGE_VERSION "${settings.cpp_version}") |
Tamas Berghammer | df6a44c | 2016-06-22 13:38:55 +0100 | [diff] [blame] | 87 | set(PACKAGE_STRING "<%text>${PACKAGE_NAME} ${PACKAGE_VERSION}</%text>") |
| 88 | set(PACKAGE_TARNAME "<%text>${PACKAGE_NAME}-${PACKAGE_VERSION}</%text>") |
| 89 | set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/") |
| 90 | project(<%text>${PACKAGE_NAME}</%text> C CXX) |
| 91 | |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 92 | # Options |
| 93 | option(gRPC_BUILD_TESTS "Build tests" OFF) |
Tamas Berghammer | df6a44c | 2016-06-22 13:38:55 +0100 | [diff] [blame] | 94 | |
Arkadiy Shapkin | 40beb37 | 2016-08-17 14:42:36 +0300 | [diff] [blame] | 95 | if (NOT MSVC) |
| 96 | set(gRPC_INSTALL ON CACHE BOOL "Generate installation target") |
| 97 | else() |
| 98 | set(gRPC_INSTALL OFF CACHE BOOL "Generate installation target") |
| 99 | endif() |
| 100 | |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 101 | set(gRPC_ZLIB_PROVIDER "module" CACHE STRING "Provider of zlib library") |
| 102 | set_property(CACHE gRPC_ZLIB_PROVIDER PROPERTY STRINGS "module" "package") |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 103 | |
Yuchen Zeng | 8076d2b | 2016-08-25 13:23:13 -0700 | [diff] [blame] | 104 | set(gRPC_CARES_PROVIDER "module" CACHE STRING "Provider of c-ares library") |
| 105 | set_property(CACHE gRPC_CARES_PROVIDER PROPERTY STRINGS "module" "package") |
| 106 | |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 107 | set(gRPC_SSL_PROVIDER "module" CACHE STRING "Provider of ssl library") |
| 108 | set_property(CACHE gRPC_SSL_PROVIDER PROPERTY STRINGS "module" "package") |
Tamas Berghammer | a72712e | 2016-07-06 10:30:25 +0100 | [diff] [blame] | 109 | |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 110 | set(gRPC_PROTOBUF_PROVIDER "module" CACHE STRING "Provider of protobuf library") |
| 111 | set_property(CACHE gRPC_PROTOBUF_PROVIDER PROPERTY STRINGS "module" "package") |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 112 | |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 113 | set(gRPC_GFLAGS_PROVIDER "module" CACHE STRING "Provider of gflags library") |
| 114 | set_property(CACHE gRPC_GFLAGS_PROVIDER PROPERTY STRINGS "module" "package") |
Yuchen Zeng | e02cbeb | 2017-01-19 16:33:30 -0800 | [diff] [blame] | 115 | |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 116 | set(gRPC_BENCHMARK_PROVIDER "module" CACHE STRING "Provider of benchmark library") |
| 117 | set_property(CACHE gRPC_BENCHMARK_PROVIDER PROPERTY STRINGS "module" "package") |
Yuchen Zeng | 1492f6c | 2017-02-02 12:42:54 -0800 | [diff] [blame] | 118 | |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 119 | set(gRPC_USE_PROTO_LITE OFF CACHE BOOL "Use the protobuf-lite library") |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 120 | |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 121 | if(UNIX) |
| 122 | if(<%text>${CMAKE_SYSTEM_NAME}</%text> MATCHES "Linux") |
| 123 | set(_gRPC_PLATFORM_LINUX ON) |
| 124 | elseif(<%text>${CMAKE_SYSTEM_NAME}</%text> MATCHES "Darwin") |
| 125 | set(_gRPC_PLATFORM_MAC ON) |
| 126 | else() |
| 127 | set(_gRPC_PLATFORM_POSIX ON) |
| 128 | endif() |
| 129 | endif() |
| 130 | if(WIN32) |
| 131 | set(_gRPC_PLATFORM_WINDOWS ON) |
| 132 | endif() |
Yuchen Zeng | f39cf46 | 2017-02-10 13:01:25 -0800 | [diff] [blame] | 133 | |
Jan Tattermusch | c09656c | 2017-01-27 13:36:24 +0100 | [diff] [blame] | 134 | ## Some libraries are shared even with BUILD_SHARED_LIBRARIES=OFF |
| 135 | set(CMAKE_POSITION_INDEPENDENT_CODE TRUE) |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 136 | |
Arkadiy Shapkin | 40beb37 | 2016-08-17 14:42:36 +0300 | [diff] [blame] | 137 | if (MSVC) |
Jan Tattermusch | 5140791 | 2017-02-02 20:44:22 +0100 | [diff] [blame] | 138 | include(cmake/msvc_static_runtime.cmake) |
Jan Tattermusch | 3aab96f | 2017-01-11 16:12:46 +0100 | [diff] [blame] | 139 | add_definitions(-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS) |
Jan Tattermusch | 3aab96f | 2017-01-11 16:12:46 +0100 | [diff] [blame] | 140 | # needed to compile protobuf |
| 141 | add_definitions(/wd4065 /wd4506) |
| 142 | # TODO(jtattermusch): revisit C4267 occurrences throughout the code |
| 143 | add_definitions(/wd4267) |
Arkadiy Shapkin | 40beb37 | 2016-08-17 14:42:36 +0300 | [diff] [blame] | 144 | endif() |
| 145 | |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 146 | if (gRPC_USE_PROTO_LITE) |
| 147 | set(_gRPC_PROTOBUF_LIBRARY_NAME "libprotobuf-lite") |
Tamas Berghammer | 2391156 | 2016-07-27 15:24:05 +0100 | [diff] [blame] | 148 | add_definitions("-DGRPC_USE_PROTO_LITE") |
| 149 | else() |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 150 | set(_gRPC_PROTOBUF_LIBRARY_NAME "libprotobuf") |
| 151 | endif() |
| 152 | |
| 153 | if("<%text>${gRPC_ZLIB_PROVIDER}</%text>" STREQUAL "module") |
| 154 | if(NOT ZLIB_ROOT_DIR) |
| 155 | set(ZLIB_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/zlib) |
| 156 | endif() |
| 157 | set(ZLIB_INCLUDE_DIR "<%text>${ZLIB_ROOT_DIR}</%text>") |
| 158 | if(EXISTS "<%text>${ZLIB_ROOT_DIR}</%text>/CMakeLists.txt") |
| 159 | add_subdirectory(<%text>${ZLIB_ROOT_DIR}</%text> third_party/zlib) |
| 160 | if(TARGET zlibstatic) |
| 161 | set(_gRPC_ZLIB_LIBRARIES zlibstatic) |
| 162 | endif() |
| 163 | else() |
| 164 | message(WARNING "gRPC_ZLIB_PROVIDER is \"module\" but ZLIB_ROOT_DIR is wrong") |
| 165 | endif() |
| 166 | elseif("<%text>${gRPC_ZLIB_PROVIDER}</%text>" STREQUAL "package") |
| 167 | find_package(ZLIB) |
| 168 | if(TARGET ZLIB::ZLIB) |
| 169 | set(_gRPC_ZLIB_LIBRARIES ZLIB::ZLIB) |
| 170 | endif() |
Konstantin Podsvirov | dd33148 | 2016-07-28 00:00:25 +0300 | [diff] [blame] | 171 | set(_gRPC_FIND_ZLIB "if(NOT ZLIB_FOUND)\n find_package(ZLIB)\nendif()") |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 172 | endif() |
| 173 | |
Yuchen Zeng | 8076d2b | 2016-08-25 13:23:13 -0700 | [diff] [blame] | 174 | if("<%text>${gRPC_CARES_PROVIDER}</%text>" STREQUAL "module") |
| 175 | if(NOT CARES_ROOT_DIR) |
Yuchen Zeng | 7496218 | 2017-03-20 15:39:47 -0700 | [diff] [blame] | 176 | set(CARES_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/src/c-ares) |
Yuchen Zeng | 8076d2b | 2016-08-25 13:23:13 -0700 | [diff] [blame] | 177 | endif() |
Yuchen Zeng | c75bbf2 | 2017-03-20 12:35:20 -0700 | [diff] [blame] | 178 | string(TOLOWER <%text>${CMAKE_SYSTEM_NAME}</%text> CARES_SYSTEM_NAME) |
Yuchen Zeng | 7496218 | 2017-03-20 15:39:47 -0700 | [diff] [blame] | 179 | set(CARES_INCLUDE_DIR "<%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/cares/cares") |
| 180 | set(CARES_BUILD_INCLUDE_DIR "<%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/cares") |
Yuchen Zeng | c75bbf2 | 2017-03-20 12:35:20 -0700 | [diff] [blame] | 181 | set(CARES_PLATFORM_INCLUDE_DIR "<%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/cares/config_<%text>${CARES_SYSTEM_NAME}</%text>") |
Yuchen Zeng | 7496218 | 2017-03-20 15:39:47 -0700 | [diff] [blame] | 182 | if(EXISTS "<%text>${CARES_ROOT_DIR}</%text>/CMakeLists.txt") |
| 183 | if("<%text>${CARES_SYSTEM_NAME}</%text>" MATCHES "windows") |
| 184 | add_definitions(-DCARES_STATICLIB=1) |
| 185 | add_definitions(-DWIN32_LEAN_AND_MEAN=1) |
| 186 | else() |
| 187 | add_definitions(-DHAVE_CONFIG_H=1) |
| 188 | add_definitions(-D_GNU_SOURCE=1) |
| 189 | endif() |
| 190 | add_subdirectory(src/c-ares third_party/cares) |
| 191 | if(TARGET cares) |
| 192 | set(_gRPC_CARES_LIBRARIES cares) |
| 193 | endif() |
Yuchen Zeng | 8076d2b | 2016-08-25 13:23:13 -0700 | [diff] [blame] | 194 | else() |
Yuchen Zeng | 7496218 | 2017-03-20 15:39:47 -0700 | [diff] [blame] | 195 | message(WARNING "gRPC_CARES_PROVIDER is \"module\" but CARES_ROOT_DIR is wrong") |
Yuchen Zeng | 8076d2b | 2016-08-25 13:23:13 -0700 | [diff] [blame] | 196 | endif() |
| 197 | elseif("<%text>${gRPC_CARES_PROVIDER}</%text>" STREQUAL "package") |
| 198 | find_package(CARES) |
| 199 | if(TARGET CARES::CARES) |
| 200 | set(_gRPC_CARES_LIBRARIES CARES::CARES) |
| 201 | endif() |
| 202 | set(_gRPC_FIND_CARES "if(NOT CARES_FOUND)\n find_package(CARES)\nendif()") |
| 203 | endif() |
| 204 | |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 205 | if("<%text>${gRPC_PROTOBUF_PROVIDER}</%text>" STREQUAL "module") |
| 206 | # Building the protobuf tests require gmock what is not part of a standard protobuf checkout. |
| 207 | # Disable them unless they are explicitly requested from the cmake command line (when we assume |
| 208 | # gmock is downloaded to the right location inside protobuf). |
| 209 | if(NOT protobuf_BUILD_TESTS) |
| 210 | set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests") |
| 211 | endif() |
| 212 | if(NOT PROTOBUF_ROOT_DIR) |
| 213 | set(PROTOBUF_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/protobuf) |
| 214 | endif() |
yang-g | 66d40c6 | 2017-04-12 10:18:10 -0700 | [diff] [blame] | 215 | set(PROTOBUF_WELLKNOWN_IMPORT_DIR <%text>${PROTOBUF_ROOT_DIR}</%text>/src) |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 216 | if(EXISTS "<%text>${PROTOBUF_ROOT_DIR}</%text>/cmake/CMakeLists.txt") |
Arkadiy Shapkin | 40beb37 | 2016-08-17 14:42:36 +0300 | [diff] [blame] | 217 | set(protobuf_MSVC_STATIC_RUNTIME OFF CACHE BOOL "Link static runtime libraries") |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 218 | add_subdirectory(<%text>${PROTOBUF_ROOT_DIR}</%text>/cmake third_party/protobuf) |
| 219 | if(TARGET <%text>${_gRPC_PROTOBUF_LIBRARY_NAME}</%text>) |
| 220 | set(_gRPC_PROTOBUF_LIBRARIES <%text>${_gRPC_PROTOBUF_LIBRARY_NAME}</%text>) |
| 221 | endif() |
| 222 | if(TARGET libprotoc) |
| 223 | set(_gRPC_PROTOBUF_PROTOC_LIBRARIES libprotoc) |
| 224 | endif() |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 225 | if(TARGET protoc) |
| 226 | set(_gRPC_PROTOBUF_PROTOC protoc) |
| 227 | endif() |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 228 | else() |
| 229 | message(WARNING "gRPC_PROTOBUF_PROVIDER is \"module\" but PROTOBUF_ROOT_DIR is wrong") |
| 230 | endif() |
| 231 | elseif("<%text>${gRPC_PROTOBUF_PROVIDER}</%text>" STREQUAL "package") |
| 232 | find_package(protobuf CONFIG) |
| 233 | if(protobuf_FOUND) |
| 234 | if(TARGET protobuf::<%text>${_gRPC_PROTOBUF_LIBRARY_NAME}</%text>) |
| 235 | set(_gRPC_PROTOBUF_LIBRARIES protobuf::<%text>${_gRPC_PROTOBUF_LIBRARY_NAME}</%text>) |
| 236 | endif() |
| 237 | if(TARGET protobuf::libprotoc) |
| 238 | set(_gRPC_PROTOBUF_PROTOC_LIBRARIES protobuf::libprotoc) |
| 239 | endif() |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 240 | if(TARGET protobuf::protoc) |
| 241 | set(_gRPC_PROTOBUF_PROTOC protobuf::protoc) |
| 242 | endif() |
Konstantin Podsvirov | dd33148 | 2016-07-28 00:00:25 +0300 | [diff] [blame] | 243 | set(_gRPC_FIND_PROTOBUF "if(NOT protobuf_FOUND)\n find_package(protobuf CONFIG)\nendif()") |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 244 | else() |
| 245 | find_package(Protobuf MODULE) |
Konstantin Podsvirov | dd33148 | 2016-07-28 00:00:25 +0300 | [diff] [blame] | 246 | set(_gRPC_FIND_PROTOBUF "if(NOT Protobuf_FOUND)\n find_package(Protobuf)\nendif()") |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 247 | endif() |
yang-g | 66d40c6 | 2017-04-12 10:18:10 -0700 | [diff] [blame] | 248 | set(PROTOBUF_WELLKNOWN_IMPORT_DIR /usr/local/include) |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 249 | endif() |
| 250 | |
| 251 | if("<%text>${gRPC_SSL_PROVIDER}</%text>" STREQUAL "module") |
| 252 | if(NOT BORINGSSL_ROOT_DIR) |
| 253 | set(BORINGSSL_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/boringssl) |
| 254 | endif() |
| 255 | if(EXISTS "<%text>${BORINGSSL_ROOT_DIR}</%text>/CMakeLists.txt") |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 256 | set(OPENSSL_NO_ASM ON) # make boringssl buildable with Visual Studio |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 257 | add_subdirectory(<%text>${BORINGSSL_ROOT_DIR}</%text> third_party/boringssl) |
| 258 | if(TARGET ssl) |
| 259 | set(_gRPC_SSL_LIBRARIES ssl) |
| 260 | endif() |
| 261 | else() |
| 262 | message(WARNING "gRPC_SSL_PROVIDER is \"module\" but BORINGSSL_ROOT_DIR is wrong") |
| 263 | endif() |
| 264 | elseif("<%text>${gRPC_SSL_PROVIDER}</%text>" STREQUAL "package") |
| 265 | find_package(OpenSSL) |
| 266 | if(TARGET OpenSSL::SSL) |
| 267 | set(_gRPC_SSL_LIBRARIES OpenSSL::SSL) |
| 268 | endif() |
Konstantin Podsvirov | dd33148 | 2016-07-28 00:00:25 +0300 | [diff] [blame] | 269 | set(_gRPC_FIND_SSL "if(NOT OpenSSL_FOUND)\n find_package(OpenSSL)\nendif()") |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 270 | endif() |
| 271 | |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 272 | if("<%text>${gRPC_GFLAGS_PROVIDER}</%text>" STREQUAL "module") |
| 273 | if(NOT GFLAGS_ROOT_DIR) |
| 274 | set(GFLAGS_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/gflags) |
| 275 | endif() |
| 276 | if(EXISTS "<%text>${GFLAGS_ROOT_DIR}</%text>/CMakeLists.txt") |
| 277 | add_subdirectory(<%text>${GFLAGS_ROOT_DIR}</%text> third_party/gflags) |
Jan Tattermusch | 87a5d65 | 2017-01-18 16:22:40 +0100 | [diff] [blame] | 278 | if(TARGET gflags_static) |
| 279 | set(_gRPC_GFLAGS_LIBRARIES gflags_static) |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 280 | endif() |
| 281 | else() |
| 282 | message(WARNING "gRPC_GFLAGS_PROVIDER is \"module\" but GFLAGS_ROOT_DIR is wrong") |
| 283 | endif() |
| 284 | elseif("<%text>${gRPC_GFLAGS_PROVIDER}</%text>" STREQUAL "package") |
| 285 | find_package(gflags) |
| 286 | if(TARGET gflags::gflags) |
| 287 | set(_gRPC_GFLAGS_LIBRARIES gflags::gflags) |
| 288 | endif() |
| 289 | set(_gRPC_FIND_GFLAGS "if(NOT gflags_FOUND)\n find_package(gflags)\nendif()") |
| 290 | endif() |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 291 | |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 292 | if("<%text>${gRPC_BENCHMARK_PROVIDER}</%text>" STREQUAL "module") |
| 293 | if(NOT BENCHMARK_ROOT_DIR) |
| 294 | set(BENCHMARK_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/benchmark) |
| 295 | endif() |
| 296 | if(EXISTS "<%text>${BENCHMARK_ROOT_DIR}</%text>/CMakeLists.txt") |
| 297 | add_subdirectory(<%text>${BENCHMARK_ROOT_DIR}</%text> third_party/benchmark) |
| 298 | if(TARGET benchmark) |
| 299 | set(_gRPC_BENCHMARK_LIBRARIES benchmark) |
| 300 | endif() |
| 301 | else() |
| 302 | message(WARNING "gRPC_BENCHMARK_PROVIDER is \"module\" but BENCHMARK_ROOT_DIR is wrong") |
| 303 | endif() |
| 304 | elseif("<%text>${gRPC_BENCHMARK_PROVIDER}</%text>" STREQUAL "package") |
| 305 | find_package(benchmark) |
| 306 | if(TARGET benchmark::benchmark) |
| 307 | set(_gRPC_BENCHMARK_LIBRARIES benchmark::benchmark) |
| 308 | endif() |
| 309 | set(_gRPC_FIND_BENCHMARK "if(NOT benchmark_FOUND)\n find_package(benchmark)\nendif()") |
| 310 | endif() |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 311 | |
| 312 | if(NOT MSVC) |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 313 | set(CMAKE_C_FLAGS "<%text>${CMAKE_C_FLAGS}</%text> -std=c99") |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 314 | set(CMAKE_CXX_FLAGS "<%text>${CMAKE_CXX_FLAGS}</%text> -std=c++11") |
| 315 | endif() |
| 316 | |
Mehrdad Afshari | 79ec0ff | 2017-04-19 03:14:26 -0700 | [diff] [blame] | 317 | if(_gRPC_PLATFORM_MAC) |
| 318 | set(_gRPC_ALLTARGETS_LIBRARIES <%text>${CMAKE_DL_LIBS}</%text> m pthread) |
| 319 | elseif(UNIX) |
| 320 | set(_gRPC_ALLTARGETS_LIBRARIES <%text>${CMAKE_DL_LIBS}</%text> rt m pthread) |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 321 | endif() |
| 322 | |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 323 | if(WIN32 AND MSVC) |
| 324 | set(_gRPC_BASELIB_LIBRARIES wsock32 ws2_32) |
Tamas Berghammer | 2391156 | 2016-07-27 15:24:05 +0100 | [diff] [blame] | 325 | endif() |
| 326 | |
Konstantin Podsvirov | d2b8830 | 2016-07-27 23:43:47 +0300 | [diff] [blame] | 327 | include(GNUInstallDirs) |
| 328 | if(NOT DEFINED CMAKE_INSTALL_CMAKEDIR) |
| 329 | set(CMAKE_INSTALL_CMAKEDIR "<%text>${CMAKE_INSTALL_LIBDIR}</%text>/cmake/gRPC") |
| 330 | endif() |
| 331 | |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 332 | # Create directory for generated .proto files |
| 333 | set(_gRPC_PROTO_GENS_DIR <%text>${CMAKE_BINARY_DIR}/gens</%text>) |
| 334 | file(MAKE_DIRECTORY <%text>${_gRPC_PROTO_GENS_DIR}</%text>) |
Yuchen Zeng | e02cbeb | 2017-01-19 16:33:30 -0800 | [diff] [blame] | 335 | |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 336 | # protobuf_generate_grpc_cpp |
| 337 | # -------------------------- |
| 338 | # |
| 339 | # Add custom commands to process ``.proto`` files to C++ using protoc and |
| 340 | # GRPC plugin:: |
| 341 | # |
| 342 | # protobuf_generate_grpc_cpp [<ARGN>...] |
| 343 | # |
| 344 | # ``ARGN`` |
| 345 | # ``.proto`` files |
| 346 | # |
| 347 | function(protobuf_generate_grpc_cpp) |
| 348 | if(NOT ARGN) |
| 349 | message(SEND_ERROR "Error: PROTOBUF_GENERATE_GRPC_CPP() called without any proto files") |
| 350 | return() |
| 351 | endif() |
Yuchen Zeng | e02cbeb | 2017-01-19 16:33:30 -0800 | [diff] [blame] | 352 | |
yang-g | 66d40c6 | 2017-04-12 10:18:10 -0700 | [diff] [blame] | 353 | set(_protobuf_include_path -I . -I <%text>${PROTOBUF_WELLKNOWN_IMPORT_DIR}</%text>) |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 354 | foreach(FIL <%text>${ARGN}</%text>) |
| 355 | get_filename_component(ABS_FIL <%text>${FIL}</%text> ABSOLUTE) |
| 356 | get_filename_component(FIL_WE <%text>${FIL}</%text> NAME_WE) |
Jan Tattermusch | ecc457b | 2017-04-07 14:06:16 +0200 | [diff] [blame] | 357 | file(RELATIVE_PATH REL_FIL <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text> <%text>${ABS_FIL}</%text>) |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 358 | get_filename_component(REL_DIR <%text>${REL_FIL}</%text> DIRECTORY) |
| 359 | set(RELFIL_WE "<%text>${REL_DIR}/${FIL_WE}</%text>") |
Yuchen Zeng | e02cbeb | 2017-01-19 16:33:30 -0800 | [diff] [blame] | 360 | |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 361 | add_custom_command( |
| 362 | OUTPUT <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.cc"</%text> |
| 363 | <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.h"</%text> |
Mahak Mukhi | 78ca0d1 | 2017-04-26 13:39:46 -0700 | [diff] [blame] | 364 | <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}_mock.grpc.pb.h"</%text> |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 365 | <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.cc"</%text> |
| 366 | <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.h"</%text> |
| 367 | COMMAND <%text>${_gRPC_PROTOBUF_PROTOC}</%text> |
Mahak Mukhi | 78ca0d1 | 2017-04-26 13:39:46 -0700 | [diff] [blame] | 368 | ARGS --grpc_out=<%text>generate_mock_code=true:${_gRPC_PROTO_GENS_DIR}</%text> |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 369 | --cpp_out=<%text>${_gRPC_PROTO_GENS_DIR}</%text> |
| 370 | --plugin=protoc-gen-grpc=$<TARGET_FILE:grpc_cpp_plugin> |
| 371 | <%text>${_protobuf_include_path}</%text> |
| 372 | <%text>${REL_FIL}</%text> |
| 373 | DEPENDS <%text>${ABS_FIL}</%text> <%text>${_gRPC_PROTOBUF_PROTOC}</%text> grpc_cpp_plugin |
Jan Tattermusch | ecc457b | 2017-04-07 14:06:16 +0200 | [diff] [blame] | 374 | WORKING_DIRECTORY <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text> |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 375 | COMMENT "Running gRPC C++ protocol buffer compiler on <%text>${FIL}</%text>" |
| 376 | VERBATIM) |
Yuchen Zeng | e02cbeb | 2017-01-19 16:33:30 -0800 | [diff] [blame] | 377 | |
Mahak Mukhi | 78ca0d1 | 2017-04-26 13:39:46 -0700 | [diff] [blame] | 378 | <%text>set_source_files_properties("${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.cc" "${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.h" "${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}_mock.grpc.pb.h" "${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.cc" "${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.h" PROPERTIES GENERATED TRUE)</%text> |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 379 | endforeach() |
| 380 | endfunction() |
Yuchen Zeng | e02cbeb | 2017-01-19 16:33:30 -0800 | [diff] [blame] | 381 | |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 382 | add_custom_target(plugins |
| 383 | DEPENDS |
| 384 | % for tgt in targets: |
| 385 | % if tgt.build == 'protoc': |
| 386 | ${tgt.name} |
| 387 | % endif |
| 388 | % endfor |
| 389 | ) |
Yuchen Zeng | 1492f6c | 2017-02-02 12:42:54 -0800 | [diff] [blame] | 390 | |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 391 | add_custom_target(tools_c |
| 392 | DEPENDS |
| 393 | % for tgt in targets: |
| 394 | % if tgt.build == 'tool' and not tgt.language == 'c++': |
| 395 | ${tgt.name} |
| 396 | % endif |
| 397 | % endfor |
| 398 | ) |
Yuchen Zeng | 1492f6c | 2017-02-02 12:42:54 -0800 | [diff] [blame] | 399 | |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 400 | add_custom_target(tools_cxx |
| 401 | DEPENDS |
| 402 | % for tgt in targets: |
| 403 | % if tgt.build == 'tool' and tgt.language == 'c++': |
| 404 | ${tgt.name} |
| 405 | % endif |
| 406 | % endfor |
| 407 | ) |
Yuchen Zeng | 1492f6c | 2017-02-02 12:42:54 -0800 | [diff] [blame] | 408 | |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 409 | add_custom_target(tools |
| 410 | DEPENDS tools_c tools_cxx) |
Yuchen Zeng | 1492f6c | 2017-02-02 12:42:54 -0800 | [diff] [blame] | 411 | |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 412 | if (gRPC_BUILD_TESTS) |
| 413 | add_custom_target(buildtests_c) |
| 414 | % for tgt in targets: |
| 415 | % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl: |
| 416 | ${get_platforms_condition_begin(tgt.platforms)}\ |
| 417 | add_dependencies(buildtests_c ${tgt.name}) |
| 418 | ${get_platforms_condition_end(tgt.platforms)}\ |
| 419 | % endif |
| 420 | % endfor |
Yuchen Zeng | 1492f6c | 2017-02-02 12:42:54 -0800 | [diff] [blame] | 421 | |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 422 | add_custom_target(buildtests_cxx) |
| 423 | % for tgt in targets: |
| 424 | % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl: |
| 425 | ${get_platforms_condition_begin(tgt.platforms)}\ |
| 426 | add_dependencies(buildtests_cxx ${tgt.name}) |
| 427 | ${get_platforms_condition_end(tgt.platforms)}\ |
| 428 | % endif |
| 429 | % endfor |
Yuchen Zeng | 1492f6c | 2017-02-02 12:42:54 -0800 | [diff] [blame] | 430 | |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 431 | add_custom_target(buildtests |
| 432 | DEPENDS buildtests_c buildtests_cxx) |
| 433 | endif (gRPC_BUILD_TESTS) |
Yuchen Zeng | 1492f6c | 2017-02-02 12:42:54 -0800 | [diff] [blame] | 434 | |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 435 | % for lib in libs: |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 436 | % if lib.build in ["all", "protoc", "tool", "test", "private"] and not lib.boringssl: |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 437 | % if not lib.get('build_system', []) or 'cmake' in lib.get('build_system', []): |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 438 | % if not lib.name in ['benchmark', 'z']: # we build these using CMake instead |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 439 | % if lib.build in ["test", "private"]: |
| 440 | if (gRPC_BUILD_TESTS) |
| 441 | ${cc_library(lib)} |
| 442 | endif (gRPC_BUILD_TESTS) |
| 443 | % else: |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 444 | ${cc_library(lib)} |
| 445 | ${cc_install(lib)} |
Jan Tattermusch | af7b87f | 2017-01-12 09:41:03 +0100 | [diff] [blame] | 446 | % endif |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 447 | % endif |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 448 | % endif |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 449 | % endif |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 450 | % endfor |
| 451 | |
| 452 | % for tgt in targets: |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 453 | % if tgt.build in ["all", "protoc", "tool", "test", "private"] and not tgt.boringssl: |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 454 | % if tgt.build in ["test", "private"]: |
| 455 | if (gRPC_BUILD_TESTS) |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 456 | ${get_platforms_condition_begin(tgt.platforms)}\ |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 457 | ${cc_binary(tgt)} |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 458 | ${get_platforms_condition_end(tgt.platforms)}\ |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 459 | endif (gRPC_BUILD_TESTS) |
| 460 | % else: |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 461 | ${get_platforms_condition_begin(tgt.platforms)}\ |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 462 | ${cc_binary(tgt)} |
Konstantin Podsvirov | d2b8830 | 2016-07-27 23:43:47 +0300 | [diff] [blame] | 463 | ${cc_install(tgt)} |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 464 | ${get_platforms_condition_end(tgt.platforms)}\ |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 465 | % endif |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 466 | % endif |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 467 | % endfor |
| 468 | |
| 469 | <%def name="cc_library(lib)"> |
Jan Tattermusch | c09656c | 2017-01-27 13:36:24 +0100 | [diff] [blame] | 470 | add_library(${lib.name}${' SHARED' if lib.get('dll', None) == 'only' else ''} |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 471 | % for src in lib.src: |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 472 | % if not proto_re.match(src): |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 473 | ${src} |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 474 | % else: |
| 475 | ${proto_replace_ext(src, '.pb.cc')} |
| 476 | ${proto_replace_ext(src, '.grpc.pb.cc')} |
| 477 | ${proto_replace_ext(src, '.pb.h')} |
| 478 | ${proto_replace_ext(src, '.grpc.pb.h')} |
Mahak Mukhi | 78ca0d1 | 2017-04-26 13:39:46 -0700 | [diff] [blame] | 479 | % if src in ["src/proto/grpc/testing/compiler_test.proto", "src/proto/grpc/testing/echo.proto"]: |
| 480 | ${proto_replace_ext(src, '_mock.grpc.pb.h')} |
| 481 | % endif |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 482 | % endif |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 483 | % endfor |
| 484 | ) |
| 485 | |
Piotr Pietraszkiewicz | 9a61810 | 2017-02-06 19:30:09 +0100 | [diff] [blame] | 486 | if(WIN32 AND MSVC) |
| 487 | set_target_properties(${lib.name} PROPERTIES COMPILE_PDB_NAME "${lib.name}" |
| 488 | COMPILE_PDB_OUTPUT_DIRECTORY <%text>"${CMAKE_BINARY_DIR}</%text>" |
| 489 | ) |
| 490 | if (gRPC_INSTALL) |
| 491 | install(FILES <%text>${CMAKE_CURRENT_BINARY_DIR}/</%text>${lib.name}.pdb |
| 492 | DESTINATION <%text>${CMAKE_INSTALL_LIBDIR}</%text> OPTIONAL |
| 493 | ) |
| 494 | endif() |
| 495 | endif() |
| 496 | |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 497 | % for src in lib.src: |
| 498 | % if proto_re.match(src): |
| 499 | protobuf_generate_grpc_cpp( |
| 500 | ${src} |
| 501 | ) |
| 502 | % endif |
| 503 | % endfor |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 504 | |
| 505 | target_include_directories(${lib.name} |
| 506 | PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text> |
| 507 | PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/include |
| 508 | PRIVATE <%text>${BORINGSSL_ROOT_DIR}</%text>/include |
| 509 | PRIVATE <%text>${PROTOBUF_ROOT_DIR}</%text>/src |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 510 | PRIVATE <%text>${ZLIB_INCLUDE_DIR}</%text> |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 511 | PRIVATE <%text>${BENCHMARK}</%text>/include |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 512 | PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}</%text>/third_party/zlib |
Yuchen Zeng | 7496218 | 2017-03-20 15:39:47 -0700 | [diff] [blame] | 513 | PRIVATE <%text>${CARES_BUILD_INCLUDE_DIR}</%text> |
Yuchen Zeng | 8076d2b | 2016-08-25 13:23:13 -0700 | [diff] [blame] | 514 | PRIVATE <%text>${CARES_INCLUDE_DIR}</%text> |
Yuchen Zeng | c75bbf2 | 2017-03-20 12:35:20 -0700 | [diff] [blame] | 515 | PRIVATE <%text>${CARES_PLATFORM_INCLUDE_DIR}</%text> |
Yuchen Zeng | d6b4985 | 2017-03-20 01:44:27 -0700 | [diff] [blame] | 516 | PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}</%text>/third_party/cares/cares |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 517 | PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}</%text>/third_party/gflags/include |
| 518 | % if lib.build in ['test', 'private'] and lib.language == 'c++': |
Ken Payson | 975b510 | 2017-03-30 17:38:40 -0700 | [diff] [blame] | 519 | PRIVATE third_party/googletest/googletest/include |
| 520 | PRIVATE third_party/googletest/googletest |
Mahak Mukhi | 78ca0d1 | 2017-04-26 13:39:46 -0700 | [diff] [blame] | 521 | PRIVATE third_party/googletest/googlemock/include |
| 522 | PRIVATE third_party/googletest/googlemock |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 523 | % endif |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 524 | % if lib.language == 'c++': |
Jan Tattermusch | cc64168 | 2017-01-17 11:59:31 +0100 | [diff] [blame] | 525 | PRIVATE <%text>${_gRPC_PROTO_GENS_DIR}</%text> |
| 526 | % endif |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 527 | ) |
| 528 | |
| 529 | % if len(get_deps(lib)) > 0: |
| 530 | target_link_libraries(${lib.name} |
| 531 | % for dep in get_deps(lib): |
| 532 | ${dep} |
| 533 | % endfor |
| 534 | ) |
| 535 | % endif |
Konstantin Podsvirov | d2b8830 | 2016-07-27 23:43:47 +0300 | [diff] [blame] | 536 | |
| 537 | % if len(lib.get('public_headers', [])) > 0: |
| 538 | foreach(_hdr |
| 539 | % for hdr in lib.get('public_headers', []): |
| 540 | ${hdr} |
| 541 | % endfor |
| 542 | ) |
| 543 | string(REPLACE "include/" "" _path <%text>${_hdr}</%text>) |
| 544 | get_filename_component(_path <%text>${_path}</%text> PATH) |
| 545 | install(FILES <%text>${_hdr}</%text> |
| 546 | DESTINATION "<%text>${CMAKE_INSTALL_INCLUDEDIR}/${_path}</%text>" |
| 547 | ) |
| 548 | endforeach() |
| 549 | % endif |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 550 | </%def> |
| 551 | |
| 552 | <%def name="cc_binary(tgt)"> |
| 553 | add_executable(${tgt.name} |
| 554 | % for src in tgt.src: |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 555 | % if not proto_re.match(src): |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 556 | ${src} |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 557 | % else: |
| 558 | ${proto_replace_ext(src, '.pb.cc')} |
| 559 | ${proto_replace_ext(src, '.grpc.pb.cc')} |
| 560 | ${proto_replace_ext(src, '.pb.h')} |
| 561 | ${proto_replace_ext(src, '.grpc.pb.h')} |
| 562 | % endif |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 563 | % endfor |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 564 | % if tgt.build == 'test' and tgt.language == 'c++': |
Ken Payson | 975b510 | 2017-03-30 17:38:40 -0700 | [diff] [blame] | 565 | third_party/googletest/googletest/src/gtest-all.cc |
Mahak Mukhi | 78ca0d1 | 2017-04-26 13:39:46 -0700 | [diff] [blame] | 566 | third_party/googletest/googlemock/src/gmock-all.cc |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 567 | % endif |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 568 | ) |
| 569 | |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 570 | % for src in tgt.src: |
| 571 | % if proto_re.match(src): |
| 572 | protobuf_generate_grpc_cpp( |
| 573 | ${src} |
| 574 | ) |
| 575 | % endif |
| 576 | % endfor |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 577 | |
| 578 | target_include_directories(${tgt.name} |
| 579 | PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text> |
| 580 | PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/include |
| 581 | PRIVATE <%text>${BORINGSSL_ROOT_DIR}</%text>/include |
| 582 | PRIVATE <%text>${PROTOBUF_ROOT_DIR}</%text>/src |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 583 | PRIVATE <%text>${BENCHMARK_ROOT_DIR}</%text>/include |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 584 | PRIVATE <%text>${ZLIB_ROOT_DIR}</%text> |
| 585 | PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}</%text>/third_party/zlib |
Yuchen Zeng | 7496218 | 2017-03-20 15:39:47 -0700 | [diff] [blame] | 586 | PRIVATE <%text>${CARES_BUILD_INCLUDE_DIR}</%text> |
Yuchen Zeng | c75bbf2 | 2017-03-20 12:35:20 -0700 | [diff] [blame] | 587 | PRIVATE <%text>${CARES_INCLUDE_DIR}</%text> |
| 588 | PRIVATE <%text>${CARES_PLATFORM_INCLUDE_DIR}</%text> |
| 589 | PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}</%text>/third_party/cares/cares |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 590 | PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}</%text>/third_party/gflags/include |
| 591 | % if tgt.build in ['test', 'private'] and tgt.language == 'c++': |
Ken Payson | 975b510 | 2017-03-30 17:38:40 -0700 | [diff] [blame] | 592 | PRIVATE third_party/googletest/googletest/include |
| 593 | PRIVATE third_party/googletest/googletest |
Mahak Mukhi | 78ca0d1 | 2017-04-26 13:39:46 -0700 | [diff] [blame] | 594 | PRIVATE third_party/googletest/googlemock/include |
| 595 | PRIVATE third_party/googletest/googlemock |
Jan Tattermusch | 0a1701f | 2017-01-17 19:44:08 +0100 | [diff] [blame] | 596 | % endif |
Jan Tattermusch | 438c0b5 | 2017-01-23 11:24:53 +0100 | [diff] [blame] | 597 | % if tgt.language == 'c++': |
| 598 | PRIVATE <%text>${_gRPC_PROTO_GENS_DIR}</%text> |
| 599 | % endif |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 600 | ) |
| 601 | |
| 602 | % if len(get_deps(tgt)) > 0: |
| 603 | target_link_libraries(${tgt.name} |
| 604 | % for dep in get_deps(tgt): |
| 605 | ${dep} |
| 606 | % endfor |
| 607 | ) |
| 608 | % endif |
| 609 | </%def> |
| 610 | |
Konstantin Podsvirov | d2b8830 | 2016-07-27 23:43:47 +0300 | [diff] [blame] | 611 | <%def name="cc_install(tgt)"> |
Arkadiy Shapkin | 40beb37 | 2016-08-17 14:42:36 +0300 | [diff] [blame] | 612 | if (gRPC_INSTALL) |
| 613 | install(TARGETS ${tgt.name} EXPORT gRPCTargets |
| 614 | RUNTIME DESTINATION <%text>${CMAKE_INSTALL_BINDIR}</%text> |
| 615 | LIBRARY DESTINATION <%text>${CMAKE_INSTALL_LIBDIR}</%text> |
| 616 | ARCHIVE DESTINATION <%text>${CMAKE_INSTALL_LIBDIR}</%text> |
| 617 | ) |
| 618 | endif() |
Konstantin Podsvirov | d2b8830 | 2016-07-27 23:43:47 +0300 | [diff] [blame] | 619 | </%def> |
| 620 | |
Konstantin Podsvirov | d2b8830 | 2016-07-27 23:43:47 +0300 | [diff] [blame] | 621 | foreach(_config gRPCConfig gRPCConfigVersion) |
| 622 | configure_file(tools/cmake/<%text>${_config}</%text>.cmake.in |
| 623 | <%text>${_config}</%text>.cmake @ONLY) |
| 624 | install(FILES <%text>${CMAKE_CURRENT_BINARY_DIR}/${_config}</%text>.cmake |
| 625 | DESTINATION <%text>${CMAKE_INSTALL_CMAKEDIR}</%text> |
| 626 | ) |
| 627 | endforeach() |