Skip to content

Commit

Permalink
Merge pull request grpc#14353 from jtattermusch/cmake_polishing
Browse files Browse the repository at this point in the history
Fine tune cmake find_package usage
  • Loading branch information
jtattermusch authored Feb 20, 2018
2 parents 84f94c1 + 6750d42 commit 2336c69
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
5 changes: 3 additions & 2 deletions cmake/benchmark.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
1 change: 1 addition & 0 deletions cmake/cares.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions cmake/gflags.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
4 changes: 4 additions & 0 deletions cmake/ssl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 6 additions & 0 deletions cmake/zlib.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 2336c69

Please sign in to comment.