diff --git a/CMakeLists.txt b/CMakeLists.txt index 32add78b99b..5f8232804f7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -55,7 +55,15 @@ if(NOT CMAKE_SOURCE_DIR STREQUAL CMAKE_CURRENT_SOURCE_DIR) set(gRPC_INSTALL_default OFF) endif() set(gRPC_INSTALL ${gRPC_INSTALL_default} CACHE BOOL - "Generate installation target: gRPC_ZLIB_PROVIDER, gRPC_CARES_PROVIDER, gRPC_SSL_PROVIDER and gRPC_PROTOBUF_PROVIDER must all be \"package\"") + "Generate installation target") + +# We can install dependencies from submodules if we're running +# CMake v3.13 or newer. +if(CMAKE_VERSION VERSION_LESS 3.13) + set(_gRPC_INSTALL_SUPPORTED_FROM_MODULE OFF) +else() + set(_gRPC_INSTALL_SUPPORTED_FROM_MODULE ON) +endif() # Providers for third-party dependencies (gRPC_*_PROVIDER properties): # "module": build the dependency using sources from git submodule (under third_party) diff --git a/cmake/cares.cmake b/cmake/cares.cmake index cf7d74cc0fc..05bb5441f03 100644 --- a/cmake/cares.cmake +++ b/cmake/cares.cmake @@ -26,10 +26,16 @@ if(gRPC_CARES_PROVIDER STREQUAL "module") if(TARGET c-ares) set(_gRPC_CARES_LIBRARIES c-ares) + if(gRPC_INSTALL AND _gRPC_INSTALL_SUPPORTED_FROM_MODULE) + install(TARGETS c-ares EXPORT gRPCTargets + RUNTIME DESTINATION ${gRPC_INSTALL_BINDIR} + LIBRARY DESTINATION ${gRPC_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${gRPC_INSTALL_LIBDIR}) + endif() endif() - if(gRPC_INSTALL) - message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_CARES_PROVIDER is \"module\"") + if(gRPC_INSTALL AND NOT _gRPC_INSTALL_SUPPORTED_FROM_MODULE) + message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_CARES_PROVIDER is \"module\" and CMake version (${CMAKE_VERSION}) is less than 3.13.") set(gRPC_INSTALL FALSE) endif() elseif(gRPC_CARES_PROVIDER STREQUAL "package") diff --git a/cmake/protobuf.cmake b/cmake/protobuf.cmake index df88fddba8c..a37e0d5cbdf 100644 --- a/cmake/protobuf.cmake +++ b/cmake/protobuf.cmake @@ -46,8 +46,8 @@ if(gRPC_PROTOBUF_PROVIDER STREQUAL "module") 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\"") + if(gRPC_INSTALL AND NOT _gRPC_INSTALL_SUPPORTED_FROM_MODULE) + message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_PROTOBUF_PROVIDER is \"module\" and CMake version (${CMAKE_VERSION}) is less than 3.13.") set(gRPC_INSTALL FALSE) endif() elseif(gRPC_PROTOBUF_PROVIDER STREQUAL "package") diff --git a/cmake/ssl.cmake b/cmake/ssl.cmake index 2c6a0adcd50..1389be32b64 100644 --- a/cmake/ssl.cmake +++ b/cmake/ssl.cmake @@ -33,12 +33,18 @@ if(gRPC_SSL_PROVIDER STREQUAL "module") if(TARGET ssl) set(_gRPC_SSL_LIBRARIES ssl) set(_gRPC_SSL_INCLUDE_DIR ${BORINGSSL_ROOT_DIR}/include) + if(gRPC_INSTALL AND _gRPC_INSTALL_SUPPORTED_FROM_MODULE) + install(TARGETS ssl crypto EXPORT gRPCTargets + RUNTIME DESTINATION ${gRPC_INSTALL_BINDIR} + LIBRARY DESTINATION ${gRPC_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${gRPC_INSTALL_LIBDIR}) + endif() endif() 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\"") + if(gRPC_INSTALL AND NOT _gRPC_INSTALL_SUPPORTED_FROM_MODULE) + message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_SSL_PROVIDER is \"module\" and CMake version (${CMAKE_VERSION}) is less than 3.13.") set(gRPC_INSTALL FALSE) endif() elseif(gRPC_SSL_PROVIDER STREQUAL "package") diff --git a/cmake/zlib.cmake b/cmake/zlib.cmake index 858d3b42fee..9d658921d33 100644 --- a/cmake/zlib.cmake +++ b/cmake/zlib.cmake @@ -28,12 +28,18 @@ if(gRPC_ZLIB_PROVIDER STREQUAL "module") if(TARGET zlibstatic) set(_gRPC_ZLIB_LIBRARIES zlibstatic) set(_gRPC_ZLIB_INCLUDE_DIR "${ZLIB_ROOT_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib") + if(gRPC_INSTALL AND _gRPC_INSTALL_SUPPORTED_FROM_MODULE) + install(TARGETS zlibstatic EXPORT gRPCTargets + RUNTIME DESTINATION ${gRPC_INSTALL_BINDIR} + LIBRARY DESTINATION ${gRPC_INSTALL_LIBDIR} + ARCHIVE DESTINATION ${gRPC_INSTALL_LIBDIR}) + endif() endif() 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\"") + if(gRPC_INSTALL AND NOT _gRPC_INSTALL_SUPPORTED_FROM_MODULE) + message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_ZLIB_PROVIDER is \"module\" and CMake version (${CMAKE_VERSION}) is less than 3.13.") set(gRPC_INSTALL FALSE) endif() elseif(gRPC_ZLIB_PROVIDER STREQUAL "package") diff --git a/templates/CMakeLists.txt.template b/templates/CMakeLists.txt.template index 4ef88f1dfba..a64102e062e 100644 --- a/templates/CMakeLists.txt.template +++ b/templates/CMakeLists.txt.template @@ -149,7 +149,15 @@ set(gRPC_INSTALL_default OFF) endif() set(gRPC_INSTALL <%text>${gRPC_INSTALL_default} CACHE BOOL - "Generate installation target: gRPC_ZLIB_PROVIDER, gRPC_CARES_PROVIDER, gRPC_SSL_PROVIDER and gRPC_PROTOBUF_PROVIDER must all be \"package\"") + "Generate installation target") + + # We can install dependencies from submodules if we're running + # CMake v3.13 or newer. + if(CMAKE_VERSION VERSION_LESS 3.13) + set(_gRPC_INSTALL_SUPPORTED_FROM_MODULE OFF) + else() + set(_gRPC_INSTALL_SUPPORTED_FROM_MODULE ON) + endif() # Providers for third-party dependencies (gRPC_*_PROVIDER properties): # "module": build the dependency using sources from git submodule (under third_party)