| 1 |
# Copyright 2018 gRPC authors. |
| 2 |
# |
| 3 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 |
# you may not use this file except in compliance with the License. |
| 5 |
# You may obtain a copy of the License at |
| 6 |
# |
| 7 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 8 |
# |
| 9 |
# Unless required by applicable law or agreed to in writing, software |
| 10 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 11 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 |
# See the License for the specific language governing permissions and |
| 13 |
# limitations under the License. |
| 14 |
# |
| 15 |
# cmake "superbuild" file for C++ helloworld example. |
| 16 |
# This build file demonstrates how to build the helloworld project |
| 17 |
# and all its dependencies in a single cmake build (hence "superbuild") |
| 18 |
# that is easy to build and maintain. |
| 19 |
# cmake's ExternalProject_Add() is used to import all the sub-projects, |
| 20 |
# including the "helloworld" project itself. |
| 21 |
# See https://blog.kitware.com/cmake-superbuilds-git-submodules/ |
| 22 |
|
| 23 |
cmake_minimum_required(VERSION 3.5.1) |
| 24 |
|
| 25 |
# Project |
| 26 |
project(HelloWorld-SuperBuild C CXX) |
| 27 |
|
| 28 |
include(ExternalProject) |
| 29 |
|
| 30 |
# Note: For all external projects, instead of using checked-out code, one could |
| 31 |
# specify GIT_REPOSITORY and GIT_TAG to have cmake download the dependency directly, |
| 32 |
# without needing to add a submodule to your project. |
| 33 |
|
| 34 |
# Builds absl project from the git submodule. |
| 35 |
ExternalProject_Add(absl |
| 36 |
PREFIX absl |
| 37 |
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party/abseil-cpp" |
| 38 |
CMAKE_CACHE_ARGS |
| 39 |
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=TRUE |
| 40 |
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/absl |
| 41 |
) |
| 42 |
|
| 43 |
# Builds c-ares project from the git submodule. |
| 44 |
ExternalProject_Add(c-ares |
| 45 |
PREFIX c-ares |
| 46 |
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party/cares/cares" |
| 47 |
CMAKE_CACHE_ARGS |
| 48 |
-DCARES_SHARED:BOOL=OFF |
| 49 |
-DCARES_STATIC:BOOL=ON |
| 50 |
-DCARES_STATIC_PIC:BOOL=ON |
| 51 |
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/c-ares |
| 52 |
) |
| 53 |
|
| 54 |
# Builds protobuf project from the git submodule. |
| 55 |
ExternalProject_Add(protobuf |
| 56 |
PREFIX protobuf |
| 57 |
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party/protobuf/cmake" |
| 58 |
CMAKE_CACHE_ARGS |
| 59 |
-Dprotobuf_BUILD_TESTS:BOOL=OFF |
| 60 |
-Dprotobuf_WITH_ZLIB:BOOL=OFF |
| 61 |
-Dprotobuf_MSVC_STATIC_RUNTIME:BOOL=OFF |
| 62 |
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/protobuf |
| 63 |
) |
| 64 |
|
| 65 |
# Builds re2 project from the git submodule. |
| 66 |
ExternalProject_Add(re2 |
| 67 |
PREFIX re2 |
| 68 |
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party/re2" |
| 69 |
CMAKE_CACHE_ARGS |
| 70 |
-DCMAKE_POSITION_INDEPENDENT_CODE:BOOL=TRUE |
| 71 |
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/re2 |
| 72 |
) |
| 73 |
|
| 74 |
# Builds zlib project from the git submodule. |
| 75 |
ExternalProject_Add(zlib |
| 76 |
PREFIX zlib |
| 77 |
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../../third_party/zlib" |
| 78 |
CMAKE_CACHE_ARGS |
| 79 |
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/zlib |
| 80 |
) |
| 81 |
|
| 82 |
# the location where protobuf-config.cmake will be installed varies by platform |
| 83 |
if (WIN32) |
| 84 |
set(_FINDPACKAGE_PROTOBUF_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/protobuf/cmake") |
| 85 |
else() |
| 86 |
set(_FINDPACKAGE_PROTOBUF_CONFIG_DIR "${CMAKE_CURRENT_BINARY_DIR}/protobuf/lib/cmake/protobuf") |
| 87 |
endif() |
| 88 |
|
| 89 |
# if OPENSSL_ROOT_DIR is set, propagate that hint path to the external projects with OpenSSL dependency. |
| 90 |
set(_CMAKE_ARGS_OPENSSL_ROOT_DIR "") |
| 91 |
if (OPENSSL_ROOT_DIR) |
| 92 |
set(_CMAKE_ARGS_OPENSSL_ROOT_DIR "-DOPENSSL_ROOT_DIR:PATH=${OPENSSL_ROOT_DIR}") |
| 93 |
endif() |
| 94 |
|
| 95 |
# Builds gRPC based on locally checked-out sources and set arguments so that all the dependencies |
| 96 |
# are correctly located. |
| 97 |
ExternalProject_Add(grpc |
| 98 |
PREFIX grpc |
| 99 |
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/../../../.." |
| 100 |
CMAKE_CACHE_ARGS |
| 101 |
-DgRPC_INSTALL:BOOL=ON |
| 102 |
-DgRPC_BUILD_TESTS:BOOL=OFF |
| 103 |
-DgRPC_BUILD_MSVC_MP_COUNT:STRING=-1 |
| 104 |
-DgRPC_PROTOBUF_PROVIDER:STRING=package |
| 105 |
-DgRPC_PROTOBUF_PACKAGE_TYPE:STRING=CONFIG |
| 106 |
-DProtobuf_DIR:PATH=${_FINDPACKAGE_PROTOBUF_CONFIG_DIR} |
| 107 |
-DgRPC_RE2_PROVIDER:STRING=package |
| 108 |
-Dre2_DIR:STRING=${CMAKE_CURRENT_BINARY_DIR}/re2/lib/cmake/re2 |
| 109 |
-DgRPC_ZLIB_PROVIDER:STRING=package |
| 110 |
-DZLIB_ROOT:STRING=${CMAKE_CURRENT_BINARY_DIR}/zlib |
| 111 |
-DgRPC_ABSL_PROVIDER:STRING=package |
| 112 |
-Dabsl_DIR:STRING=${CMAKE_CURRENT_BINARY_DIR}/absl/lib/cmake/absl |
| 113 |
-DgRPC_CARES_PROVIDER:STRING=package |
| 114 |
-Dc-ares_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/c-ares/lib/cmake/c-ares |
| 115 |
-DgRPC_SSL_PROVIDER:STRING=package |
| 116 |
${_CMAKE_ARGS_OPENSSL_ROOT_DIR} |
| 117 |
-DCMAKE_INSTALL_PREFIX:PATH=${CMAKE_CURRENT_BINARY_DIR}/grpc |
| 118 |
DEPENDS c-ares protobuf re2 zlib absl |
| 119 |
) |
| 120 |
|
| 121 |
# Build the helloworld projects itself using a CMakeLists.txt that assumes all the dependencies |
| 122 |
# have already been installed. |
| 123 |
# Even though helloworld is not really an "external project" from perspective of this build, |
| 124 |
# we are still importing it using ExternalProject_Add because that allows us to use find_package() |
| 125 |
# to locate all the dependencies (if we were building helloworld directly in this build we, |
| 126 |
# we would have needed to manually import the libraries as opposed to reusing targets exported by |
| 127 |
# gRPC and protobuf). |
| 128 |
ExternalProject_Add(helloworld |
| 129 |
PREFIX helloworld |
| 130 |
SOURCE_DIR "${CMAKE_CURRENT_SOURCE_DIR}/.." |
| 131 |
BINARY_DIR "${CMAKE_CURRENT_BINARY_DIR}/helloworld" |
| 132 |
INSTALL_COMMAND "" |
| 133 |
CMAKE_CACHE_ARGS |
| 134 |
-DProtobuf_DIR:PATH=${_FINDPACKAGE_PROTOBUF_CONFIG_DIR} |
| 135 |
-Dc-ares_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/c-ares/lib/cmake/c-ares |
| 136 |
-Dre2_DIR:STRING=${CMAKE_CURRENT_BINARY_DIR}/re2/lib/cmake/re2 |
| 137 |
-DZLIB_ROOT:STRING=${CMAKE_CURRENT_BINARY_DIR}/zlib |
| 138 |
-Dabsl_DIR:STRING=${CMAKE_CURRENT_BINARY_DIR}/absl/lib/cmake/absl |
| 139 |
${_CMAKE_ARGS_OPENSSL_ROOT_DIR} |
| 140 |
-DgRPC_DIR:PATH=${CMAKE_CURRENT_BINARY_DIR}/grpc/lib/cmake/grpc |
| 141 |
DEPENDS protobuf grpc |
| 142 |
) |