blob: de13d02e2a399be13bcabc6f980019c37292434d [file] [log] [blame]
Tamas Berghammerd798a7d2016-06-21 13:58:18 +01001%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" Nobleb360c8a2016-07-02 00:54:28 +02009 #
Jan Tattermusch4d5c3102017-06-07 10:23:56 +020010 # Copyright 2015 gRPC authors.
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010011 #
Jan Tattermusch4d5c3102017-06-07 10:23:56 +020012 # Licensed under the Apache License, Version 2.0 (the "License");
13 # you may not use this file except in compliance with the License.
14 # You may obtain a copy of the License at
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010015 #
Jan Tattermusch4d5c3102017-06-07 10:23:56 +020016 # http://www.apache.org/licenses/LICENSE-2.0
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010017 #
Jan Tattermusch4d5c3102017-06-07 10:23:56 +020018 # Unless required by applicable law or agreed to in writing, software
19 # distributed under the License is distributed on an "AS IS" BASIS,
20 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21 # See the License for the specific language governing permissions and
22 # limitations under the License.
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010023
24 <%!
Yuchen Zenge02cbeb2017-01-19 16:33:30 -080025
Jan Tattermuschcc641682017-01-17 11:59:31 +010026 import re
Yuchen Zenge02cbeb2017-01-19 16:33:30 -080027
Jan Tattermuschcc641682017-01-17 11:59:31 +010028 proto_re = re.compile('(.*)\\.proto')
Yuchen Zenge02cbeb2017-01-19 16:33:30 -080029
Jan Tattermuschcc641682017-01-17 11:59:31 +010030 def proto_replace_ext(filename, ext):
31 m = proto_re.match(filename)
32 if not m:
33 return filename
34 return '${_gRPC_PROTO_GENS_DIR}/' + m.group(1) + ext
Yuchen Zenge02cbeb2017-01-19 16:33:30 -080035
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010036 def get_deps(target_dict):
37 deps = []
Alexander Polcyn18caf6d2018-06-06 12:06:52 -070038 if target_dict.get('baselib', False) or target_dict['name'] == 'address_sorting':
Konstantin Podsvirov5baf7252016-07-27 16:25:37 +030039 deps.append("${_gRPC_BASELIB_LIBRARIES}")
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010040 if target_dict.get('build', None) in ['protoc']:
Konstantin Podsvirov5baf7252016-07-27 16:25:37 +030041 deps.append("${_gRPC_PROTOBUF_PROTOC_LIBRARIES}")
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010042 if target_dict.get('secure', False):
Konstantin Podsvirov5baf7252016-07-27 16:25:37 +030043 deps.append("${_gRPC_SSL_LIBRARIES}")
Jan Tattermusch438c0b52017-01-23 11:24:53 +010044 if target_dict.language == 'c++':
Konstantin Podsvirov5baf7252016-07-27 16:25:37 +030045 deps.append("${_gRPC_PROTOBUF_LIBRARIES}")
Jan Tattermusch807693b2017-06-12 10:15:27 +020046 if target_dict['name'] in ['grpc', 'grpc_cronet', 'grpc_unsecure']:
Konstantin Podsvirov5baf7252016-07-27 16:25:37 +030047 deps.append("${_gRPC_ZLIB_LIBRARIES}")
Yuchen Zeng8076d2b2016-08-25 13:23:13 -070048 deps.append("${_gRPC_CARES_LIBRARIES}")
Alexander Polcyn690dde62017-10-18 00:20:33 -070049 deps.append("${_gRPC_ADDRESS_SORTING_LIBRARIES}")
Jan Tattermusch438c0b52017-01-23 11:24:53 +010050 deps.append("${_gRPC_ALLTARGETS_LIBRARIES}")
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010051 for d in target_dict.get('deps', []):
Jan Tattermusch586f7192018-01-16 17:57:17 +010052 if d == 'benchmark':
53 deps.append("${_gRPC_BENCHMARK_LIBRARIES}")
54 else:
55 deps.append(d)
Jan Tattermusch0a1701f2017-01-17 19:44:08 +010056 if target_dict.build == 'test' and target_dict.language == 'c++':
57 deps.append("${_gRPC_GFLAGS_LIBRARIES}")
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010058 return deps
Yuchen Zeng1492f6c2017-02-02 12:42:54 -080059
Jan Tattermusch438c0b52017-01-23 11:24:53 +010060 def get_platforms_condition_begin(platforms):
61 if all(platform in platforms for platform in ['linux', 'mac', 'posix', 'windows']):
62 return ''
63 cond = ' OR '.join(['_gRPC_PLATFORM_%s' % platform.upper() for platform in platforms])
64 return 'if(%s)\n' % cond
Yuchen Zeng1492f6c2017-02-02 12:42:54 -080065
Jan Tattermusch438c0b52017-01-23 11:24:53 +010066 def get_platforms_condition_end(platforms):
67 if not get_platforms_condition_begin(platforms):
68 return ''
69 return 'endif()\n'
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010070 %>
71
72 cmake_minimum_required(VERSION 2.8)
73
Tamas Berghammerdf6a44c2016-06-22 13:38:55 +010074 set(PACKAGE_NAME "grpc")
Craig Tiller83c47892016-09-13 11:14:43 -070075 set(PACKAGE_VERSION "${settings.cpp_version}")
Tamas Berghammerdf6a44c2016-06-22 13:38:55 +010076 set(PACKAGE_STRING "<%text>${PACKAGE_NAME} ${PACKAGE_VERSION}</%text>")
77 set(PACKAGE_TARNAME "<%text>${PACKAGE_NAME}-${PACKAGE_VERSION}</%text>")
78 set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/")
79 project(<%text>${PACKAGE_NAME}</%text> C CXX)
Craig Tiller4e86af72017-10-10 23:24:14 -070080
Stefan Hacker471a5dc2018-01-14 13:38:20 +010081 set(gRPC_INSTALL_BINDIR "bin" CACHE STRING "Installation directory for executables")
82 set(gRPC_INSTALL_LIBDIR "lib" CACHE STRING "Installation directory for libraries")
83 set(gRPC_INSTALL_INCLUDEDIR "include" CACHE STRING "Installation directory for headers")
84 set(gRPC_INSTALL_CMAKEDIR "lib/cmake/<%text>${PACKAGE_NAME}</%text>" CACHE STRING "Installation directory for cmake config files")
Jan Tattermuscha3992d22018-05-09 17:37:27 +020085 set(gRPC_INSTALL_SHAREDIR "share/grpc" CACHE STRING "Installation directory for root certificates")
Tamas Berghammerdf6a44c2016-06-22 13:38:55 +010086
Jan Tattermusch0a1701f2017-01-17 19:44:08 +010087 # Options
88 option(gRPC_BUILD_TESTS "Build tests" OFF)
Eric Gribkoffa32a4c52018-01-25 13:16:41 -080089 option(gRPC_BUILD_CODEGEN "Build codegen" ON)
Jozef Izsobbdee162018-04-26 17:39:17 +020090 option(gRPC_BUILD_CSHARP_EXT "Build C# extensions" ON)
Tamas Berghammerdf6a44c2016-06-22 13:38:55 +010091
Alex Merryc17eb5c2017-05-15 21:17:29 +010092 set(gRPC_INSTALL_default ON)
Alex Merrya65f0062017-05-15 22:59:37 +010093 if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
94 # Disable gRPC_INSTALL by default if building as a submodule
95 set(gRPC_INSTALL_default OFF)
Arkadiy Shapkin40beb372016-08-17 14:42:36 +030096 endif()
Alex Merryc17eb5c2017-05-15 21:17:29 +010097 set(gRPC_INSTALL <%text>${gRPC_INSTALL_default}</%text> CACHE BOOL
98 "Generate installation target: gRPC_ZLIB_PROVIDER, gRPC_CARES_PROVIDER, gRPC_SSL_PROVIDER and gRPC_PROTOBUF_PROVIDER must all be \"package\"")
Arkadiy Shapkin40beb372016-08-17 14:42:36 +030099
Jan Tattermusch586f7192018-01-16 17:57:17 +0100100 # Providers for third-party dependencies (gRPC_*_PROVIDER properties):
101 # "module": build the dependency using sources from git submodule (under third_party)
102 # "package": use cmake's find_package functionality to locate a pre-installed dependency
103
Konstantin Podsvirov5baf7252016-07-27 16:25:37 +0300104 set(gRPC_ZLIB_PROVIDER "module" CACHE STRING "Provider of zlib library")
105 set_property(CACHE gRPC_ZLIB_PROVIDER PROPERTY STRINGS "module" "package")
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100106
Yuchen Zeng8076d2b2016-08-25 13:23:13 -0700107 set(gRPC_CARES_PROVIDER "module" CACHE STRING "Provider of c-ares library")
108 set_property(CACHE gRPC_CARES_PROVIDER PROPERTY STRINGS "module" "package")
109
Konstantin Podsvirov5baf7252016-07-27 16:25:37 +0300110 set(gRPC_SSL_PROVIDER "module" CACHE STRING "Provider of ssl library")
111 set_property(CACHE gRPC_SSL_PROVIDER PROPERTY STRINGS "module" "package")
Tamas Berghammera72712e2016-07-06 10:30:25 +0100112
Konstantin Podsvirov5baf7252016-07-27 16:25:37 +0300113 set(gRPC_PROTOBUF_PROVIDER "module" CACHE STRING "Provider of protobuf library")
114 set_property(CACHE gRPC_PROTOBUF_PROVIDER PROPERTY STRINGS "module" "package")
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100115
Kamil Skalski6ba7d532017-06-28 19:42:26 +0100116 set(gRPC_PROTOBUF_PACKAGE_TYPE "" CACHE STRING "Algorithm for searching protobuf package")
117 set_property(CACHE gRPC_PROTOBUF_PACKAGE_TYPE PROPERTY STRINGS "CONFIG" "MODULE")
118
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100119 set(gRPC_GFLAGS_PROVIDER "module" CACHE STRING "Provider of gflags library")
120 set_property(CACHE gRPC_GFLAGS_PROVIDER PROPERTY STRINGS "module" "package")
Yuchen Zenge02cbeb2017-01-19 16:33:30 -0800121
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100122 set(gRPC_BENCHMARK_PROVIDER "module" CACHE STRING "Provider of benchmark library")
123 set_property(CACHE gRPC_BENCHMARK_PROVIDER PROPERTY STRINGS "module" "package")
Yuchen Zeng1492f6c2017-02-02 12:42:54 -0800124
Konstantin Podsvirov5baf7252016-07-27 16:25:37 +0300125 set(gRPC_USE_PROTO_LITE OFF CACHE BOOL "Use the protobuf-lite library")
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100126
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100127 if(UNIX)
128 if(<%text>${CMAKE_SYSTEM_NAME}</%text> MATCHES "Linux")
129 set(_gRPC_PLATFORM_LINUX ON)
130 elseif(<%text>${CMAKE_SYSTEM_NAME}</%text> MATCHES "Darwin")
131 set(_gRPC_PLATFORM_MAC ON)
Eric Gribkoffa32a4c52018-01-25 13:16:41 -0800132 elseif(<%text>${CMAKE_SYSTEM_NAME}</%text> MATCHES "Android")
133 set(_gRPC_PLATFORM_ANDROID ON)
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100134 else()
135 set(_gRPC_PLATFORM_POSIX ON)
136 endif()
137 endif()
138 if(WIN32)
139 set(_gRPC_PLATFORM_WINDOWS ON)
140 endif()
Yuchen Zengf39cf462017-02-10 13:01:25 -0800141
Jan Tattermuschc09656c2017-01-27 13:36:24 +0100142 ## Some libraries are shared even with BUILD_SHARED_LIBRARIES=OFF
143 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
Yihua Zhang04fb58e2018-03-08 06:49:24 -0800144
145 add_definitions(-DPB_FIELD_16BIT)
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100146
Arkadiy Shapkin40beb372016-08-17 14:42:36 +0300147 if (MSVC)
Jan Tattermusch51407912017-02-02 20:44:22 +0100148 include(cmake/msvc_static_runtime.cmake)
Jan Tattermusch3aab96f2017-01-11 16:12:46 +0100149 add_definitions(-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS)
Jan Tattermusch3aab96f2017-01-11 16:12:46 +0100150 # needed to compile protobuf
151 add_definitions(/wd4065 /wd4506)
152 # TODO(jtattermusch): revisit C4267 occurrences throughout the code
153 add_definitions(/wd4267)
Jan Tattermusch07d20922017-08-23 16:05:43 +0200154 # TODO(jtattermusch): needed to build boringssl with VS2017, revisit later
155 add_definitions(/wd4987 /wd4774 /wd4819 /wd4996 /wd4619)
Arkadiy Shapkin40beb372016-08-17 14:42:36 +0300156 endif()
157
Konstantin Podsvirov5baf7252016-07-27 16:25:37 +0300158 if (gRPC_USE_PROTO_LITE)
159 set(_gRPC_PROTOBUF_LIBRARY_NAME "libprotobuf-lite")
Tamas Berghammer23911562016-07-27 15:24:05 +0100160 add_definitions("-DGRPC_USE_PROTO_LITE")
161 else()
Konstantin Podsvirov5baf7252016-07-27 16:25:37 +0300162 set(_gRPC_PROTOBUF_LIBRARY_NAME "libprotobuf")
163 endif()
164
Jan Tattermuschf38b1522017-12-19 14:05:41 -0800165 include(cmake/zlib.cmake)
166 include(cmake/cares.cmake)
167 include(cmake/protobuf.cmake)
168 include(cmake/ssl.cmake)
169 include(cmake/gflags.cmake)
170 include(cmake/benchmark.cmake)
Alexander Polcyn5de34782018-01-19 14:48:19 -0800171 include(cmake/address_sorting.cmake)
David Garcia Quintas7f947022018-06-04 16:45:06 -0700172 include(cmake/nanopb.cmake)
Alexander Polcyn690dde62017-10-18 00:20:33 -0700173
Konstantin Podsvirov5baf7252016-07-27 16:25:37 +0300174 if(NOT MSVC)
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100175 set(CMAKE_C_FLAGS "<%text>${CMAKE_C_FLAGS}</%text> -std=c99")
Konstantin Podsvirov5baf7252016-07-27 16:25:37 +0300176 set(CMAKE_CXX_FLAGS "<%text>${CMAKE_CXX_FLAGS}</%text> -std=c++11")
177 endif()
178
Mehrdad Afshari79ec0ff2017-04-19 03:14:26 -0700179 if(_gRPC_PLATFORM_MAC)
180 set(_gRPC_ALLTARGETS_LIBRARIES <%text>${CMAKE_DL_LIBS}</%text> m pthread)
Eric Gribkoffa32a4c52018-01-25 13:16:41 -0800181 elseif(_gRPC_PLATFORM_ANDROID)
182 set(_gRPC_ALLTARGETS_LIBRARIES <%text>${CMAKE_DL_LIBS}</%text> m)
Mehrdad Afshari79ec0ff2017-04-19 03:14:26 -0700183 elseif(UNIX)
184 set(_gRPC_ALLTARGETS_LIBRARIES <%text>${CMAKE_DL_LIBS}</%text> rt m pthread)
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100185 endif()
186
Konstantin Podsvirov5baf7252016-07-27 16:25:37 +0300187 if(WIN32 AND MSVC)
188 set(_gRPC_BASELIB_LIBRARIES wsock32 ws2_32)
Tamas Berghammer23911562016-07-27 15:24:05 +0100189 endif()
190
Jan Tattermuschcc641682017-01-17 11:59:31 +0100191 # Create directory for generated .proto files
192 set(_gRPC_PROTO_GENS_DIR <%text>${CMAKE_BINARY_DIR}/gens</%text>)
193 file(MAKE_DIRECTORY <%text>${_gRPC_PROTO_GENS_DIR}</%text>)
Yuchen Zenge02cbeb2017-01-19 16:33:30 -0800194
Jan Tattermuschcc641682017-01-17 11:59:31 +0100195 # protobuf_generate_grpc_cpp
196 # --------------------------
197 #
198 # Add custom commands to process ``.proto`` files to C++ using protoc and
199 # GRPC plugin::
200 #
201 # protobuf_generate_grpc_cpp [<ARGN>...]
202 #
203 # ``ARGN``
204 # ``.proto`` files
205 #
206 function(protobuf_generate_grpc_cpp)
207 if(NOT ARGN)
208 message(SEND_ERROR "Error: PROTOBUF_GENERATE_GRPC_CPP() called without any proto files")
209 return()
210 endif()
Yuchen Zenge02cbeb2017-01-19 16:33:30 -0800211
Jan Tattermusch586f7192018-01-16 17:57:17 +0100212 set(_protobuf_include_path -I . -I <%text>${_gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR}</%text>)
Jan Tattermuschcc641682017-01-17 11:59:31 +0100213 foreach(FIL <%text>${ARGN}</%text>)
214 get_filename_component(ABS_FIL <%text>${FIL}</%text> ABSOLUTE)
215 get_filename_component(FIL_WE <%text>${FIL}</%text> NAME_WE)
Jan Tattermuschecc457b2017-04-07 14:06:16 +0200216 file(RELATIVE_PATH REL_FIL <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text> <%text>${ABS_FIL}</%text>)
Jan Tattermuschcc641682017-01-17 11:59:31 +0100217 get_filename_component(REL_DIR <%text>${REL_FIL}</%text> DIRECTORY)
218 set(RELFIL_WE "<%text>${REL_DIR}/${FIL_WE}</%text>")
Yuchen Zenge02cbeb2017-01-19 16:33:30 -0800219
Jan Tattermuschcc641682017-01-17 11:59:31 +0100220 add_custom_command(
221 OUTPUT <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.cc"</%text>
222 <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.h"</%text>
Mahak Mukhi78ca0d12017-04-26 13:39:46 -0700223 <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}_mock.grpc.pb.h"</%text>
Jan Tattermuschcc641682017-01-17 11:59:31 +0100224 <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.cc"</%text>
225 <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.h"</%text>
Jan Tattermusch210f2a52017-08-24 17:51:47 +0200226 COMMAND <%text>${_gRPC_PROTOBUF_PROTOC_EXECUTABLE}</%text>
Mahak Mukhi78ca0d12017-04-26 13:39:46 -0700227 ARGS --grpc_out=<%text>generate_mock_code=true:${_gRPC_PROTO_GENS_DIR}</%text>
Jan Tattermuschcc641682017-01-17 11:59:31 +0100228 --cpp_out=<%text>${_gRPC_PROTO_GENS_DIR}</%text>
229 --plugin=protoc-gen-grpc=$<TARGET_FILE:grpc_cpp_plugin>
230 <%text>${_protobuf_include_path}</%text>
231 <%text>${REL_FIL}</%text>
232 DEPENDS <%text>${ABS_FIL}</%text> <%text>${_gRPC_PROTOBUF_PROTOC}</%text> grpc_cpp_plugin
Jan Tattermuschecc457b2017-04-07 14:06:16 +0200233 WORKING_DIRECTORY <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>
Jan Tattermuschcc641682017-01-17 11:59:31 +0100234 COMMENT "Running gRPC C++ protocol buffer compiler on <%text>${FIL}</%text>"
235 VERBATIM)
Yuchen Zenge02cbeb2017-01-19 16:33:30 -0800236
Mahak Mukhi78ca0d12017-04-26 13:39:46 -0700237 <%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 Tattermuschcc641682017-01-17 11:59:31 +0100238 endforeach()
239 endfunction()
Yuchen Zenge02cbeb2017-01-19 16:33:30 -0800240
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100241 add_custom_target(plugins
242 DEPENDS
243 % for tgt in targets:
244 % if tgt.build == 'protoc':
245 ${tgt.name}
246 % endif
247 % endfor
248 )
Yuchen Zeng1492f6c2017-02-02 12:42:54 -0800249
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100250 add_custom_target(tools_c
251 DEPENDS
252 % for tgt in targets:
253 % if tgt.build == 'tool' and not tgt.language == 'c++':
254 ${tgt.name}
255 % endif
256 % endfor
257 )
Yuchen Zeng1492f6c2017-02-02 12:42:54 -0800258
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100259 add_custom_target(tools_cxx
260 DEPENDS
261 % for tgt in targets:
262 % if tgt.build == 'tool' and tgt.language == 'c++':
263 ${tgt.name}
264 % endif
265 % endfor
266 )
Yuchen Zeng1492f6c2017-02-02 12:42:54 -0800267
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100268 add_custom_target(tools
269 DEPENDS tools_c tools_cxx)
Yuchen Zeng1492f6c2017-02-02 12:42:54 -0800270
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100271 if (gRPC_BUILD_TESTS)
272 add_custom_target(buildtests_c)
273 % for tgt in targets:
274 % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
275 ${get_platforms_condition_begin(tgt.platforms)}\
276 add_dependencies(buildtests_c ${tgt.name})
277 ${get_platforms_condition_end(tgt.platforms)}\
278 % endif
279 % endfor
Yuchen Zeng1492f6c2017-02-02 12:42:54 -0800280
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100281 add_custom_target(buildtests_cxx)
282 % for tgt in targets:
283 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
284 ${get_platforms_condition_begin(tgt.platforms)}\
285 add_dependencies(buildtests_cxx ${tgt.name})
286 ${get_platforms_condition_end(tgt.platforms)}\
287 % endif
288 % endfor
Yuchen Zeng1492f6c2017-02-02 12:42:54 -0800289
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100290 add_custom_target(buildtests
291 DEPENDS buildtests_c buildtests_cxx)
292 endif (gRPC_BUILD_TESTS)
Yuchen Zeng1492f6c2017-02-02 12:42:54 -0800293
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100294 % for lib in libs:
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100295 % if lib.build in ["all", "protoc", "tool", "test", "private"] and not lib.boringssl:
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100296 % if not lib.get('build_system', []) or 'cmake' in lib.get('build_system', []):
Jan Tattermusch3fc14dc2017-12-14 01:03:37 +0100297 % if not lib.name in ['ares', 'benchmark', 'z']: # we build these using CMake instead
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100298 % if lib.build in ["test", "private"]:
299 if (gRPC_BUILD_TESTS)
300 ${cc_library(lib)}
301 endif (gRPC_BUILD_TESTS)
Jozef Izsobbdee162018-04-26 17:39:17 +0200302 % elif lib.name in ['grpc_csharp_ext']:
303 if (gRPC_BUILD_CSHARP_EXT)
304 ${cc_library(lib)}
305 ${cc_install(lib)}
306 endif (gRPC_BUILD_CSHARP_EXT)
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100307 % else:
Jan Tattermuschcc641682017-01-17 11:59:31 +0100308 ${cc_library(lib)}
Vijay Paic4cc7402018-03-28 11:25:37 -0700309 % if not lib.build in ["tool"]:
Jan Tattermuschcc641682017-01-17 11:59:31 +0100310 ${cc_install(lib)}
Jan Tattermuschaf7b87f2017-01-12 09:41:03 +0100311 % endif
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100312 % endif
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100313 % endif
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100314 % endif
Vijay Paic4cc7402018-03-28 11:25:37 -0700315 % endif
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100316 % endfor
317
318 % for tgt in targets:
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100319 % if tgt.build in ["all", "protoc", "tool", "test", "private"] and not tgt.boringssl:
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100320 % if tgt.build in ["test", "private"]:
321 if (gRPC_BUILD_TESTS)
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100322 ${get_platforms_condition_begin(tgt.platforms)}\
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100323 ${cc_binary(tgt)}
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100324 ${get_platforms_condition_end(tgt.platforms)}\
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100325 endif (gRPC_BUILD_TESTS)
Eric Gribkoffa32a4c52018-01-25 13:16:41 -0800326 % elif tgt.build in ["protoc"]:
327 if (gRPC_BUILD_CODEGEN)
328 ${get_platforms_condition_begin(tgt.platforms)}\
329 ${cc_binary(tgt)}
330 ${cc_install(tgt)}
331 ${get_platforms_condition_end(tgt.platforms)}\
332 endif (gRPC_BUILD_CODEGEN)
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100333 % else:
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100334 ${get_platforms_condition_begin(tgt.platforms)}\
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100335 ${cc_binary(tgt)}
Vijay Paic4cc7402018-03-28 11:25:37 -0700336 % if not tgt.build in ["tool"]:
Konstantin Podsvirovd2b88302016-07-27 23:43:47 +0300337 ${cc_install(tgt)}
Vijay Paic4cc7402018-03-28 11:25:37 -0700338 % endif
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100339 ${get_platforms_condition_end(tgt.platforms)}\
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100340 % endif
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100341 % endif
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100342 % endfor
343
344 <%def name="cc_library(lib)">
Eric Gribkoffa32a4c52018-01-25 13:16:41 -0800345 % if any(proto_re.match(src) for src in lib.src):
346 if (gRPC_BUILD_CODEGEN)
347 % endif
Jan Tattermuschc09656c2017-01-27 13:36:24 +0100348 add_library(${lib.name}${' SHARED' if lib.get('dll', None) == 'only' else ''}
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100349 % for src in lib.src:
Jan Tattermuschcc641682017-01-17 11:59:31 +0100350 % if not proto_re.match(src):
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100351 ${src}
Jan Tattermuschcc641682017-01-17 11:59:31 +0100352 % else:
353 ${proto_replace_ext(src, '.pb.cc')}
354 ${proto_replace_ext(src, '.grpc.pb.cc')}
355 ${proto_replace_ext(src, '.pb.h')}
356 ${proto_replace_ext(src, '.grpc.pb.h')}
Mahak Mukhi78ca0d12017-04-26 13:39:46 -0700357 % if src in ["src/proto/grpc/testing/compiler_test.proto", "src/proto/grpc/testing/echo.proto"]:
358 ${proto_replace_ext(src, '_mock.grpc.pb.h')}
359 % endif
Jan Tattermuschcc641682017-01-17 11:59:31 +0100360 % endif
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100361 % endfor
362 )
363
Piotr Pietraszkiewicz9a618102017-02-06 19:30:09 +0100364 if(WIN32 AND MSVC)
365 set_target_properties(${lib.name} PROPERTIES COMPILE_PDB_NAME "${lib.name}"
366 COMPILE_PDB_OUTPUT_DIRECTORY <%text>"${CMAKE_BINARY_DIR}</%text>"
367 )
368 if (gRPC_INSTALL)
369 install(FILES <%text>${CMAKE_CURRENT_BINARY_DIR}/</%text>${lib.name}.pdb
Jan Tattermuschf6915562017-06-23 14:53:55 +0200370 DESTINATION <%text>${gRPC_INSTALL_LIBDIR}</%text> OPTIONAL
Piotr Pietraszkiewicz9a618102017-02-06 19:30:09 +0100371 )
372 endif()
373 endif()
374
Jan Tattermuschcc641682017-01-17 11:59:31 +0100375 % for src in lib.src:
376 % if proto_re.match(src):
377 protobuf_generate_grpc_cpp(
378 ${src}
379 )
380 % endif
381 % endfor
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100382
383 target_include_directories(${lib.name}
Jan Tattermuschf567ab02017-08-25 16:13:30 +0200384 PUBLIC <%text>$<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include></%text>
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100385 PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>
Jan Tattermusch86ef9252017-12-14 02:42:34 +0100386 PRIVATE <%text>${_gRPC_SSL_INCLUDE_DIR}</%text>
Jan Tattermusch586f7192018-01-16 17:57:17 +0100387 PRIVATE <%text>${_gRPC_PROTOBUF_INCLUDE_DIR}</%text>
388 PRIVATE <%text>${_gRPC_ZLIB_INCLUDE_DIR}</%text>
389 PRIVATE <%text>${_gRPC_BENCHMARK_INCLUDE_DIR}</%text>
390 PRIVATE <%text>${_gRPC_CARES_INCLUDE_DIR}</%text>
391 PRIVATE <%text>${_gRPC_GFLAGS_INCLUDE_DIR}</%text>
Alexander Polcyn5de34782018-01-19 14:48:19 -0800392 PRIVATE <%text>${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}</%text>
David Garcia Quintas7f947022018-06-04 16:45:06 -0700393 PRIVATE <%text>${_gRPC_NANOPB_INCLUDE_DIR}</%text>
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100394 % if lib.build in ['test', 'private'] and lib.language == 'c++':
Ken Payson975b5102017-03-30 17:38:40 -0700395 PRIVATE third_party/googletest/googletest/include
396 PRIVATE third_party/googletest/googletest
Mahak Mukhi78ca0d12017-04-26 13:39:46 -0700397 PRIVATE third_party/googletest/googlemock/include
398 PRIVATE third_party/googletest/googlemock
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100399 % endif
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100400 % if lib.language == 'c++':
Jan Tattermuschcc641682017-01-17 11:59:31 +0100401 PRIVATE <%text>${_gRPC_PROTO_GENS_DIR}</%text>
402 % endif
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100403 )
404
405 % if len(get_deps(lib)) > 0:
406 target_link_libraries(${lib.name}
407 % for dep in get_deps(lib):
408 ${dep}
409 % endfor
410 )
411 % endif
Eric Gribkoffa32a4c52018-01-25 13:16:41 -0800412 % if lib.name in ["gpr"]:
413 if (_gRPC_PLATFORM_ANDROID)
414 target_link_libraries(gpr
415 android
416 log
417 )
418 endif (_gRPC_PLATFORM_ANDROID)
419 % endif
Konstantin Podsvirovd2b88302016-07-27 23:43:47 +0300420
421 % if len(lib.get('public_headers', [])) > 0:
422 foreach(_hdr
423 % for hdr in lib.get('public_headers', []):
424 ${hdr}
425 % endfor
426 )
427 string(REPLACE "include/" "" _path <%text>${_hdr}</%text>)
428 get_filename_component(_path <%text>${_path}</%text> PATH)
429 install(FILES <%text>${_hdr}</%text>
Jan Tattermuschf6915562017-06-23 14:53:55 +0200430 DESTINATION "<%text>${gRPC_INSTALL_INCLUDEDIR}/${_path}</%text>"
Konstantin Podsvirovd2b88302016-07-27 23:43:47 +0300431 )
432 endforeach()
433 % endif
Eric Gribkoffa32a4c52018-01-25 13:16:41 -0800434 % if any(proto_re.match(src) for src in lib.src):
435 endif (gRPC_BUILD_CODEGEN)
436 % endif
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100437 </%def>
438
439 <%def name="cc_binary(tgt)">
440 add_executable(${tgt.name}
441 % for src in tgt.src:
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100442 % if not proto_re.match(src):
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100443 ${src}
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100444 % else:
445 ${proto_replace_ext(src, '.pb.cc')}
446 ${proto_replace_ext(src, '.grpc.pb.cc')}
447 ${proto_replace_ext(src, '.pb.h')}
448 ${proto_replace_ext(src, '.grpc.pb.h')}
449 % endif
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100450 % endfor
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100451 % if tgt.build == 'test' and tgt.language == 'c++':
Ken Payson975b5102017-03-30 17:38:40 -0700452 third_party/googletest/googletest/src/gtest-all.cc
Mahak Mukhi78ca0d12017-04-26 13:39:46 -0700453 third_party/googletest/googlemock/src/gmock-all.cc
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100454 % endif
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100455 )
456
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100457 % for src in tgt.src:
458 % if proto_re.match(src):
459 protobuf_generate_grpc_cpp(
460 ${src}
461 )
462 % endif
463 % endfor
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100464
465 target_include_directories(${tgt.name}
466 PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>
467 PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/include
Jan Tattermusch86ef9252017-12-14 02:42:34 +0100468 PRIVATE <%text>${_gRPC_SSL_INCLUDE_DIR}</%text>
Jan Tattermusch586f7192018-01-16 17:57:17 +0100469 PRIVATE <%text>${_gRPC_PROTOBUF_INCLUDE_DIR}</%text>
470 PRIVATE <%text>${_gRPC_ZLIB_INCLUDE_DIR}</%text>
471 PRIVATE <%text>${_gRPC_BENCHMARK_INCLUDE_DIR}</%text>
472 PRIVATE <%text>${_gRPC_CARES_INCLUDE_DIR}</%text>
473 PRIVATE <%text>${_gRPC_GFLAGS_INCLUDE_DIR}</%text>
Alexander Polcyn5de34782018-01-19 14:48:19 -0800474 PRIVATE <%text>${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}</%text>
David Garcia Quintas7f947022018-06-04 16:45:06 -0700475 PRIVATE <%text>${_gRPC_NANOPB_INCLUDE_DIR}</%text>
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100476 % if tgt.build in ['test', 'private'] and tgt.language == 'c++':
Ken Payson975b5102017-03-30 17:38:40 -0700477 PRIVATE third_party/googletest/googletest/include
478 PRIVATE third_party/googletest/googletest
Mahak Mukhi78ca0d12017-04-26 13:39:46 -0700479 PRIVATE third_party/googletest/googlemock/include
480 PRIVATE third_party/googletest/googlemock
Jan Tattermusch0a1701f2017-01-17 19:44:08 +0100481 % endif
Jan Tattermusch438c0b52017-01-23 11:24:53 +0100482 % if tgt.language == 'c++':
483 PRIVATE <%text>${_gRPC_PROTO_GENS_DIR}</%text>
484 % endif
Tamas Berghammerd798a7d2016-06-21 13:58:18 +0100485 )
486
487 % if len(get_deps(tgt)) > 0:
488 target_link_libraries(${tgt.name}
489 % for dep in get_deps(tgt):
490 ${dep}
491 % endfor
492 )
493 % endif
494 </%def>
495
Konstantin Podsvirovd2b88302016-07-27 23:43:47 +0300496 <%def name="cc_install(tgt)">
Arkadiy Shapkin40beb372016-08-17 14:42:36 +0300497 if (gRPC_INSTALL)
498 install(TARGETS ${tgt.name} EXPORT gRPCTargets
Jan Tattermuschf6915562017-06-23 14:53:55 +0200499 RUNTIME DESTINATION <%text>${gRPC_INSTALL_BINDIR}</%text>
500 LIBRARY DESTINATION <%text>${gRPC_INSTALL_LIBDIR}</%text>
501 ARCHIVE DESTINATION <%text>${gRPC_INSTALL_LIBDIR}</%text>
Arkadiy Shapkin40beb372016-08-17 14:42:36 +0300502 )
503 endif()
Konstantin Podsvirovd2b88302016-07-27 23:43:47 +0300504 </%def>
505
Alex Merryb5984fa2017-05-15 21:04:16 +0100506 if (gRPC_INSTALL)
507 install(EXPORT gRPCTargets
Jan Tattermuschf6915562017-06-23 14:53:55 +0200508 DESTINATION <%text>${gRPC_INSTALL_CMAKEDIR}</%text>
Alex Merryb5984fa2017-05-15 21:04:16 +0100509 NAMESPACE gRPC::
510 )
511 endif()
512
Konstantin Podsvirovd2b88302016-07-27 23:43:47 +0300513 foreach(_config gRPCConfig gRPCConfigVersion)
Jan Tattermusch9d1d0522017-08-25 14:26:47 +0200514 configure_file(cmake/<%text>${_config}</%text>.cmake.in
Konstantin Podsvirovd2b88302016-07-27 23:43:47 +0300515 <%text>${_config}</%text>.cmake @ONLY)
516 install(FILES <%text>${CMAKE_CURRENT_BINARY_DIR}/${_config}</%text>.cmake
Jan Tattermuschf6915562017-06-23 14:53:55 +0200517 DESTINATION <%text>${gRPC_INSTALL_CMAKEDIR}</%text>
Konstantin Podsvirovd2b88302016-07-27 23:43:47 +0300518 )
519 endforeach()
Jan Tattermuscha3992d22018-05-09 17:37:27 +0200520
521 install(FILES <%text>${CMAKE_CURRENT_SOURCE_DIR}/etc/roots.pem</%text>
522 DESTINATION <%text>${gRPC_INSTALL_SHAREDIR}</%text>)