From 6750d42ef1811cb5527f7eaa13fdbbd0cde4b8ef Mon Sep 17 00:00:00 2001 From: Jan Tattermusch Date: Wed, 7 Feb 2018 15:57:23 +0100 Subject: fine tune cmake find_package usage --- cmake/benchmark.cmake | 5 +++-- cmake/cares.cmake | 1 + cmake/gflags.cmake | 5 +++-- cmake/ssl.cmake | 4 ++++ cmake/zlib.cmake | 6 ++++++ 5 files changed, 17 insertions(+), 4 deletions(-) (limited to 'cmake') diff --git a/cmake/benchmark.cmake b/cmake/benchmark.cmake index 753dc0696f..2b4c20f2db 100644 --- a/cmake/benchmark.cmake +++ b/cmake/benchmark.cmake @@ -26,11 +26,12 @@ if("${gRPC_BENCHMARK_PROVIDER}" STREQUAL "module") message(WARNING "gRPC_BENCHMARK_PROVIDER is \"module\" but BENCHMARK_ROOT_DIR is wrong") endif() elseif("${gRPC_BENCHMARK_PROVIDER}" STREQUAL "package") - find_package(benchmark REQUIRED) + # Use "CONFIG" as there is no built-in cmake module for benchmark. + find_package(benchmark REQUIRED CONFIG) if(TARGET benchmark::benchmark) set(_gRPC_BENCHMARK_LIBRARIES benchmark::benchmark) # extract the include dir from target's properties get_target_property(_gRPC_BENCHMARK_INCLUDE_DIR benchmark::benchmark INTERFACE_INCLUDE_DIRECTORIES) endif() - set(_gRPC_FIND_BENCHMARK "if(NOT benchmark_FOUND)\n find_package(benchmark)\nendif()") + set(_gRPC_FIND_BENCHMARK "if(NOT benchmark_FOUND)\n find_package(benchmark CONFIG)\nendif()") endif() diff --git a/cmake/cares.cmake b/cmake/cares.cmake index 53d7582f6f..3d4a0cae76 100644 --- a/cmake/cares.cmake +++ b/cmake/cares.cmake @@ -30,6 +30,7 @@ if("${gRPC_CARES_PROVIDER}" STREQUAL "module") set(gRPC_INSTALL FALSE) endif() elseif("${gRPC_CARES_PROVIDER}" STREQUAL "package") + # Use "CONFIG" as there is no built-in cmake module for c-ares. find_package(c-ares REQUIRED CONFIG) if(TARGET c-ares::cares) set(_gRPC_CARES_LIBRARIES c-ares::cares) diff --git a/cmake/gflags.cmake b/cmake/gflags.cmake index f86a141c1d..01e0a75b60 100644 --- a/cmake/gflags.cmake +++ b/cmake/gflags.cmake @@ -26,10 +26,11 @@ if("${gRPC_GFLAGS_PROVIDER}" STREQUAL "module") message(WARNING "gRPC_GFLAGS_PROVIDER is \"module\" but GFLAGS_ROOT_DIR is wrong") endif() elseif("${gRPC_GFLAGS_PROVIDER}" STREQUAL "package") - find_package(gflags REQUIRED) + # Use "CONFIG" as there is no built-in cmake module for gflags. + find_package(gflags REQUIRED CONFIG) if(TARGET gflags::gflags) set(_gRPC_GFLAGS_LIBRARIES gflags::gflags) set(_gRPC_GFLAGS_INCLUDE_DIR ${GFLAGS_INCLUDE_DIR}) endif() - set(_gRPC_FIND_GFLAGS "if(NOT gflags_FOUND)\n find_package(gflags)\nendif()") + set(_gRPC_FIND_GFLAGS "if(NOT gflags_FOUND)\n find_package(gflags CONFIG)\nendif()") endif() diff --git a/cmake/ssl.cmake b/cmake/ssl.cmake index 53d8a1597e..83f642a675 100644 --- a/cmake/ssl.cmake +++ b/cmake/ssl.cmake @@ -31,6 +31,10 @@ if("${gRPC_SSL_PROVIDER}" STREQUAL "module") set(gRPC_INSTALL FALSE) endif() elseif("${gRPC_SSL_PROVIDER}" STREQUAL "package") + # OpenSSL installation directory can be configured by setting OPENSSL_ROOT_DIR + # We expect to locate OpenSSL using the built-in cmake module as the openssl + # project itself does not provide installation support in its CMakeLists.txt + # See https://cmake.org/cmake/help/v3.6/module/FindOpenSSL.html find_package(OpenSSL REQUIRED) if(TARGET OpenSSL::SSL) diff --git a/cmake/zlib.cmake b/cmake/zlib.cmake index e4c94f5213..ed7c9c216a 100644 --- a/cmake/zlib.cmake +++ b/cmake/zlib.cmake @@ -33,6 +33,12 @@ if("${gRPC_ZLIB_PROVIDER}" STREQUAL "module") set(gRPC_INSTALL FALSE) endif() elseif("${gRPC_ZLIB_PROVIDER}" STREQUAL "package") + # zlib installation directory can be configured by setting ZLIB_ROOT + # We allow locating zlib using both "CONFIG" and "MODULE" as the expectation + # is that many Linux systems will have zlib installed via a distribution + # package ("MODULE"), while on Windows the user is likely to have installed + # zlib using cmake ("CONFIG"). + # See https://cmake.org/cmake/help/v3.6/module/FindZLIB.html find_package(ZLIB REQUIRED) if(TARGET ZLIB::ZLIB) -- cgit v1.2.3