• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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
15if("${gRPC_SSL_PROVIDER}" STREQUAL "module")
16  if(NOT BORINGSSL_ROOT_DIR)
17    set(BORINGSSL_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/boringssl)
18  endif()
19  if(EXISTS "${BORINGSSL_ROOT_DIR}/CMakeLists.txt")
20    if (MSVC AND NOT CMAKE_GENERATOR STREQUAL "Ninja")
21      # Visual Studio build with assembly optimizations is broken,
22      # but it works with Ninja generator.
23      # This will get eventually fixed in cmake, but until then
24      # we need to disable assembly optimizations.
25      # See https://github.com/grpc/grpc/issues/16376
26      set(OPENSSL_NO_ASM ON)
27    endif()
28    add_subdirectory(${BORINGSSL_ROOT_DIR} third_party/boringssl)
29    if(TARGET ssl)
30      set(_gRPC_SSL_LIBRARIES ssl)
31      set(_gRPC_SSL_INCLUDE_DIR ${BORINGSSL_ROOT_DIR}/include)
32    endif()
33  else()
34      message(WARNING "gRPC_SSL_PROVIDER is \"module\" but BORINGSSL_ROOT_DIR is wrong")
35  endif()
36  if(gRPC_INSTALL)
37    message(WARNING "gRPC_INSTALL will be forced to FALSE because gRPC_SSL_PROVIDER is \"module\"")
38    set(gRPC_INSTALL FALSE)
39  endif()
40elseif("${gRPC_SSL_PROVIDER}" STREQUAL "package")
41  # OpenSSL installation directory can be configured by setting OPENSSL_ROOT_DIR
42  # We expect to locate OpenSSL using the built-in cmake module as the openssl
43  # project itself does not provide installation support in its CMakeLists.txt
44  # See https://cmake.org/cmake/help/v3.6/module/FindOpenSSL.html
45  find_package(OpenSSL REQUIRED)
46
47  if(TARGET OpenSSL::SSL)
48    set(_gRPC_SSL_LIBRARIES OpenSSL::SSL OpenSSL::Crypto)
49  else()
50    set(_gRPC_SSL_LIBRARIES ${OPENSSL_LIBRARIES})
51  endif()
52  set(_gRPC_SSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR})
53
54  set(_gRPC_FIND_SSL "if(NOT OPENSSL_FOUND)\n  find_package(OpenSSL)\nendif()")
55endif()
56