aboutsummaryrefslogtreecommitdiffhomepage
path: root/templates/CMakeLists.txt.template
diff options
context:
space:
mode:
Diffstat (limited to 'templates/CMakeLists.txt.template')
-rw-r--r--templates/CMakeLists.txt.template133
1 files changed, 80 insertions, 53 deletions
diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template
index 2252a7ea80..850404baad 100644
--- a/templates/CMakeLists.txt.template
+++ b/templates/CMakeLists.txt.template
@@ -7,34 +7,19 @@
# This file can be regenerated from the template by running
# tools/buildgen/generate_projects.sh
#
- # Copyright 2015, Google Inc.
- # All rights reserved.
+ # Copyright 2015 gRPC authors.
#
- # Redistribution and use in source and binary forms, with or without
- # modification, are permitted provided that the following conditions are
- # met:
+ # Licensed under the Apache License, Version 2.0 (the "License");
+ # you may not use this file except in compliance with the License.
+ # You may obtain a copy of the License at
#
- # * Redistributions of source code must retain the above copyright
- # notice, this list of conditions and the following disclaimer.
- # * Redistributions in binary form must reproduce the above
- # copyright notice, this list of conditions and the following disclaimer
- # in the documentation and/or other materials provided with the
- # distribution.
- # * Neither the name of Google Inc. nor the names of its
- # contributors may be used to endorse or promote products derived from
- # this software without specific prior written permission.
+ # http://www.apache.org/licenses/LICENSE-2.0
#
- # THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
- # "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
- # LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
- # A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
- # OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
- # SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
- # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
- # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
- # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
- # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
- # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ # Unless required by applicable law or agreed to in writing, software
+ # distributed under the License is distributed on an "AS IS" BASIS,
+ # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ # See the License for the specific language governing permissions and
+ # limitations under the License.
<%!
@@ -58,7 +43,7 @@
deps.append("${_gRPC_SSL_LIBRARIES}")
if target_dict.language == 'c++':
deps.append("${_gRPC_PROTOBUF_LIBRARIES}")
- if target_dict['name'] in ['grpc']:
+ if target_dict['name'] in ['grpc', 'grpc_cronet', 'grpc_unsecure']:
deps.append("${_gRPC_ZLIB_LIBRARIES}")
deps.append("${_gRPC_CARES_LIBRARIES}")
deps.append("${_gRPC_ALLTARGETS_LIBRARIES}")
@@ -88,15 +73,22 @@
set(PACKAGE_TARNAME "<%text>${PACKAGE_NAME}-${PACKAGE_VERSION}</%text>")
set(PACKAGE_BUGREPORT "https://github.com/grpc/grpc/issues/")
project(<%text>${PACKAGE_NAME}</%text> C CXX)
+
+ set(gRPC_INSTALL_BINDIR "<%text>${CMAKE_INSTALL_PREFIX}</%text>/bin" CACHE PATH "Installation directory for executables")
+ set(gRPC_INSTALL_LIBDIR "<%text>${CMAKE_INSTALL_PREFIX}</%text>/lib" CACHE PATH "Installation directory for libraries")
+ set(gRPC_INSTALL_INCLUDEDIR "<%text>${CMAKE_INSTALL_PREFIX}</%text>/include" CACHE PATH "Installation directory for headers")
+ set(gRPC_INSTALL_CMAKEDIR "<%text>${CMAKE_INSTALL_PREFIX}/lib/cmake/${PACKAGE_NAME}</%text>" CACHE PATH "Installation directory for cmake config files")
# Options
option(gRPC_BUILD_TESTS "Build tests" OFF)
- if (NOT MSVC)
- set(gRPC_INSTALL ON CACHE BOOL "Generate installation target")
- else()
- set(gRPC_INSTALL OFF CACHE BOOL "Generate installation target")
+ set(gRPC_INSTALL_default ON)
+ if (NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR)
+ # Disable gRPC_INSTALL by default if building as a submodule
+ set(gRPC_INSTALL_default OFF)
endif()
+ set(gRPC_INSTALL <%text>${gRPC_INSTALL_default}</%text> CACHE BOOL
+ "Generate installation target: gRPC_ZLIB_PROVIDER, gRPC_CARES_PROVIDER, gRPC_SSL_PROVIDER and gRPC_PROTOBUF_PROVIDER must all be \"package\"")
set(gRPC_ZLIB_PROVIDER "module" CACHE STRING "Provider of zlib library")
set_property(CACHE gRPC_ZLIB_PROVIDER PROPERTY STRINGS "module" "package")
@@ -110,6 +102,9 @@
set(gRPC_PROTOBUF_PROVIDER "module" CACHE STRING "Provider of protobuf library")
set_property(CACHE gRPC_PROTOBUF_PROVIDER PROPERTY STRINGS "module" "package")
+ set(gRPC_PROTOBUF_PACKAGE_TYPE "" CACHE STRING "Algorithm for searching protobuf package")
+ set_property(CACHE gRPC_PROTOBUF_PACKAGE_TYPE PROPERTY STRINGS "CONFIG" "MODULE")
+
set(gRPC_GFLAGS_PROVIDER "module" CACHE STRING "Provider of gflags library")
set_property(CACHE gRPC_GFLAGS_PROVIDER PROPERTY STRINGS "module" "package")
@@ -156,6 +151,9 @@
endif()
set(ZLIB_INCLUDE_DIR "<%text>${ZLIB_ROOT_DIR}</%text>")
if(EXISTS "<%text>${ZLIB_ROOT_DIR}</%text>/CMakeLists.txt")
+ # TODO(jtattermusch): workaround for https://github.com/madler/zlib/issues/218
+ include_directories(<%text>${ZLIB_INCLUDE_DIR}</%text>)
+
add_subdirectory(<%text>${ZLIB_ROOT_DIR}</%text> third_party/zlib)
if(TARGET zlibstatic)
set(_gRPC_ZLIB_LIBRARIES zlibstatic)
@@ -163,6 +161,10 @@
else()
message(WARNING "gRPC_ZLIB_PROVIDER is \"module\" but ZLIB_ROOT_DIR is wrong")
endif()
+ if(gRPC_INSTALL)
+ message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_ZLIB_PROVIDER is \"module\"")
+ set(gRPC_INSTALL FALSE)
+ endif()
elseif("<%text>${gRPC_ZLIB_PROVIDER}</%text>" STREQUAL "package")
find_package(ZLIB)
if(TARGET ZLIB::ZLIB)
@@ -194,12 +196,16 @@
else()
message(WARNING "gRPC_CARES_PROVIDER is \"module\" but CARES_ROOT_DIR is wrong")
endif()
+ if(gRPC_INSTALL)
+ message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_CARES_PROVIDER is \"module\"")
+ set(gRPC_INSTALL FALSE)
+ endif()
elseif("<%text>${gRPC_CARES_PROVIDER}</%text>" STREQUAL "package")
- find_package(CARES)
- if(TARGET CARES::CARES)
- set(_gRPC_CARES_LIBRARIES CARES::CARES)
+ find_package(c-ares CONFIG)
+ if(TARGET c-ares::cares)
+ set(_gRPC_CARES_LIBRARIES c-ares::cares)
endif()
- set(_gRPC_FIND_CARES "if(NOT CARES_FOUND)\n find_package(CARES)\nendif()")
+ set(_gRPC_FIND_CARES "if(NOT c-ares_FOUND)\n find_package(c-ares CONFIG)\nendif()")
endif()
if("<%text>${gRPC_PROTOBUF_PROVIDER}</%text>" STREQUAL "module")
@@ -209,6 +215,11 @@
if(NOT protobuf_BUILD_TESTS)
set(protobuf_BUILD_TESTS OFF CACHE BOOL "Build protobuf tests")
endif()
+ # Disable building protobuf with zlib. Building protobuf with zlib breaks
+ # the build if zlib is not installed on the system.
+ if(NOT protobuf_WITH_ZLIB)
+ set(protobuf_WITH_ZLIB OFF CACHE BOOL "Build protobuf with zlib.")
+ endif()
if(NOT PROTOBUF_ROOT_DIR)
set(PROTOBUF_ROOT_DIR <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/third_party/protobuf)
endif()
@@ -228,22 +239,32 @@
else()
message(WARNING "gRPC_PROTOBUF_PROVIDER is \"module\" but PROTOBUF_ROOT_DIR is wrong")
endif()
+ if(gRPC_INSTALL)
+ message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_PROTOBUF_PROVIDER is \"module\"")
+ set(gRPC_INSTALL FALSE)
+ endif()
elseif("<%text>${gRPC_PROTOBUF_PROVIDER}</%text>" STREQUAL "package")
- find_package(protobuf CONFIG)
- if(protobuf_FOUND)
+ find_package(Protobuf <%text>${gRPC_PROTOBUF_PACKAGE_TYPE}</%text>)
+ if(Protobuf_FOUND OR PROTOBUF_FOUND)
if(TARGET protobuf::<%text>${_gRPC_PROTOBUF_LIBRARY_NAME}</%text>)
set(_gRPC_PROTOBUF_LIBRARIES protobuf::<%text>${_gRPC_PROTOBUF_LIBRARY_NAME}</%text>)
+ else()
+ set(_gRPC_PROTOBUF_LIBRARIES <%text>${PROTOBUF_LIBRARIES}</%text>)
endif()
if(TARGET protobuf::libprotoc)
set(_gRPC_PROTOBUF_PROTOC_LIBRARIES protobuf::libprotoc)
+ else()
+ set(_gRPC_PROTOBUF_PROTOC_LIBRARIES <%text>${PROTOBUF_PROTOC_LIBRARIES}</%text>)
endif()
if(TARGET protobuf::protoc)
set(_gRPC_PROTOBUF_PROTOC protobuf::protoc)
+ else()
+ set(_gRPC_PROTOBUF_PROTOC <%text>${PROTOBUF_PROTOC_EXECUTABLE}</%text>)
endif()
- set(_gRPC_FIND_PROTOBUF "if(NOT protobuf_FOUND)\n find_package(protobuf CONFIG)\nendif()")
- else()
- find_package(Protobuf MODULE)
- set(_gRPC_FIND_PROTOBUF "if(NOT Protobuf_FOUND)\n find_package(Protobuf)\nendif()")
+ set(_gRPC_FIND_PROTOBUF "if(NOT Protobuf_FOUND AND NOT PROTOBUF_FOUND)\n find_package(Protobuf <%text>${gRPC_PROTOBUF_PACKAGE_TYPE}</%text>)\nendif()")
+ endif()
+ if(PROTOBUF_FOUND)
+ include_directories(<%text>${PROTOBUF_INCLUDE_DIRS}</%text>)
endif()
set(PROTOBUF_WELLKNOWN_IMPORT_DIR /usr/local/include)
endif()
@@ -261,6 +282,10 @@
else()
message(WARNING "gRPC_SSL_PROVIDER is \"module\" but BORINGSSL_ROOT_DIR is wrong")
endif()
+ if(gRPC_INSTALL)
+ message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_SSL_PROVIDER is \"module\"")
+ set(gRPC_INSTALL FALSE)
+ endif()
elseif("<%text>${gRPC_SSL_PROVIDER}</%text>" STREQUAL "package")
find_package(OpenSSL)
if(TARGET OpenSSL::SSL)
@@ -324,11 +349,6 @@
set(_gRPC_BASELIB_LIBRARIES wsock32 ws2_32)
endif()
- include(GNUInstallDirs)
- if(NOT DEFINED CMAKE_INSTALL_CMAKEDIR)
- set(CMAKE_INSTALL_CMAKEDIR "<%text>${CMAKE_INSTALL_LIBDIR}</%text>/cmake/gRPC")
- endif()
-
# Create directory for generated .proto files
set(_gRPC_PROTO_GENS_DIR <%text>${CMAKE_BINARY_DIR}/gens</%text>)
file(MAKE_DIRECTORY <%text>${_gRPC_PROTO_GENS_DIR}</%text>)
@@ -364,7 +384,7 @@
<%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}_mock.grpc.pb.h"</%text>
<%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.cc"</%text>
<%text>"${_gRPC_PROTO_GENS_DIR}/${RELFIL_WE}.pb.h"</%text>
- COMMAND <%text>${_gRPC_PROTOBUF_PROTOC}</%text>
+ COMMAND <%text>$<TARGET_FILE:${_gRPC_PROTOBUF_PROTOC}></%text>
ARGS --grpc_out=<%text>generate_mock_code=true:${_gRPC_PROTO_GENS_DIR}</%text>
--cpp_out=<%text>${_gRPC_PROTO_GENS_DIR}</%text>
--plugin=protoc-gen-grpc=$<TARGET_FILE:grpc_cpp_plugin>
@@ -489,7 +509,7 @@
)
if (gRPC_INSTALL)
install(FILES <%text>${CMAKE_CURRENT_BINARY_DIR}/</%text>${lib.name}.pdb
- DESTINATION <%text>${CMAKE_INSTALL_LIBDIR}</%text> OPTIONAL
+ DESTINATION <%text>${gRPC_INSTALL_LIBDIR}</%text> OPTIONAL
)
endif()
endif()
@@ -503,8 +523,8 @@
% endfor
target_include_directories(${lib.name}
+ PUBLIC <%text>$<INSTALL_INTERFACE:include> $<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include></%text>
PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>
- PRIVATE <%text>${CMAKE_CURRENT_SOURCE_DIR}</%text>/include
PRIVATE <%text>${BORINGSSL_ROOT_DIR}</%text>/include
PRIVATE <%text>${PROTOBUF_ROOT_DIR}</%text>/src
PRIVATE <%text>${ZLIB_INCLUDE_DIR}</%text>
@@ -543,7 +563,7 @@
string(REPLACE "include/" "" _path <%text>${_hdr}</%text>)
get_filename_component(_path <%text>${_path}</%text> PATH)
install(FILES <%text>${_hdr}</%text>
- DESTINATION "<%text>${CMAKE_INSTALL_INCLUDEDIR}/${_path}</%text>"
+ DESTINATION "<%text>${gRPC_INSTALL_INCLUDEDIR}/${_path}</%text>"
)
endforeach()
% endif
@@ -611,17 +631,24 @@
<%def name="cc_install(tgt)">
if (gRPC_INSTALL)
install(TARGETS ${tgt.name} EXPORT gRPCTargets
- RUNTIME DESTINATION <%text>${CMAKE_INSTALL_BINDIR}</%text>
- LIBRARY DESTINATION <%text>${CMAKE_INSTALL_LIBDIR}</%text>
- ARCHIVE DESTINATION <%text>${CMAKE_INSTALL_LIBDIR}</%text>
+ RUNTIME DESTINATION <%text>${gRPC_INSTALL_BINDIR}</%text>
+ LIBRARY DESTINATION <%text>${gRPC_INSTALL_LIBDIR}</%text>
+ ARCHIVE DESTINATION <%text>${gRPC_INSTALL_LIBDIR}</%text>
)
endif()
</%def>
+ if (gRPC_INSTALL)
+ install(EXPORT gRPCTargets
+ DESTINATION <%text>${gRPC_INSTALL_CMAKEDIR}</%text>
+ NAMESPACE gRPC::
+ )
+ endif()
+
foreach(_config gRPCConfig gRPCConfigVersion)
configure_file(tools/cmake/<%text>${_config}</%text>.cmake.in
<%text>${_config}</%text>.cmake @ONLY)
install(FILES <%text>${CMAKE_CURRENT_BINARY_DIR}/${_config}</%text>.cmake
- DESTINATION <%text>${CMAKE_INSTALL_CMAKEDIR}</%text>
+ DESTINATION <%text>${gRPC_INSTALL_CMAKEDIR}</%text>
)
endforeach()