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
10 # Copyright 2015 gRPC authors.
12 # 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
16 # http://www.apache.org/licenses/LICENSE-2.0
18 # 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.
27 proto_re = re.compile('(.*)\\.proto')
28 lib_map = {lib.name: lib for lib in libs}
30 def proto_replace_ext(filename, ext):
31 m = proto_re.match(filename)
34 return '${_gRPC_PROTO_GENS_DIR}/' + m.group(1) + ext
36 def is_absl_lib(lib_name):
37 return lib_name.startswith("absl/");
39 def get_absl_dep(lib_name):
40 return lib_map[lib_name].cmake_target
42 def list_absl_lib_files_for(lib_name):
44 lib = lib_map[lib_name]
45 for dep in lib.transitive_deps:
46 if is_absl_lib(dep) and len(lib_map[dep].src) > 0:
47 ret.append(get_absl_dep(dep).replace("::", "_"))
50 def get_deps(target_dict):
52 if target_dict.get('baselib', False) or target_dict['name'] == 'address_sorting':
53 deps.append("${_gRPC_BASELIB_LIBRARIES}")
54 if target_dict.get('build', None) in ['protoc']:
55 deps.append("${_gRPC_PROTOBUF_PROTOC_LIBRARIES}")
56 if target_dict.get('secure', False):
57 deps.append("${_gRPC_SSL_LIBRARIES}")
58 if target_dict.language == 'c++':
59 deps.append("${_gRPC_PROTOBUF_LIBRARIES}")
60 if target_dict['name'] in ['grpc', 'grpc_cronet', 'grpc_unsecure']:
61 deps.append("${_gRPC_ZLIB_LIBRARIES}")
62 deps.append("${_gRPC_CARES_LIBRARIES}")
63 deps.append("${_gRPC_ADDRESS_SORTING_LIBRARIES}")
64 deps.append("${_gRPC_RE2_LIBRARIES}")
65 deps.append("${_gRPC_UPB_LIBRARIES}")
66 deps.append("${_gRPC_ALLTARGETS_LIBRARIES}")
67 for d in target_dict.get('deps', []):
69 deps.append("${_gRPC_BENCHMARK_LIBRARIES}")
71 deps.append(get_absl_dep(d))
74 if (target_dict.build == 'test' or target_dict.build == 'private') and target_dict.language == 'c++':
75 deps.append("${_gRPC_GFLAGS_LIBRARIES}")
78 def get_platforms_condition_begin(platforms):
79 if all(platform in platforms for platform in ['linux', 'mac', 'posix', 'windows']):
81 cond = ' OR '.join(['_gRPC_PLATFORM_%s' % platform.upper() for platform in platforms])
82 return 'if(%s)' % cond
84 def get_platforms_condition_end(platforms):
85 if not get_platforms_condition_begin(platforms):
89 def platforms_condition_block(platforms):
91 lines = text.split('\n')
92 cond = get_platforms_condition_begin(platforms)
94 # Remove empty line following <%block>
97 # Indent each line after
98 for i, line in enumerate(lines[:-1]):
100 lines[i] = ' ' + line
102 # Add the condition block
103 lines.insert(0, cond)
105 # Add endif() to the last line
106 lines[-1] += 'endif()'
108 # Remove empty line following <%block>
111 # Strip leading whitespace from first line
112 lines[0] = lines[0].lstrip(' ')
114 # Remove empty line before </%block>
117 return '\n'.join(lines)
121 # These files are added to a set so that they are not duplicated if multiple
122 # targets use them. Generating the same file multiple times with
123 # add_custom_command() is not allowed in CMake.
125 protobuf_gen_files = set()
128 if proto_re.match(src):
129 protobuf_gen_files.add(src)
132 if proto_re.match(src):
133 protobuf_gen_files.add(src)
136 cmake_minimum_required(VERSION 3.5.1)
138 set(PACKAGE_NAME "grpc")
139 set(PACKAGE_VERSION "${settings.cpp_version}")
140 set(gRPC_CORE_VERSION "${settings.core_version}")
141 set(gRPC_CORE_SOVERSION "${settings.core_version.major}")
142 set(gRPC_CPP_VERSION "${settings.cpp_version}")
143 set(gRPC_CPP_SOVERSION "${settings.cpp_version.major}")
144 set(gRPC_CSHARP_VERSION "${settings.csharp_version}")
145 set(gRPC_CSHARP_SOVERSION "${settings.csharp_version.major}")
146 set(PACKAGE_STRING "<%text>${PACKAGE_NAME} ${PACKAGE_VERSION}</%text>")
147 set(PACKAGE_TARNAME "<%text>${PACKAGE_NAME}-${PACKAGE_VERSION}</%text>")
148 set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/")
149 project(<%text>${PACKAGE_NAME}</%text> LANGUAGES C CXX)
151 set(gRPC_INSTALL_BINDIR "bin" CACHE STRING "Installation directory for executables")
152 set(gRPC_INSTALL_LIBDIR "lib" CACHE STRING "Installation directory for libraries")
153 set(gRPC_INSTALL_INCLUDEDIR "include" CACHE STRING "Installation directory for headers")
154 set(gRPC_INSTALL_CMAKEDIR "lib/cmake/<%text>${PACKAGE_NAME}</%text>" CACHE STRING "Installation directory for cmake config files")
155 set(gRPC_INSTALL_SHAREDIR "share/grpc" CACHE STRING "Installation directory for root certificates")
158 option(gRPC_BUILD_TESTS "Build tests" OFF)
159 option(gRPC_BUILD_CODEGEN "Build codegen" ON)
160 option(gRPC_BUILD_CSHARP_EXT "Build C# extensions" ON)
161 option(gRPC_BACKWARDS_COMPATIBILITY_MODE "Build libraries that are binary compatible across a larger number of OS and libc versions" OFF)
163 set(gRPC_INSTALL_default ON)
164 if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
165 # Disable gRPC_INSTALL by default if building as a submodule
166 set(gRPC_INSTALL_default OFF)
168 set(gRPC_INSTALL <%text>${gRPC_INSTALL_default}</%text> CACHE BOOL
169 "Generate installation target")
171 # We can install dependencies from submodules if we're running
172 # CMake v3.13 or newer.
173 if(CMAKE_VERSION VERSION_LESS 3.13)
174 set(_gRPC_INSTALL_SUPPORTED_FROM_MODULE OFF)
176 set(_gRPC_INSTALL_SUPPORTED_FROM_MODULE ON)
179 # Providers for third-party dependencies (gRPC_*_PROVIDER properties):
180 # "module": build the dependency using sources from git submodule (under third_party)
181 # "package": use cmake's find_package functionality to locate a pre-installed dependency
183 set(gRPC_ZLIB_PROVIDER "module" CACHE STRING "Provider of zlib library")
184 set_property(CACHE gRPC_ZLIB_PROVIDER PROPERTY STRINGS "module" "package")
186 set(gRPC_CARES_PROVIDER "module" CACHE STRING "Provider of c-ares library")
187 set_property(CACHE gRPC_CARES_PROVIDER PROPERTY STRINGS "module" "package")
189 set(gRPC_RE2_PROVIDER "module" CACHE STRING "Provider of re2 library")
190 set_property(CACHE gRPC_RE2_PROVIDER PROPERTY STRINGS "module" "package")
192 set(gRPC_SSL_PROVIDER "module" CACHE STRING "Provider of ssl library")
193 set_property(CACHE gRPC_SSL_PROVIDER PROPERTY STRINGS "module" "package")
195 set(gRPC_PROTOBUF_PROVIDER "module" CACHE STRING "Provider of protobuf library")
196 set_property(CACHE gRPC_PROTOBUF_PROVIDER PROPERTY STRINGS "module" "package")
198 set(gRPC_PROTOBUF_PACKAGE_TYPE "" CACHE STRING "Algorithm for searching protobuf package")
199 set_property(CACHE gRPC_PROTOBUF_PACKAGE_TYPE PROPERTY STRINGS "CONFIG" "MODULE")
202 set(gRPC_GFLAGS_PROVIDER "module" CACHE STRING "Provider of gflags library")
203 set_property(CACHE gRPC_GFLAGS_PROVIDER PROPERTY STRINGS "module" "package")
205 set(gRPC_BENCHMARK_PROVIDER "module" CACHE STRING "Provider of benchmark library")
206 set_property(CACHE gRPC_BENCHMARK_PROVIDER PROPERTY STRINGS "module" "package")
208 set(gRPC_GFLAGS_PROVIDER "none")
209 set(gRPC_BENCHMARK_PROVIDER "none")
212 set(gRPC_ABSL_PROVIDER "module" CACHE STRING "Provider of absl library")
213 set_property(CACHE gRPC_ABSL_PROVIDER PROPERTY STRINGS "module" "package")
215 # Collect all abseil rules used by gpr, grpc, so on.
216 used_abseil_rules = set()
218 if lib.get("baselib"):
219 for dep in lib.transitive_deps:
221 used_abseil_rules.add(lib_map[dep].cmake_target.replace("::", "_"))
223 set(gRPC_ABSL_USED_TARGETS
224 % for rule in sorted(used_abseil_rules):
230 set(gRPC_USE_PROTO_LITE OFF CACHE BOOL "Use the protobuf-lite library")
233 if(<%text>${CMAKE_SYSTEM_NAME}</%text> MATCHES "Linux")
234 set(_gRPC_PLATFORM_LINUX ON)
235 elseif(<%text>${CMAKE_SYSTEM_NAME}</%text> MATCHES "Darwin")
236 set(_gRPC_PLATFORM_MAC ON)
237 elseif(<%text>${CMAKE_SYSTEM_NAME}</%text> MATCHES "iOS")
238 set(_gRPC_PLATFORM_IOS ON)
239 elseif(<%text>${CMAKE_SYSTEM_NAME}</%text> MATCHES "Android")
240 set(_gRPC_PLATFORM_ANDROID ON)
242 set(_gRPC_PLATFORM_POSIX ON)
246 set(_gRPC_PLATFORM_WINDOWS ON)
250 if (NOT DEFINED CMAKE_C_STANDARD)
251 set(CMAKE_C_STANDARD 99)
255 if (NOT DEFINED CMAKE_CXX_STANDARD)
256 set(CMAKE_CXX_STANDARD 11)
258 if (CMAKE_CXX_STANDARD LESS 11)
259 message(FATAL_ERROR "CMAKE_CXX_STANDARD is less than 11, please specify at least SET(CMAKE_CXX_STANDARD 11)")
262 if (NOT DEFINED CMAKE_CXX_STANDARD_REQUIRED)
263 set(CMAKE_CXX_STANDARD_REQUIRED ON)
265 if (NOT DEFINED CMAKE_CXX_EXTENSIONS)
266 set(CMAKE_CXX_EXTENSIONS OFF)
269 ## Some libraries are shared even with BUILD_SHARED_LIBRARIES=OFF
270 if (NOT DEFINED CMAKE_POSITION_INDEPENDENT_CODE)
271 set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
273 list(APPEND CMAKE_MODULE_PATH "<%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/cmake/modules")
276 include(cmake/msvc_static_runtime.cmake)
277 add_definitions(-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS)
278 # needed to compile protobuf
279 set(_gRPC_C_CXX_FLAGS "<%text>${_gRPC_C_CXX_FLAGS}</%text> /wd4065 /wd4506")
280 # TODO(jtattermusch): revisit warnings that were silenced as part of upgrade to protobuf3.6.0
281 set(_gRPC_C_CXX_FLAGS "<%text>${_gRPC_C_CXX_FLAGS}</%text> /wd4200 /wd4291 /wd4244")
282 # TODO(jtattermusch): revisit C4267 occurrences throughout the code
283 set(_gRPC_C_CXX_FLAGS "<%text>${_gRPC_C_CXX_FLAGS}</%text> /wd4267")
284 # TODO(jtattermusch): needed to build boringssl with VS2017, revisit later
285 set(_gRPC_C_CXX_FLAGS "<%text>${_gRPC_C_CXX_FLAGS}</%text> /wd4987 /wd4774 /wd4819 /wd4996 /wd4619")
288 add_definitions(-D_WIN32_WINNT=0x600)
290 set(CMAKE_C_FLAGS "<%text>${CMAKE_C_FLAGS} ${_gRPC_C_CXX_FLAGS}</%text>")
291 set(CMAKE_CXX_FLAGS "<%text>${CMAKE_CXX_FLAGS} ${_gRPC_C_CXX_FLAGS}</%text>")
293 if(gRPC_USE_PROTO_LITE)
294 set(_gRPC_PROTOBUF_LIBRARY_NAME "libprotobuf-lite")
295 add_definitions("-DGRPC_USE_PROTO_LITE")
297 set(_gRPC_PROTOBUF_LIBRARY_NAME "libprotobuf")
300 if(gRPC_BACKWARDS_COMPATIBILITY_MODE)
301 add_definitions(-DGPR_BACKWARDS_COMPATIBILITY_MODE)
302 if(_gRPC_PLATFORM_MAC)
303 # some C++11 constructs not supported before OS X 10.9
304 set(CMAKE_OSX_DEPLOYMENT_TARGET 10.9)
308 if(_gRPC_PLATFORM_LINUX OR _gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_IOS)
309 set(_gRPC_CORE_NOSTDCXX_FLAGS -fno-exceptions -fno-rtti)
311 set(_gRPC_CORE_NOSTDCXX_FLAGS "")
314 include(cmake/abseil-cpp.cmake)
315 include(cmake/address_sorting.cmake)
316 include(cmake/benchmark.cmake)
317 include(cmake/cares.cmake)
318 include(cmake/gflags.cmake)
319 include(cmake/protobuf.cmake)
320 include(cmake/re2.cmake)
321 include(cmake/ssl.cmake)
322 include(cmake/upb.cmake)
323 include(cmake/zlib.cmake)
325 if(_gRPC_PLATFORM_MAC OR _gRPC_PLATFORM_IOS)
326 set(_gRPC_ALLTARGETS_LIBRARIES <%text>${CMAKE_DL_LIBS}</%text> m pthread)
327 elseif(_gRPC_PLATFORM_ANDROID)
328 set(_gRPC_ALLTARGETS_LIBRARIES <%text>${CMAKE_DL_LIBS}</%text> m)
330 set(_gRPC_ALLTARGETS_LIBRARIES <%text>${CMAKE_DL_LIBS}</%text> rt m pthread)
334 set(_gRPC_BASELIB_LIBRARIES wsock32 ws2_32 crypt32)
337 # Create directory for generated .proto files
338 set(_gRPC_PROTO_GENS_DIR <%text>${CMAKE_BINARY_DIR}/gens</%text>)
339 file(MAKE_DIRECTORY <%text>${_gRPC_PROTO_GENS_DIR}</%text>)
341 # protobuf_generate_grpc_cpp
342 # --------------------------
344 # Add custom commands to process ``.proto`` files to C++ using protoc and
347 # protobuf_generate_grpc_cpp [<ARGN>...]
352 function(protobuf_generate_grpc_cpp)
354 message(SEND_ERROR "Error: PROTOBUF_GENERATE_GRPC_CPP() called without any proto files")
358 set(_protobuf_include_path -I . -I <%text>${_gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR}</%text>)
359 foreach(FIL <%text>${ARGN}</%text>)
360 get_filename_component(ABS_FIL <%text>${FIL}</%text> ABSOLUTE)
361 get_filename_component(FIL_WE <%text>${FIL}</%text> NAME_WE)
362 file(RELATIVE_PATH REL_FIL <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text> <%text>${ABS_FIL}</%text>)
363 get_filename_component(REL_DIR <%text>${REL_FIL}</%text> DIRECTORY)
364 set(RELFIL_WE "<%text>${REL_DIR}/${FIL_WE}</%text>")
366 #if cross-compiling, find host plugin
367 if(CMAKE_CROSSCOMPILING)
368 find_program(_gRPC_CPP_PLUGIN grpc_cpp_plugin)
370 set(_gRPC_CPP_PLUGIN $<TARGET_FILE:grpc_cpp_plugin>)
374 OUTPUT <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.cc"</%text>
375 <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.h"</%text>
376 <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}_mock.grpc.pb.h"</%text>
377 <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.cc"</%text>
378 <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.h"</%text>
379 COMMAND <%text>${_gRPC_PROTOBUF_PROTOC_EXECUTABLE}</%text>
380 ARGS --grpc_out=<%text>generate_mock_code=true:${_gRPC_PROTO_GENS_DIR}</%text>
381 --cpp_out=<%text>${_gRPC_PROTO_GENS_DIR}</%text>
382 --plugin=protoc-gen-grpc=<%text>${_gRPC_CPP_PLUGIN}</%text>
383 <%text>${_protobuf_include_path}</%text>
384 <%text>${REL_FIL}</%text>
385 DEPENDS <%text>${ABS_FIL}</%text> <%text>${_gRPC_PROTOBUF_PROTOC}</%text> grpc_cpp_plugin
386 WORKING_DIRECTORY <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>
387 COMMENT "Running gRPC C++ protocol buffer compiler on <%text>${FIL}</%text>"
392 # These options allow users to enable or disable the building of the various
393 # protoc plugins. For example, running CMake with
394 # -DgRPC_BUILD_GRPC_CSHARP_PLUGIN=OFF will disable building the C# plugin.
395 set(_gRPC_PLUGIN_LIST)
396 % for tgt in targets:
397 % if tgt.build == 'protoc':
398 option(gRPC_BUILD_${tgt.name.upper()} "Build ${tgt.name}" ON)
399 if (gRPC_BUILD_${tgt.name.upper()})
400 list(APPEND _gRPC_PLUGIN_LIST ${tgt.name})
405 add_custom_target(plugins
406 DEPENDS <%text>${_gRPC_PLUGIN_LIST}</%text>
409 add_custom_target(tools_c
411 % for tgt in targets:
412 % if tgt.build == 'tool' and not tgt.language == 'c++':
418 add_custom_target(tools_cxx
420 % for tgt in targets:
421 % if tgt.build == 'tool' and tgt.language == 'c++':
427 add_custom_target(tools
428 DEPENDS tools_c tools_cxx)
430 % for src in sorted(protobuf_gen_files):
431 protobuf_generate_grpc_cpp(
437 add_custom_target(buildtests_c)
438 % for tgt in targets:
439 % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
440 <%block filter='platforms_condition_block(tgt.platforms)'>
441 add_dependencies(buildtests_c ${tgt.name})
446 add_custom_target(buildtests_cxx)
447 % for tgt in targets:
448 % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
449 <%block filter='platforms_condition_block(tgt.platforms)'>
450 add_dependencies(buildtests_cxx ${tgt.name})
455 add_custom_target(buildtests
456 DEPENDS buildtests_c buildtests_cxx)
461 if lib.build not in ["all", "protoc", "tool", "test", "private"] or lib.boringssl: continue
462 if lib.get('build_system', []) and 'cmake' not in lib.get('build_system', []): continue
463 if lib.name in ['ares', 'benchmark', 're2', 'z']: continue # we build these using CMake instead
464 if is_absl_lib(lib.name): continue # we build these using CMake instead
465 cmake_libs.append(lib)
467 % for lib in cmake_libs:
468 % if lib.build in ["test", "private"]:
472 % elif lib.name in ['grpc_csharp_ext']:
473 if(gRPC_BUILD_CSHARP_EXT)
478 % if not lib.build in ["tool"]:
479 % if any(proto_re.match(src) for src in lib.src):
480 if(gRPC_BUILD_CODEGEN)
483 % if any(proto_re.match(src) for src in lib.src):
490 % for tgt in targets:
491 % if tgt.build in ["all", "protoc", "tool", "test", "private"] and not tgt.boringssl:
492 % if tgt.build in ["test", "private"]:
494 <%block filter='platforms_condition_block(tgt.platforms)'>
498 % elif tgt.build in ["protoc"]:
499 if(gRPC_BUILD_CODEGEN AND gRPC_BUILD_${tgt.name.upper()})
500 <%block filter='platforms_condition_block(tgt.platforms)'>
506 <%block filter='platforms_condition_block(tgt.platforms)'>
508 % if not tgt.build in ["tool"]:
516 <%def name="cc_library(lib)">
517 % if any(proto_re.match(src) for src in lib.src):
518 % if lib.name == 'grpcpp_channelz':
519 # grpcpp_channelz doesn't build with protobuf-lite
520 # See https://github.com/grpc/grpc/issues/19473
521 if(gRPC_BUILD_CODEGEN AND NOT gRPC_USE_PROTO_LITE)
523 if(gRPC_BUILD_CODEGEN)
526 add_library(${lib.name}${' SHARED' if lib.get('dll', None) == 'only' else ''}
527 % for src in lib.src:
528 % if not proto_re.match(src):
531 ${proto_replace_ext(src, '.pb.cc')}
532 ${proto_replace_ext(src, '.grpc.pb.cc')}
533 ${proto_replace_ext(src, '.pb.h')}
534 ${proto_replace_ext(src, '.grpc.pb.h')}
535 % if src in ["src/proto/grpc/testing/compiler_test.proto", "src/proto/grpc/testing/echo.proto"]:
536 ${proto_replace_ext(src, '_mock.grpc.pb.h')}
542 set_target_properties(${lib.name} PROPERTIES
543 % if lib.language == 'c++':
544 VERSION <%text>${gRPC_CPP_VERSION}</%text>
545 SOVERSION <%text>${gRPC_CPP_SOVERSION}</%text>
546 % elif lib.language == 'csharp':
547 VERSION <%text>${gRPC_CSHARP_VERSION}</%text>
548 SOVERSION <%text>${gRPC_CSHARP_SOVERSION}</%text>
550 VERSION <%text>${gRPC_CORE_VERSION}</%text>
551 SOVERSION <%text>${gRPC_CORE_SOVERSION}</%text>
556 set_target_properties(${lib.name} PROPERTIES COMPILE_PDB_NAME "${lib.name}"
557 COMPILE_PDB_OUTPUT_DIRECTORY <%text>"${CMAKE_BINARY_DIR}</%text>"
560 install(FILES <%text>${CMAKE_CURRENT_BINARY_DIR}/</%text>${lib.name}.pdb
561 DESTINATION <%text>${gRPC_INSTALL_LIBDIR}</%text> OPTIONAL
566 target_include_directories(${lib.name}
567 PUBLIC <%text>$<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include></%text>
569 <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>
570 <%text>${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}</%text>
571 <%text>${_gRPC_RE2_INCLUDE_DIR}</%text>
572 <%text>${_gRPC_SSL_INCLUDE_DIR}</%text>
573 <%text>${_gRPC_UPB_GENERATED_DIR}</%text>
574 <%text>${_gRPC_UPB_GRPC_GENERATED_DIR}</%text>
575 <%text>${_gRPC_UPB_INCLUDE_DIR}</%text>
576 <%text>${_gRPC_ZLIB_INCLUDE_DIR}</%text>
577 % if lib.build in ['test', 'private'] and lib.language == 'c++':
578 third_party/googletest/googletest/include
579 third_party/googletest/googletest
580 third_party/googletest/googlemock/include
581 third_party/googletest/googlemock
583 % if lib.language == 'c++':
584 <%text>${_gRPC_PROTO_GENS_DIR}</%text>
587 % if len(get_deps(lib)) > 0:
588 target_link_libraries(${lib.name}
589 % for dep in get_deps(lib):
594 % if lib.name in ["gpr"]:
595 if(_gRPC_PLATFORM_ANDROID)
596 target_link_libraries(gpr
602 % if lib.name in ["grpc", "grpc_cronet", "grpc_test_util", \
603 "grpc_test_util_unsecure", "grpc_unsecure", \
605 if(_gRPC_PLATFORM_IOS OR _gRPC_PLATFORM_MAC)
606 target_link_libraries(${lib.name} "-framework CoreFoundation")
610 % if len(lib.get('public_headers', [])) > 0:
612 % for hdr in lib.get('public_headers', []):
616 string(REPLACE "include/" "" _path <%text>${_hdr}</%text>)
617 get_filename_component(_path <%text>${_path}</%text> PATH)
618 install(FILES <%text>${_hdr}</%text>
619 DESTINATION "<%text>${gRPC_INSTALL_INCLUDEDIR}/${_path}</%text>"
623 % if any(proto_re.match(src) for src in lib.src):
628 <%def name="cc_binary(tgt)">
629 add_executable(${tgt.name}
630 % for src in tgt.src:
631 % if not proto_re.match(src):
634 ${proto_replace_ext(src, '.pb.cc')}
635 ${proto_replace_ext(src, '.grpc.pb.cc')}
636 ${proto_replace_ext(src, '.pb.h')}
637 ${proto_replace_ext(src, '.grpc.pb.h')}
640 % if tgt.build == 'test' and tgt.language == 'c++':
641 third_party/googletest/googletest/src/gtest-all.cc
642 third_party/googletest/googlemock/src/gmock-all.cc
646 target_include_directories(${tgt.name}
648 <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>
649 <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/include
650 <%text>${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}</%text>
651 <%text>${_gRPC_RE2_INCLUDE_DIR}</%text>
652 <%text>${_gRPC_SSL_INCLUDE_DIR}</%text>
653 <%text>${_gRPC_UPB_GENERATED_DIR}</%text>
654 <%text>${_gRPC_UPB_GRPC_GENERATED_DIR}</%text>
655 <%text>${_gRPC_UPB_INCLUDE_DIR}</%text>
656 <%text>${_gRPC_ZLIB_INCLUDE_DIR}</%text>
657 % if tgt.build in ['test', 'private'] and tgt.language == 'c++':
658 third_party/googletest/googletest/include
659 third_party/googletest/googletest
660 third_party/googletest/googlemock/include
661 third_party/googletest/googlemock
663 % if tgt.language == 'c++':
664 <%text>${_gRPC_PROTO_GENS_DIR}</%text>
668 % if len(get_deps(tgt)) > 0:
669 target_link_libraries(${tgt.name}
670 % for dep in get_deps(tgt):
678 <%def name="cc_install(tgt)">
680 install(TARGETS ${tgt.name} EXPORT gRPCTargets
681 RUNTIME DESTINATION <%text>${gRPC_INSTALL_BINDIR}</%text>
682 LIBRARY DESTINATION <%text>${gRPC_INSTALL_LIBDIR}</%text>
683 ARCHIVE DESTINATION <%text>${gRPC_INSTALL_LIBDIR}</%text>
689 install(EXPORT gRPCTargets
690 DESTINATION <%text>${gRPC_INSTALL_CMAKEDIR}</%text>
695 include(CMakePackageConfigHelpers)
697 configure_file(cmake/gRPCConfig.cmake.in
698 gRPCConfig.cmake @ONLY)
699 write_basic_package_version_file(<%text>${CMAKE_CURRENT_BINARY_DIR}/</%text>gRPCConfigVersion.cmake
700 VERSION <%text>${gRPC_CPP_VERSION}</%text>
701 COMPATIBILITY AnyNewerVersion)
703 <%text>${CMAKE_CURRENT_BINARY_DIR}/</%text>gRPCConfig.cmake
704 <%text>${CMAKE_CURRENT_BINARY_DIR}/</%text>gRPCConfigVersion.cmake
705 DESTINATION <%text>${gRPC_INSTALL_CMAKEDIR}</%text>
708 <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/cmake/modules/Findc-ares.cmake
709 <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/cmake/modules/Findre2.cmake
710 DESTINATION <%text>${gRPC_INSTALL_CMAKEDIR}</%text>/modules
713 install(FILES <%text>${CMAKE_CURRENT_SOURCE_DIR}/etc/roots.pem</%text>
714 DESTINATION <%text>${gRPC_INSTALL_SHAREDIR}</%text>)
716 # Function to generate pkg-config files.
717 function(generate_pkgconfig name description version requires
718 libs libs_private output_filename)
719 set(PC_NAME "<%text>${name}</%text>")
720 set(PC_DESCRIPTION "<%text>${description}</%text>")
721 set(PC_VERSION "<%text>${version}</%text>")
722 set(PC_REQUIRES "<%text>${requires}</%text>")
723 set(PC_LIB "<%text>${libs}</%text>")
724 set(PC_LIBS_PRIVATE "<%text>${libs_private}</%text>")
725 set(output_filepath "<%text>${grpc_BINARY_DIR}/libs/opt/pkgconfig/${output_filename}</%text>")
727 "<%text>${grpc_SOURCE_DIR}/cmake/pkg-config-template.pc.in</%text>"
728 "<%text>${output_filepath}</%text>"
730 install(FILES "<%text>${output_filepath}</%text>"
731 DESTINATION "lib/pkgconfig/")
737 "gRPC platform support library"
738 "<%text>${gRPC_CORE_VERSION}</%text>"
740 "${" ".join(("-l" + l) for l in ["gpr",] + list_absl_lib_files_for("gpr"))}"
747 "high performance general RPC framework"
748 "<%text>${gRPC_CORE_VERSION}</%text>"
750 "${" ".join(("-l" + l) for l in ["grpc", "address_sorting", "re2", "upb", "cares", "z"] + list_absl_lib_files_for("grpc"))}"
754 # grpc_unsecure .pc file
757 "high performance general RPC framework without SSL"
758 "<%text>${gRPC_CORE_VERSION}</%text>"
760 "${" ".join(("-l" + l) for l in ["grpc_unsecure",] + list_absl_lib_files_for("grpc_unsecure"))}"
767 "C++ wrapper for gRPC"
768 "<%text>${gRPC_CPP_VERSION}</%text>"
770 "${" ".join(("-l" + l) for l in ["grpc++",] + list_absl_lib_files_for("grpc++"))}"
774 # grpc++_unsecure .pc file
777 "C++ wrapper for gRPC without SSL"
778 "<%text>${gRPC_CPP_VERSION}</%text>"
780 "${" ".join(("-l" + l) for l in ["grpc++_unsecure",] + list_absl_lib_files_for("grpc++_unsecure"))}"
782 "grpc++_unsecure.pc")