Jan Tattermusch | f38b152 | 2017-12-19 14:05:41 -0800 | [diff] [blame] | 1 | # Copyright 2017 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 | if("${gRPC_ZLIB_PROVIDER}" STREQUAL "module") |
| 16 | if(NOT ZLIB_ROOT_DIR) |
| 17 | set(ZLIB_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/zlib) |
| 18 | endif() |
Jan Tattermusch | f38b152 | 2017-12-19 14:05:41 -0800 | [diff] [blame] | 19 | if(EXISTS "${ZLIB_ROOT_DIR}/CMakeLists.txt") |
Jan Tattermusch | 586f719 | 2018-01-16 17:57:17 +0100 | [diff] [blame] | 20 | # TODO(jtattermusch): workaround for https://github.com/madler/zlib/issues/218 |
| 21 | include_directories("${ZLIB_ROOT_DIR}") |
| 22 | add_subdirectory(${ZLIB_ROOT_DIR} third_party/zlib) |
Jan Tattermusch | f38b152 | 2017-12-19 14:05:41 -0800 | [diff] [blame] | 23 | |
Jan Tattermusch | 586f719 | 2018-01-16 17:57:17 +0100 | [diff] [blame] | 24 | if(TARGET zlibstatic) |
| 25 | set(_gRPC_ZLIB_LIBRARIES zlibstatic) |
| 26 | set(_gRPC_ZLIB_INCLUDE_DIR "${ZLIB_ROOT_DIR}" "${CMAKE_CURRENT_BINARY_DIR}/third_party/zlib") |
| 27 | endif() |
Jan Tattermusch | f38b152 | 2017-12-19 14:05:41 -0800 | [diff] [blame] | 28 | else() |
| 29 | message(WARNING "gRPC_ZLIB_PROVIDER is \"module\" but ZLIB_ROOT_DIR is wrong") |
| 30 | endif() |
| 31 | if(gRPC_INSTALL) |
| 32 | message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_ZLIB_PROVIDER is \"module\"") |
| 33 | set(gRPC_INSTALL FALSE) |
| 34 | endif() |
| 35 | elseif("${gRPC_ZLIB_PROVIDER}" STREQUAL "package") |
Jan Tattermusch | 6750d42 | 2018-02-07 15:57:23 +0100 | [diff] [blame] | 36 | # zlib installation directory can be configured by setting ZLIB_ROOT |
| 37 | # We allow locating zlib using both "CONFIG" and "MODULE" as the expectation |
| 38 | # is that many Linux systems will have zlib installed via a distribution |
| 39 | # package ("MODULE"), while on Windows the user is likely to have installed |
| 40 | # zlib using cmake ("CONFIG"). |
| 41 | # See https://cmake.org/cmake/help/v3.6/module/FindZLIB.html |
Jan Tattermusch | f38b152 | 2017-12-19 14:05:41 -0800 | [diff] [blame] | 42 | find_package(ZLIB REQUIRED) |
Jan Tattermusch | 461cf30 | 2018-01-19 08:17:29 +0100 | [diff] [blame] | 43 | |
Stefan Hacker | 471a5dc | 2018-01-14 13:38:20 +0100 | [diff] [blame] | 44 | if(TARGET ZLIB::ZLIB) |
| 45 | set(_gRPC_ZLIB_LIBRARIES ZLIB::ZLIB) |
| 46 | else() |
| 47 | set(_gRPC_ZLIB_LIBRARIES ${ZLIB_LIBRARIES}) |
| 48 | endif() |
Jan Tattermusch | 586f719 | 2018-01-16 17:57:17 +0100 | [diff] [blame] | 49 | set(_gRPC_ZLIB_INCLUDE_DIR ${ZLIB_INCLUDE_DIRS}) |
Jan Tattermusch | f38b152 | 2017-12-19 14:05:41 -0800 | [diff] [blame] | 50 | set(_gRPC_FIND_ZLIB "if(NOT ZLIB_FOUND)\n find_package(ZLIB)\nendif()") |
| 51 | endif() |