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 | # |
| 10 | # Additionally, this is currently very experimental, and unsupported. |
| 11 | # Further work will happen on that file. |
| 12 | # |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 13 | # Copyright 2015, Google Inc. |
| 14 | # All rights reserved. |
| 15 | # |
| 16 | # Redistribution and use in source and binary forms, with or without |
| 17 | # modification, are permitted provided that the following conditions are |
| 18 | # met: |
| 19 | # |
| 20 | # * Redistributions of source code must retain the above copyright |
| 21 | # notice, this list of conditions and the following disclaimer. |
| 22 | # * Redistributions in binary form must reproduce the above |
| 23 | # copyright notice, this list of conditions and the following disclaimer |
| 24 | # in the documentation and/or other materials provided with the |
| 25 | # distribution. |
| 26 | # * Neither the name of Google Inc. nor the names of its |
| 27 | # contributors may be used to endorse or promote products derived from |
| 28 | # this software without specific prior written permission. |
| 29 | # |
| 30 | # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 31 | # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 32 | # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 33 | # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 34 | # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 35 | # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 36 | # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 37 | # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 38 | # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 39 | # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 40 | # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 41 | |
| 42 | <%! |
| 43 | def get_deps(target_dict): |
| 44 | deps = [] |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 45 | if target_dict.get('baselib', False): |
| 46 | deps.append("${_gRPC_BASELIB_LIBRARIES}") |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 47 | if target_dict.get('build', None) in ['protoc']: |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 48 | deps.append("${_gRPC_PROTOBUF_PROTOC_LIBRARIES}") |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 49 | if target_dict.get('secure', False): |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 50 | deps.append("${_gRPC_SSL_LIBRARIES}") |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 51 | if target_dict['name'] in ['grpc++', 'grpc++_unsecure', 'grpc++_codegen_lib']: |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 52 | deps.append("${_gRPC_PROTOBUF_LIBRARIES}") |
Tamas Berghammer | df6a44c | 2016-06-22 13:38:55 +0100 | [diff] [blame] | 53 | elif target_dict['name'] in ['grpc']: |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 54 | deps.append("${_gRPC_ZLIB_LIBRARIES}") |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 55 | for d in target_dict.get('deps', []): |
| 56 | deps.append(d) |
| 57 | return deps |
| 58 | %> |
| 59 | |
| 60 | cmake_minimum_required(VERSION 2.8) |
| 61 | |
Tamas Berghammer | df6a44c | 2016-06-22 13:38:55 +0100 | [diff] [blame] | 62 | set(PACKAGE_NAME "grpc") |
Craig Tiller | 83c4789 | 2016-09-13 11:14:43 -0700 | [diff] [blame] | 63 | set(PACKAGE_VERSION "${settings.cpp_version}") |
Tamas Berghammer | df6a44c | 2016-06-22 13:38:55 +0100 | [diff] [blame] | 64 | set(PACKAGE_STRING "<%text>${PACKAGE_NAME} ${PACKAGE_VERSION}</%text>") |
| 65 | set(PACKAGE_TARNAME "<%text>${PACKAGE_NAME}-${PACKAGE_VERSION}</%text>") |
| 66 | set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/") |
| 67 | project(<%text>${PACKAGE_NAME}</%text> C CXX) |
| 68 | |
Arkadiy Shapkin | 40beb37 | 2016-08-17 14:42:36 +0300 | [diff] [blame] | 69 | if (NOT MSVC) |
| 70 | set(gRPC_INSTALL ON CACHE BOOL "Generate installation target") |
| 71 | else() |
| 72 | set(gRPC_INSTALL OFF CACHE BOOL "Generate installation target") |
| 73 | endif() |
| 74 | |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 75 | set(gRPC_ZLIB_PROVIDER "module" CACHE STRING "Provider of zlib library") |
| 76 | set_property(CACHE gRPC_ZLIB_PROVIDER PROPERTY STRINGS "module" "package") |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 77 | |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 78 | set(gRPC_SSL_PROVIDER "module" CACHE STRING "Provider of ssl library") |
| 79 | set_property(CACHE gRPC_SSL_PROVIDER PROPERTY STRINGS "module" "package") |
Tamas Berghammer | a72712e | 2016-07-06 10:30:25 +0100 | [diff] [blame] | 80 | |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 81 | set(gRPC_PROTOBUF_PROVIDER "module" CACHE STRING "Provider of protobuf library") |
| 82 | set_property(CACHE gRPC_PROTOBUF_PROVIDER PROPERTY STRINGS "module" "package") |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 83 | |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 84 | 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] | 85 | |
Arkadiy Shapkin | 40beb37 | 2016-08-17 14:42:36 +0300 | [diff] [blame] | 86 | if (MSVC) |
| 87 | add_definitions( -D_WIN32_WINNT=0x600 ) |
| 88 | endif() |
| 89 | |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 90 | if (gRPC_USE_PROTO_LITE) |
| 91 | set(_gRPC_PROTOBUF_LIBRARY_NAME "libprotobuf-lite") |
Tamas Berghammer | 2391156 | 2016-07-27 15:24:05 +0100 | [diff] [blame] | 92 | add_definitions("-DGRPC_USE_PROTO_LITE") |
| 93 | else() |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 94 | set(_gRPC_PROTOBUF_LIBRARY_NAME "libprotobuf") |
| 95 | endif() |
| 96 | |
| 97 | if("<%text>${gRPC_ZLIB_PROVIDER}</%text>" STREQUAL "module") |
| 98 | if(NOT ZLIB_ROOT_DIR) |
| 99 | set(ZLIB_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/zlib) |
| 100 | endif() |
| 101 | set(ZLIB_INCLUDE_DIR "<%text>${ZLIB_ROOT_DIR}</%text>") |
| 102 | if(EXISTS "<%text>${ZLIB_ROOT_DIR}</%text>/CMakeLists.txt") |
| 103 | add_subdirectory(<%text>${ZLIB_ROOT_DIR}</%text> third_party/zlib) |
| 104 | if(TARGET zlibstatic) |
| 105 | set(_gRPC_ZLIB_LIBRARIES zlibstatic) |
| 106 | endif() |
| 107 | else() |
| 108 | message(WARNING "gRPC_ZLIB_PROVIDER is \"module\" but ZLIB_ROOT_DIR is wrong") |
| 109 | endif() |
| 110 | elseif("<%text>${gRPC_ZLIB_PROVIDER}</%text>" STREQUAL "package") |
| 111 | find_package(ZLIB) |
| 112 | if(TARGET ZLIB::ZLIB) |
| 113 | set(_gRPC_ZLIB_LIBRARIES ZLIB::ZLIB) |
| 114 | endif() |
Konstantin Podsvirov | dd33148 | 2016-07-28 00:00:25 +0300 | [diff] [blame] | 115 | 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] | 116 | endif() |
| 117 | |
| 118 | if("<%text>${gRPC_PROTOBUF_PROVIDER}</%text>" STREQUAL "module") |
| 119 | # Building the protobuf tests require gmock what is not part of a standard protobuf checkout. |
| 120 | # Disable them unless they are explicitly requested from the cmake command line (when we assume |
| 121 | # gmock is downloaded to the right location inside protobuf). |
| 122 | if(NOT protobuf_BUILD_TESTS) |
| 123 | set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests") |
| 124 | endif() |
| 125 | if(NOT PROTOBUF_ROOT_DIR) |
| 126 | set(PROTOBUF_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/protobuf) |
| 127 | endif() |
| 128 | if(EXISTS "<%text>${PROTOBUF_ROOT_DIR}</%text>/cmake/CMakeLists.txt") |
Arkadiy Shapkin | 40beb37 | 2016-08-17 14:42:36 +0300 | [diff] [blame] | 129 | set(protobuf_MSVC_STATIC_RUNTIME OFF CACHE BOOL "Link static runtime libraries") |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 130 | add_subdirectory(<%text>${PROTOBUF_ROOT_DIR}</%text>/cmake third_party/protobuf) |
| 131 | if(TARGET <%text>${_gRPC_PROTOBUF_LIBRARY_NAME}</%text>) |
| 132 | set(_gRPC_PROTOBUF_LIBRARIES <%text>${_gRPC_PROTOBUF_LIBRARY_NAME}</%text>) |
| 133 | endif() |
| 134 | if(TARGET libprotoc) |
| 135 | set(_gRPC_PROTOBUF_PROTOC_LIBRARIES libprotoc) |
| 136 | endif() |
| 137 | else() |
| 138 | message(WARNING "gRPC_PROTOBUF_PROVIDER is \"module\" but PROTOBUF_ROOT_DIR is wrong") |
| 139 | endif() |
| 140 | elseif("<%text>${gRPC_PROTOBUF_PROVIDER}</%text>" STREQUAL "package") |
| 141 | find_package(protobuf CONFIG) |
| 142 | if(protobuf_FOUND) |
| 143 | if(TARGET protobuf::<%text>${_gRPC_PROTOBUF_LIBRARY_NAME}</%text>) |
| 144 | set(_gRPC_PROTOBUF_LIBRARIES protobuf::<%text>${_gRPC_PROTOBUF_LIBRARY_NAME}</%text>) |
| 145 | endif() |
| 146 | if(TARGET protobuf::libprotoc) |
| 147 | set(_gRPC_PROTOBUF_PROTOC_LIBRARIES protobuf::libprotoc) |
| 148 | endif() |
Konstantin Podsvirov | dd33148 | 2016-07-28 00:00:25 +0300 | [diff] [blame] | 149 | 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] | 150 | else() |
| 151 | find_package(Protobuf MODULE) |
Konstantin Podsvirov | dd33148 | 2016-07-28 00:00:25 +0300 | [diff] [blame] | 152 | 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] | 153 | endif() |
| 154 | endif() |
| 155 | |
| 156 | if("<%text>${gRPC_SSL_PROVIDER}</%text>" STREQUAL "module") |
| 157 | if(NOT BORINGSSL_ROOT_DIR) |
| 158 | set(BORINGSSL_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/boringssl) |
| 159 | endif() |
| 160 | if(EXISTS "<%text>${BORINGSSL_ROOT_DIR}</%text>/CMakeLists.txt") |
| 161 | add_subdirectory(<%text>${BORINGSSL_ROOT_DIR}</%text> third_party/boringssl) |
| 162 | if(TARGET ssl) |
| 163 | set(_gRPC_SSL_LIBRARIES ssl) |
| 164 | endif() |
| 165 | else() |
| 166 | message(WARNING "gRPC_SSL_PROVIDER is \"module\" but BORINGSSL_ROOT_DIR is wrong") |
| 167 | endif() |
| 168 | elseif("<%text>${gRPC_SSL_PROVIDER}</%text>" STREQUAL "package") |
| 169 | find_package(OpenSSL) |
| 170 | if(TARGET OpenSSL::SSL) |
| 171 | set(_gRPC_SSL_LIBRARIES OpenSSL::SSL) |
| 172 | endif() |
Konstantin Podsvirov | dd33148 | 2016-07-28 00:00:25 +0300 | [diff] [blame] | 173 | 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] | 174 | endif() |
| 175 | |
| 176 | if(NOT MSVC) |
| 177 | set(CMAKE_C_FLAGS "<%text>${CMAKE_C_FLAGS}</%text> -std=c11") |
| 178 | set(CMAKE_CXX_FLAGS "<%text>${CMAKE_CXX_FLAGS}</%text> -std=c++11") |
| 179 | endif() |
| 180 | |
| 181 | if(WIN32 AND MSVC) |
| 182 | set(_gRPC_BASELIB_LIBRARIES wsock32 ws2_32) |
Tamas Berghammer | 2391156 | 2016-07-27 15:24:05 +0100 | [diff] [blame] | 183 | endif() |
| 184 | |
Konstantin Podsvirov | d2b8830 | 2016-07-27 23:43:47 +0300 | [diff] [blame] | 185 | include(GNUInstallDirs) |
| 186 | if(NOT DEFINED CMAKE_INSTALL_CMAKEDIR) |
| 187 | set(CMAKE_INSTALL_CMAKEDIR "<%text>${CMAKE_INSTALL_LIBDIR}</%text>/cmake/gRPC") |
| 188 | endif() |
| 189 | |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 190 | % for lib in libs: |
Tamas Berghammer | df6a44c | 2016-06-22 13:38:55 +0100 | [diff] [blame] | 191 | % if lib.build in ["all", "protoc", "tool"]: |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 192 | ${cc_library(lib)} |
Konstantin Podsvirov | d2b8830 | 2016-07-27 23:43:47 +0300 | [diff] [blame] | 193 | ${cc_install(lib)} |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 194 | % endif |
| 195 | % endfor |
| 196 | |
| 197 | % for tgt in targets: |
Tamas Berghammer | df6a44c | 2016-06-22 13:38:55 +0100 | [diff] [blame] | 198 | % if tgt.build in ["all", "protoc", "tool"]: |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 199 | ${cc_binary(tgt)} |
Konstantin Podsvirov | d2b8830 | 2016-07-27 23:43:47 +0300 | [diff] [blame] | 200 | ${cc_install(tgt)} |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 201 | % endif |
| 202 | % endfor |
| 203 | |
| 204 | <%def name="cc_library(lib)"> |
| 205 | add_library(${lib.name} |
| 206 | % for src in lib.src: |
| 207 | ${src} |
| 208 | % endfor |
| 209 | ) |
| 210 | |
| 211 | target_include_directories(${lib.name} |
| 212 | PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text> |
| 213 | PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/include |
| 214 | PRIVATE <%text>${BORINGSSL_ROOT_DIR}</%text>/include |
| 215 | PRIVATE <%text>${PROTOBUF_ROOT_DIR}</%text>/src |
Konstantin Podsvirov | 5baf725 | 2016-07-27 16:25:37 +0300 | [diff] [blame] | 216 | PRIVATE <%text>${ZLIB_INCLUDE_DIR}</%text> |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 217 | PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}</%text>/third_party/zlib |
| 218 | ) |
| 219 | |
| 220 | % if len(get_deps(lib)) > 0: |
| 221 | target_link_libraries(${lib.name} |
| 222 | % for dep in get_deps(lib): |
| 223 | ${dep} |
| 224 | % endfor |
| 225 | ) |
| 226 | % endif |
Konstantin Podsvirov | d2b8830 | 2016-07-27 23:43:47 +0300 | [diff] [blame] | 227 | |
| 228 | % if len(lib.get('public_headers', [])) > 0: |
| 229 | foreach(_hdr |
| 230 | % for hdr in lib.get('public_headers', []): |
| 231 | ${hdr} |
| 232 | % endfor |
| 233 | ) |
| 234 | string(REPLACE "include/" "" _path <%text>${_hdr}</%text>) |
| 235 | get_filename_component(_path <%text>${_path}</%text> PATH) |
| 236 | install(FILES <%text>${_hdr}</%text> |
| 237 | DESTINATION "<%text>${CMAKE_INSTALL_INCLUDEDIR}/${_path}</%text>" |
| 238 | ) |
| 239 | endforeach() |
| 240 | % endif |
Tamas Berghammer | d798a7d | 2016-06-21 13:58:18 +0100 | [diff] [blame] | 241 | </%def> |
| 242 | |
| 243 | <%def name="cc_binary(tgt)"> |
| 244 | add_executable(${tgt.name} |
| 245 | % for src in tgt.src: |
| 246 | ${src} |
| 247 | % endfor |
| 248 | ) |
| 249 | |
| 250 | target_include_directories(${tgt.name} |
| 251 | PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text> |
| 252 | PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/include |
| 253 | PRIVATE <%text>${BORINGSSL_ROOT_DIR}</%text>/include |
| 254 | PRIVATE <%text>${PROTOBUF_ROOT_DIR}</%text>/src |
| 255 | PRIVATE <%text>${ZLIB_ROOT_DIR}</%text> |
| 256 | PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}</%text>/third_party/zlib |
| 257 | ) |
| 258 | |
| 259 | % if len(get_deps(tgt)) > 0: |
| 260 | target_link_libraries(${tgt.name} |
| 261 | % for dep in get_deps(tgt): |
| 262 | ${dep} |
| 263 | % endfor |
| 264 | ) |
| 265 | % endif |
| 266 | </%def> |
| 267 | |
Konstantin Podsvirov | d2b8830 | 2016-07-27 23:43:47 +0300 | [diff] [blame] | 268 | <%def name="cc_install(tgt)"> |
Arkadiy Shapkin | 40beb37 | 2016-08-17 14:42:36 +0300 | [diff] [blame] | 269 | if (gRPC_INSTALL) |
| 270 | install(TARGETS ${tgt.name} EXPORT gRPCTargets |
| 271 | RUNTIME DESTINATION <%text>${CMAKE_INSTALL_BINDIR}</%text> |
| 272 | LIBRARY DESTINATION <%text>${CMAKE_INSTALL_LIBDIR}</%text> |
| 273 | ARCHIVE DESTINATION <%text>${CMAKE_INSTALL_LIBDIR}</%text> |
| 274 | ) |
| 275 | endif() |
Konstantin Podsvirov | d2b8830 | 2016-07-27 23:43:47 +0300 | [diff] [blame] | 276 | </%def> |
| 277 | |
Arkadiy Shapkin | 40beb37 | 2016-08-17 14:42:36 +0300 | [diff] [blame] | 278 | if (gRPC_INSTALL) |
| 279 | install(EXPORT gRPCTargets |
| 280 | DESTINATION <%text>${CMAKE_INSTALL_CMAKEDIR}</%text> |
| 281 | NAMESPACE gRPC:: |
| 282 | ) |
| 283 | endif() |
Konstantin Podsvirov | d2b8830 | 2016-07-27 23:43:47 +0300 | [diff] [blame] | 284 | |
| 285 | foreach(_config gRPCConfig gRPCConfigVersion) |
| 286 | configure_file(tools/cmake/<%text>${_config}</%text>.cmake.in |
| 287 | <%text>${_config}</%text>.cmake @ONLY) |
| 288 | install(FILES <%text>${CMAKE_CURRENT_BINARY_DIR}/${_config}</%text>.cmake |
| 289 | DESTINATION <%text>${CMAKE_INSTALL_CMAKEDIR}</%text> |
| 290 | ) |
| 291 | endforeach() |