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# The CMakeLists.txt for BoringSSL doesn't propagate include directories 16# transitively so `_gRPC_SSL_INCLUDE_DIR` should be set for gRPC 17# to find header files. 18 19if(gRPC_SSL_PROVIDER STREQUAL "module") 20 if(NOT BORINGSSL_ROOT_DIR) 21 set(BORINGSSL_ROOT_DIR ${CMAKE_CURRENT_SOURCE_DIR}/third_party/boringssl-with-bazel) 22 endif() 23 24 if(EXISTS "${BORINGSSL_ROOT_DIR}/CMakeLists.txt") 25 if(CMAKE_GENERATOR MATCHES "Visual Studio") 26 if(CMAKE_VERSION VERSION_LESS 3.13) 27 # Visual Studio build with assembly optimizations is broken for older 28 # version of CMake (< 3.13). 29 message(WARNING "Disabling SSL assembly support because CMake version ${CMAKE_VERSION} is too old (less than 3.13)") 30 set(OPENSSL_NO_ASM ON) 31 else() 32 # If we're using a new enough version of CMake, make sure that the 33 # NASM assembler can be found. 34 include(CheckLanguage) 35 check_language(ASM_NASM) 36 if(NOT CMAKE_ASM_NASM_COMPILER) 37 message(WARNING "Disabling SSL assembly support because NASM could not be found") 38 set(OPENSSL_NO_ASM ON) 39 endif() 40 endif() 41 endif() 42 43 add_subdirectory(${BORINGSSL_ROOT_DIR} third_party/boringssl-with-bazel) 44 if(TARGET ssl) 45 set(_gRPC_SSL_LIBRARIES ssl crypto) 46 set(_gRPC_SSL_INCLUDE_DIR ${BORINGSSL_ROOT_DIR}/src/include) 47 if(gRPC_INSTALL AND _gRPC_INSTALL_SUPPORTED_FROM_MODULE) 48 install(TARGETS ssl crypto EXPORT gRPCTargets 49 RUNTIME DESTINATION ${gRPC_INSTALL_BINDIR} 50 LIBRARY DESTINATION ${gRPC_INSTALL_LIBDIR} 51 ARCHIVE DESTINATION ${gRPC_INSTALL_LIBDIR}) 52 endif() 53 endif() 54 else() 55 message(WARNING "gRPC_SSL_PROVIDER is \"module\" but BORINGSSL_ROOT_DIR is wrong") 56 endif() 57 if(gRPC_INSTALL AND NOT _gRPC_INSTALL_SUPPORTED_FROM_MODULE) 58 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.") 59 set(gRPC_INSTALL FALSE) 60 endif() 61elseif(gRPC_SSL_PROVIDER STREQUAL "package") 62 # OpenSSL installation directory can be configured by setting OPENSSL_ROOT_DIR 63 # We expect to locate OpenSSL using the built-in cmake module as the openssl 64 # project itself does not provide installation support in its CMakeLists.txt 65 # See https://cmake.org/cmake/help/v3.6/module/FindOpenSSL.html 66 find_package(OpenSSL REQUIRED) 67 68 if(TARGET OpenSSL::SSL) 69 set(_gRPC_SSL_LIBRARIES OpenSSL::SSL OpenSSL::Crypto) 70 else() 71 set(_gRPC_SSL_LIBRARIES ${OPENSSL_LIBRARIES}) 72 endif() 73 set(_gRPC_SSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR}) 74 75 set(_gRPC_FIND_SSL "if(NOT OPENSSL_FOUND)\n find_package(OpenSSL)\nendif()") 76endif() 77