blob: 52e8b866be1b6a645349101fbd0b03a3a712cf34 [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 #
10 # Additionally, this is currently very experimental, and unsupported.
11 # Further work will happen on that file.
12 #
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010013 # 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 = []
45 if target_dict.get('build', None) in ['protoc']:
46 deps.append("libprotoc")
47 if target_dict.get('secure', False):
48 deps = ["ssl"]
49 if target_dict['name'] in ['grpc++', 'grpc++_unsecure', 'grpc++_codegen_lib']:
50 deps.append("libprotobuf")
Tamas Berghammerdf6a44c2016-06-22 13:38:55 +010051 elif target_dict['name'] in ['grpc']:
52 deps.append("zlibstatic")
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010053 for d in target_dict.get('deps', []):
54 deps.append(d)
55 return deps
56 %>
57
58 cmake_minimum_required(VERSION 2.8)
59
Tamas Berghammerdf6a44c2016-06-22 13:38:55 +010060 set(PACKAGE_NAME "grpc")
61 set(PACKAGE_VERSION "${settings.core_version}")
62 set(PACKAGE_STRING "<%text>${PACKAGE_NAME} ${PACKAGE_VERSION}</%text>")
63 set(PACKAGE_TARNAME "<%text>${PACKAGE_NAME}-${PACKAGE_VERSION}</%text>")
64 set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/")
65 project(<%text>${PACKAGE_NAME}</%text> C CXX)
66
67 if(NOT BORINGSSL_ROOT_DIR)
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010068 set(BORINGSSL_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/boringssl)
69 endif()
Tamas Berghammerdf6a44c2016-06-22 13:38:55 +010070 if(NOT PROTOBUF_ROOT_DIR)
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010071 set(PROTOBUF_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/protobuf)
72 endif()
Tamas Berghammerdf6a44c2016-06-22 13:38:55 +010073 if(NOT ZLIB_ROOT_DIR)
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010074 set(ZLIB_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/zlib)
75 endif()
76
Tamas Berghammera72712e2016-07-06 10:30:25 +010077 # Building the protobuf tests require gmock what is not part of a standard protobuf checkout.
78 # Disable them unless they are explicitly requested from the cmake command line (when we assume
79 # gmock is downloaded to the right location inside protobuf).
80 if(NOT protobuf_BUILD_TESTS)
81 set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests")
82 endif()
83
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010084 add_subdirectory(<%text>${BORINGSSL_ROOT_DIR}</%text> third_party/boringssl)
85 add_subdirectory(<%text>${PROTOBUF_ROOT_DIR}</%text>/cmake third_party/protobuf)
86 add_subdirectory(<%text>${ZLIB_ROOT_DIR}</%text> third_party/zlib)
87
Tamas Berghammerdf6a44c2016-06-22 13:38:55 +010088 set(CMAKE_C_FLAGS "<%text>${CMAKE_C_FLAGS}</%text> -std=c11")
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010089 set(CMAKE_CXX_FLAGS "<%text>${CMAKE_CXX_FLAGS}</%text> -std=c++11")
90
91 % for lib in libs:
Tamas Berghammerdf6a44c2016-06-22 13:38:55 +010092 % if lib.build in ["all", "protoc", "tool"]:
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010093 ${cc_library(lib)}
94 % endif
95 % endfor
96
97 % for tgt in targets:
Tamas Berghammerdf6a44c2016-06-22 13:38:55 +010098 % if tgt.build in ["all", "protoc", "tool"]:
Tamas Berghammerd798a7d2016-06-21 13:58:18 +010099 ${cc_binary(tgt)}
100 % endif
101 % endfor
102
103 <%def name="cc_library(lib)">
104 add_library(${lib.name}
105 % for src in lib.src:
106 ${src}
107 % endfor
108 )
109
110 target_include_directories(${lib.name}
111 PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>
112 PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/include
113 PRIVATE <%text>${BORINGSSL_ROOT_DIR}</%text>/include
114 PRIVATE <%text>${PROTOBUF_ROOT_DIR}</%text>/src
115 PRIVATE <%text>${ZLIB_ROOT_DIR}</%text>
116 PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}</%text>/third_party/zlib
117 )
118
119 % if len(get_deps(lib)) > 0:
120 target_link_libraries(${lib.name}
121 % for dep in get_deps(lib):
122 ${dep}
123 % endfor
124 )
125 % endif
126 </%def>
127
128 <%def name="cc_binary(tgt)">
129 add_executable(${tgt.name}
130 % for src in tgt.src:
131 ${src}
132 % endfor
133 )
134
135 target_include_directories(${tgt.name}
136 PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>
137 PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/include
138 PRIVATE <%text>${BORINGSSL_ROOT_DIR}</%text>/include
139 PRIVATE <%text>${PROTOBUF_ROOT_DIR}</%text>/src
140 PRIVATE <%text>${ZLIB_ROOT_DIR}</%text>
141 PRIVATE <%text>${CMAKE_CURRENT_BINARY_DIR}</%text>/third_party/zlib
142 )
143
144 % if len(get_deps(tgt)) > 0:
145 target_link_libraries(${tgt.name}
146 % for dep in get_deps(tgt):
147 ${dep}
148 % endfor
149 )
150 % endif
151 </%def>
152