Home | History | Annotate | Download | only in templates
      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
      9   #
     10   # Copyright 2015 gRPC authors.
     11   #
     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
     15   #
     16   #     http://www.apache.org/licenses/LICENSE-2.0
     17   #
     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.
     23 
     24   <%!
     25 
     26   import re
     27 
     28   proto_re = re.compile('(.*)\\.proto')
     29 
     30   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
     35 
     36   def get_deps(target_dict):
     37     deps = []
     38     if target_dict.get('baselib', False) or target_dict['name'] == 'address_sorting':
     39       deps.append("${_gRPC_BASELIB_LIBRARIES}")
     40     if target_dict.get('build', None) in ['protoc']:
     41       deps.append("${_gRPC_PROTOBUF_PROTOC_LIBRARIES}")
     42     if target_dict.get('secure', False):
     43       deps.append("${_gRPC_SSL_LIBRARIES}")
     44     if target_dict.language == 'c++':
     45       deps.append("${_gRPC_PROTOBUF_LIBRARIES}")
     46     if target_dict['name'] in ['grpc', 'grpc_cronet', 'grpc_unsecure']:
     47       deps.append("${_gRPC_ZLIB_LIBRARIES}")
     48       deps.append("${_gRPC_CARES_LIBRARIES}")
     49       deps.append("${_gRPC_ADDRESS_SORTING_LIBRARIES}")
     50     deps.append("${_gRPC_ALLTARGETS_LIBRARIES}")
     51     for d in target_dict.get('deps', []):
     52       if d == 'benchmark':
     53         deps.append("${_gRPC_BENCHMARK_LIBRARIES}")
     54       else:
     55         deps.append(d)
     56     if target_dict.build == 'test' and target_dict.language == 'c++':
     57       deps.append("${_gRPC_GFLAGS_LIBRARIES}")
     58     return deps
     59 
     60   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
     65 
     66   def get_platforms_condition_end(platforms):
     67     if not get_platforms_condition_begin(platforms):
     68       return ''
     69     return 'endif()\n'
     70   %>
     71 
     72   cmake_minimum_required(VERSION 2.8)
     73 
     74   set(PACKAGE_NAME      "grpc")
     75   set(PACKAGE_VERSION   "${settings.cpp_version}")
     76   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)
     80 
     81   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")
     85   set(gRPC_INSTALL_SHAREDIR "share/grpc" CACHE STRING "Installation directory for root certificates")
     86 
     87   # Options
     88   option(gRPC_BUILD_TESTS "Build tests" OFF)
     89   option(gRPC_BUILD_CODEGEN "Build codegen" ON)
     90   option(gRPC_BUILD_CSHARP_EXT "Build C# extensions" ON)
     91 
     92   set(gRPC_INSTALL_default ON)
     93   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)
     96   endif()
     97   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\"")
     99 
    100   # 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   
    104   set(gRPC_ZLIB_PROVIDER "module" CACHE STRING "Provider of zlib library")
    105   set_property(CACHE gRPC_ZLIB_PROVIDER PROPERTY STRINGS "module" "package")
    106 
    107   set(gRPC_CARES_PROVIDER "module" CACHE STRING "Provider of c-ares library")
    108   set_property(CACHE gRPC_CARES_PROVIDER PROPERTY STRINGS "module" "package")
    109 
    110   set(gRPC_SSL_PROVIDER "module" CACHE STRING "Provider of ssl library")
    111   set_property(CACHE gRPC_SSL_PROVIDER PROPERTY STRINGS "module" "package")
    112 
    113   set(gRPC_PROTOBUF_PROVIDER "module" CACHE STRING "Provider of protobuf library")
    114   set_property(CACHE gRPC_PROTOBUF_PROVIDER PROPERTY STRINGS "module" "package")
    115 
    116   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 
    119   set(gRPC_GFLAGS_PROVIDER "module" CACHE STRING "Provider of gflags library")
    120   set_property(CACHE gRPC_GFLAGS_PROVIDER PROPERTY STRINGS "module" "package")
    121 
    122   set(gRPC_BENCHMARK_PROVIDER "module" CACHE STRING "Provider of benchmark library")
    123   set_property(CACHE gRPC_BENCHMARK_PROVIDER PROPERTY STRINGS "module" "package")
    124 
    125   set(gRPC_USE_PROTO_LITE OFF CACHE BOOL "Use the protobuf-lite library")
    126 
    127   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)
    132     elseif(<%text>${CMAKE_SYSTEM_NAME}</%text> MATCHES "Android")
    133       set(_gRPC_PLATFORM_ANDROID ON)
    134     else()
    135       set(_gRPC_PLATFORM_POSIX ON)
    136     endif()
    137   endif()
    138   if(WIN32)
    139     set(_gRPC_PLATFORM_WINDOWS ON)
    140   endif()
    141 
    142   ## Some libraries are shared even with BUILD_SHARED_LIBRARIES=OFF
    143   set(CMAKE_POSITION_INDEPENDENT_CODE TRUE)
    144   
    145   add_definitions(-DPB_FIELD_16BIT)
    146 
    147   if (MSVC)
    148     include(cmake/msvc_static_runtime.cmake)
    149     add_definitions(-D_WIN32_WINNT=0x600 -D_SCL_SECURE_NO_WARNINGS -D_CRT_SECURE_NO_WARNINGS -D_WINSOCK_DEPRECATED_NO_WARNINGS)
    150     # needed to compile protobuf
    151     add_definitions(/wd4065 /wd4506)
    152     # TODO(jtattermusch): revisit warnings that were silenced as part of upgrade to protobuf3.6.0
    153     add_definitions(/wd4200 /wd4291 /wd4244)
    154     # TODO(jtattermusch): revisit C4267 occurrences throughout the code
    155     add_definitions(/wd4267)
    156     # TODO(jtattermusch): needed to build boringssl with VS2017, revisit later
    157     add_definitions(/wd4987 /wd4774 /wd4819 /wd4996 /wd4619)
    158   endif()
    159 
    160   if (gRPC_USE_PROTO_LITE)
    161     set(_gRPC_PROTOBUF_LIBRARY_NAME "libprotobuf-lite")
    162     add_definitions("-DGRPC_USE_PROTO_LITE")
    163   else()
    164     set(_gRPC_PROTOBUF_LIBRARY_NAME "libprotobuf")
    165   endif()
    166 
    167   include(cmake/zlib.cmake)
    168   include(cmake/cares.cmake)
    169   include(cmake/protobuf.cmake)
    170   include(cmake/ssl.cmake)
    171   include(cmake/gflags.cmake)
    172   include(cmake/benchmark.cmake)
    173   include(cmake/address_sorting.cmake)
    174   include(cmake/nanopb.cmake)
    175 
    176   if(NOT MSVC)
    177     set(CMAKE_C_FLAGS   "<%text>${CMAKE_C_FLAGS}</%text> -std=c99")
    178     set(CMAKE_CXX_FLAGS "<%text>${CMAKE_CXX_FLAGS}</%text> -std=c++11")
    179   endif()
    180 
    181   if(_gRPC_PLATFORM_MAC)
    182     set(_gRPC_ALLTARGETS_LIBRARIES <%text>${CMAKE_DL_LIBS}</%text> m pthread)
    183   elseif(_gRPC_PLATFORM_ANDROID)
    184     set(_gRPC_ALLTARGETS_LIBRARIES <%text>${CMAKE_DL_LIBS}</%text> m)
    185   elseif(UNIX)
    186     set(_gRPC_ALLTARGETS_LIBRARIES <%text>${CMAKE_DL_LIBS}</%text> rt m pthread)
    187   endif()
    188 
    189   if(WIN32 AND MSVC)
    190     set(_gRPC_BASELIB_LIBRARIES wsock32 ws2_32)
    191   endif()
    192 
    193   # Create directory for generated .proto files
    194   set(_gRPC_PROTO_GENS_DIR <%text>${CMAKE_BINARY_DIR}/gens</%text>)
    195   file(MAKE_DIRECTORY <%text>${_gRPC_PROTO_GENS_DIR}</%text>)
    196 
    197   #  protobuf_generate_grpc_cpp
    198   #  --------------------------
    199   #
    200   #   Add custom commands to process ``.proto`` files to C++ using protoc and
    201   #   GRPC plugin::
    202   #
    203   #     protobuf_generate_grpc_cpp [<ARGN>...]
    204   #
    205   #   ``ARGN``
    206   #     ``.proto`` files
    207   #
    208   function(protobuf_generate_grpc_cpp)
    209     if(NOT ARGN)
    210       message(SEND_ERROR "Error: PROTOBUF_GENERATE_GRPC_CPP() called without any proto files")
    211       return()
    212     endif()
    213 
    214     set(_protobuf_include_path -I . -I <%text>${_gRPC_PROTOBUF_WELLKNOWN_INCLUDE_DIR}</%text>)
    215     foreach(FIL <%text>${ARGN}</%text>)
    216       get_filename_component(ABS_FIL <%text>${FIL}</%text> ABSOLUTE)
    217       get_filename_component(FIL_WE <%text>${FIL}</%text> NAME_WE)
    218       file(RELATIVE_PATH REL_FIL <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text> <%text>${ABS_FIL}</%text>)
    219       get_filename_component(REL_DIR <%text>${REL_FIL}</%text> DIRECTORY)
    220       set(RELFIL_WE "<%text>${REL_DIR}/${FIL_WE}</%text>")
    221 
    222       add_custom_command(
    223         OUTPUT <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.cc"</%text>
    224                <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.grpc.pb.h"</%text>
    225                <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}_mock.grpc.pb.h"</%text>
    226                <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.cc"</%text>
    227                <%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.h"</%text>
    228         COMMAND <%text>${_gRPC_PROTOBUF_PROTOC_EXECUTABLE}</%text>
    229         ARGS --grpc_out=<%text>generate_mock_code=true:${_gRPC_PROTO_GENS_DIR}</%text>
    230              --cpp_out=<%text>${_gRPC_PROTO_GENS_DIR}</%text>
    231              --plugin=protoc-gen-grpc=$<TARGET_FILE:grpc_cpp_plugin>
    232              <%text>${_protobuf_include_path}</%text>
    233              <%text>${REL_FIL}</%text>
    234         DEPENDS <%text>${ABS_FIL}</%text> <%text>${_gRPC_PROTOBUF_PROTOC}</%text> grpc_cpp_plugin
    235         WORKING_DIRECTORY <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>
    236         COMMENT "Running gRPC C++ protocol buffer compiler on <%text>${FIL}</%text>"
    237         VERBATIM)
    238 
    239         <%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>
    240     endforeach()
    241   endfunction()
    242 
    243   add_custom_target(plugins
    244     DEPENDS
    245   % for tgt in targets:
    246   % if tgt.build == 'protoc':
    247     ${tgt.name}
    248   % endif
    249   % endfor
    250   )
    251 
    252   add_custom_target(tools_c
    253     DEPENDS
    254   % for tgt in targets:
    255   % if tgt.build == 'tool' and not tgt.language == 'c++':
    256     ${tgt.name}
    257   % endif
    258   % endfor
    259   )
    260 
    261   add_custom_target(tools_cxx
    262     DEPENDS
    263   % for tgt in targets:
    264   % if tgt.build == 'tool' and tgt.language == 'c++':
    265     ${tgt.name}
    266   % endif
    267   % endfor
    268   )
    269 
    270   add_custom_target(tools
    271     DEPENDS tools_c tools_cxx)
    272 
    273   if (gRPC_BUILD_TESTS)
    274   add_custom_target(buildtests_c)
    275   % for tgt in targets:
    276   % if tgt.build == 'test' and not tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
    277   ${get_platforms_condition_begin(tgt.platforms)}\
    278   add_dependencies(buildtests_c ${tgt.name})
    279   ${get_platforms_condition_end(tgt.platforms)}\
    280   % endif
    281   % endfor
    282 
    283   add_custom_target(buildtests_cxx)
    284   % for tgt in targets:
    285   % if tgt.build == 'test' and tgt.language == 'c++' and not tgt.get('external_deps', None) and not tgt.boringssl:
    286   ${get_platforms_condition_begin(tgt.platforms)}\
    287   add_dependencies(buildtests_cxx ${tgt.name})
    288   ${get_platforms_condition_end(tgt.platforms)}\
    289   % endif
    290   % endfor
    291 
    292   add_custom_target(buildtests
    293     DEPENDS buildtests_c buildtests_cxx)
    294   endif (gRPC_BUILD_TESTS)
    295 
    296   % for lib in libs:
    297   % if lib.build in ["all", "protoc", "tool", "test", "private"] and not lib.boringssl:
    298   % if not lib.get('build_system', []) or 'cmake' in lib.get('build_system', []):
    299   % if not lib.name in ['ares', 'benchmark', 'z']:  # we build these using CMake instead
    300   % if lib.build in ["test", "private"]:
    301   if (gRPC_BUILD_TESTS)
    302   ${cc_library(lib)}
    303   endif (gRPC_BUILD_TESTS)
    304   % elif lib.name in ['grpc_csharp_ext']:
    305   if (gRPC_BUILD_CSHARP_EXT)
    306   ${cc_library(lib)}
    307   ${cc_install(lib)}
    308   endif (gRPC_BUILD_CSHARP_EXT)
    309   % else:
    310   ${cc_library(lib)}
    311   % if not lib.build in ["tool"]:
    312   ${cc_install(lib)}
    313   % endif
    314   % endif
    315   % endif
    316   % endif
    317   % endif
    318   % endfor
    319 
    320   % for tgt in targets:
    321   % if tgt.build in ["all", "protoc", "tool", "test", "private"] and not tgt.boringssl:
    322   % if tgt.build in ["test", "private"]:
    323   if (gRPC_BUILD_TESTS)
    324   ${get_platforms_condition_begin(tgt.platforms)}\
    325   ${cc_binary(tgt)}
    326   ${get_platforms_condition_end(tgt.platforms)}\
    327   endif (gRPC_BUILD_TESTS)
    328   % elif tgt.build in ["protoc"]:
    329   if (gRPC_BUILD_CODEGEN)
    330   ${get_platforms_condition_begin(tgt.platforms)}\
    331   ${cc_binary(tgt)}
    332   ${cc_install(tgt)}
    333   ${get_platforms_condition_end(tgt.platforms)}\
    334   endif (gRPC_BUILD_CODEGEN)
    335   % else:
    336   ${get_platforms_condition_begin(tgt.platforms)}\
    337   ${cc_binary(tgt)}
    338   % if not tgt.build in ["tool"]:
    339   ${cc_install(tgt)}
    340   % endif
    341   ${get_platforms_condition_end(tgt.platforms)}\
    342   % endif
    343   % endif
    344   % endfor
    345 
    346   <%def name="cc_library(lib)">
    347   % if any(proto_re.match(src) for src in lib.src):
    348   if (gRPC_BUILD_CODEGEN)
    349   % endif
    350   add_library(${lib.name}${' SHARED' if lib.get('dll', None) == 'only' else ''}
    351   % for src in lib.src:
    352   % if not proto_re.match(src):
    353     ${src}
    354   % else:
    355     ${proto_replace_ext(src, '.pb.cc')}
    356     ${proto_replace_ext(src, '.grpc.pb.cc')}
    357     ${proto_replace_ext(src, '.pb.h')}
    358     ${proto_replace_ext(src, '.grpc.pb.h')}
    359     % if src in ["src/proto/grpc/testing/compiler_test.proto", "src/proto/grpc/testing/echo.proto"]:
    360     ${proto_replace_ext(src, '_mock.grpc.pb.h')}
    361     % endif
    362   % endif
    363   % endfor
    364   )
    365 
    366   if(WIN32 AND MSVC)
    367     set_target_properties(${lib.name} PROPERTIES COMPILE_PDB_NAME "${lib.name}"
    368       COMPILE_PDB_OUTPUT_DIRECTORY <%text>"${CMAKE_BINARY_DIR}</%text>"
    369     )
    370     if (gRPC_INSTALL)
    371       install(FILES <%text>${CMAKE_CURRENT_BINARY_DIR}/</%text>${lib.name}.pdb
    372         DESTINATION <%text>${gRPC_INSTALL_LIBDIR}</%text> OPTIONAL
    373       )
    374     endif()
    375   endif()
    376 
    377   % for src in lib.src:
    378   % if proto_re.match(src):
    379   protobuf_generate_grpc_cpp(
    380     ${src}
    381   )
    382   % endif
    383   % endfor
    384 
    385   target_include_directories(${lib.name}
    386     PUBLIC <%text>$<INSTALL_INTERFACE:${gRPC_INSTALL_INCLUDEDIR}> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include></%text>
    387     PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>
    388     PRIVATE <%text>${_gRPC_SSL_INCLUDE_DIR}</%text>
    389     PRIVATE <%text>${_gRPC_PROTOBUF_INCLUDE_DIR}</%text>
    390     PRIVATE <%text>${_gRPC_ZLIB_INCLUDE_DIR}</%text>
    391     PRIVATE <%text>${_gRPC_BENCHMARK_INCLUDE_DIR}</%text>
    392     PRIVATE <%text>${_gRPC_CARES_INCLUDE_DIR}</%text>
    393     PRIVATE <%text>${_gRPC_GFLAGS_INCLUDE_DIR}</%text>
    394     PRIVATE <%text>${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}</%text>
    395     PRIVATE <%text>${_gRPC_NANOPB_INCLUDE_DIR}</%text>
    396   % if lib.build in ['test', 'private'] and lib.language == 'c++':
    397     PRIVATE third_party/googletest/googletest/include
    398     PRIVATE third_party/googletest/googletest
    399     PRIVATE third_party/googletest/googlemock/include
    400     PRIVATE third_party/googletest/googlemock
    401   % endif
    402   % if lib.language == 'c++':
    403     PRIVATE <%text>${_gRPC_PROTO_GENS_DIR}</%text>
    404   % endif
    405   )
    406 
    407   % if len(get_deps(lib)) > 0:
    408   target_link_libraries(${lib.name}
    409   % for dep in get_deps(lib):
    410     ${dep}
    411   % endfor
    412   )
    413   % endif
    414   % if lib.name in ["gpr"]:
    415   if (_gRPC_PLATFORM_ANDROID)
    416     target_link_libraries(gpr
    417       android
    418       log
    419     )
    420   endif (_gRPC_PLATFORM_ANDROID)
    421   % endif
    422 
    423   % if len(lib.get('public_headers', [])) > 0:
    424   foreach(_hdr
    425   % for hdr in lib.get('public_headers', []):
    426     ${hdr}
    427   % endfor
    428   )
    429     string(REPLACE "include/" "" _path <%text>${_hdr}</%text>)
    430     get_filename_component(_path <%text>${_path}</%text> PATH)
    431     install(FILES <%text>${_hdr}</%text>
    432       DESTINATION "<%text>${gRPC_INSTALL_INCLUDEDIR}/${_path}</%text>"
    433     )
    434   endforeach()
    435   % endif
    436   % if any(proto_re.match(src) for src in lib.src):
    437   endif (gRPC_BUILD_CODEGEN)
    438   % endif
    439   </%def>
    440 
    441   <%def name="cc_binary(tgt)">
    442   add_executable(${tgt.name}
    443   % for src in tgt.src:
    444   % if not proto_re.match(src):
    445     ${src}
    446   % else:
    447     ${proto_replace_ext(src, '.pb.cc')}
    448     ${proto_replace_ext(src, '.grpc.pb.cc')}
    449     ${proto_replace_ext(src, '.pb.h')}
    450     ${proto_replace_ext(src, '.grpc.pb.h')}
    451   % endif
    452   % endfor
    453   % if tgt.build == 'test' and tgt.language == 'c++':
    454     third_party/googletest/googletest/src/gtest-all.cc
    455     third_party/googletest/googlemock/src/gmock-all.cc
    456   % endif
    457   )
    458 
    459   % for src in tgt.src:
    460   % if proto_re.match(src):
    461   protobuf_generate_grpc_cpp(
    462     ${src}
    463   )
    464   % endif
    465   % endfor
    466 
    467   target_include_directories(${tgt.name}
    468     PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>
    469     PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/include
    470     PRIVATE <%text>${_gRPC_SSL_INCLUDE_DIR}</%text>
    471     PRIVATE <%text>${_gRPC_PROTOBUF_INCLUDE_DIR}</%text>
    472     PRIVATE <%text>${_gRPC_ZLIB_INCLUDE_DIR}</%text>
    473     PRIVATE <%text>${_gRPC_BENCHMARK_INCLUDE_DIR}</%text>
    474     PRIVATE <%text>${_gRPC_CARES_INCLUDE_DIR}</%text>
    475     PRIVATE <%text>${_gRPC_GFLAGS_INCLUDE_DIR}</%text>
    476     PRIVATE <%text>${_gRPC_ADDRESS_SORTING_INCLUDE_DIR}</%text>
    477     PRIVATE <%text>${_gRPC_NANOPB_INCLUDE_DIR}</%text>
    478   % if tgt.build in ['test', 'private'] and tgt.language == 'c++':
    479     PRIVATE third_party/googletest/googletest/include
    480     PRIVATE third_party/googletest/googletest
    481     PRIVATE third_party/googletest/googlemock/include
    482     PRIVATE third_party/googletest/googlemock
    483   % endif
    484   % if tgt.language == 'c++':
    485     PRIVATE <%text>${_gRPC_PROTO_GENS_DIR}</%text>
    486   % endif
    487   )
    488 
    489   % if len(get_deps(tgt)) > 0:
    490   target_link_libraries(${tgt.name}
    491   % for dep in get_deps(tgt):
    492     ${dep}
    493   % endfor
    494   )
    495   % endif
    496   </%def>
    497 
    498   <%def name="cc_install(tgt)">
    499   if (gRPC_INSTALL)
    500     install(TARGETS ${tgt.name} EXPORT gRPCTargets
    501       RUNTIME DESTINATION <%text>${gRPC_INSTALL_BINDIR}</%text>
    502       LIBRARY DESTINATION <%text>${gRPC_INSTALL_LIBDIR}</%text>
    503       ARCHIVE DESTINATION <%text>${gRPC_INSTALL_LIBDIR}</%text>
    504     )
    505   endif()
    506   </%def>
    507 
    508   if (gRPC_INSTALL)
    509     install(EXPORT gRPCTargets
    510       DESTINATION <%text>${gRPC_INSTALL_CMAKEDIR}</%text>
    511       NAMESPACE gRPC::
    512     )
    513   endif()
    514 
    515   foreach(_config gRPCConfig gRPCConfigVersion)
    516     configure_file(cmake/<%text>${_config}</%text>.cmake.in
    517       <%text>${_config}</%text>.cmake @ONLY)
    518     install(FILES <%text>${CMAKE_CURRENT_BINARY_DIR}/${_config}</%text>.cmake
    519       DESTINATION <%text>${gRPC_INSTALL_CMAKEDIR}</%text>
    520     )
    521   endforeach()
    522   
    523   install(FILES <%text>${CMAKE_CURRENT_SOURCE_DIR}/etc/roots.pem</%text>
    524     DESTINATION <%text>${gRPC_INSTALL_SHAREDIR}</%text>)
    525