blob: 19a7d779b35bf77cfd46221a3f38efd33f0109b1 [file] [log] [blame]
Jan Tattermuschf38b1522017-12-19 14:05:41 -08001# 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")
Jan Tattermusch7132cd72018-08-21 18:01:53 +020020 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()
Jan Tattermuschf38b1522017-12-19 14:05:41 -080028 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")
Jan Tattermusch6750d422018-02-07 15:57:23 +010041 # 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
Jan Tattermuschf38b1522017-12-19 14:05:41 -080045 find_package(OpenSSL REQUIRED)
Stefan Hacker471a5dc2018-01-14 13:38:20 +010046
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()
Jan Tattermuschf38b1522017-12-19 14:05:41 -080052 set(_gRPC_SSL_INCLUDE_DIR ${OPENSSL_INCLUDE_DIR})
Stefan Hacker471a5dc2018-01-14 13:38:20 +010053
Jan Tattermuschf38b1522017-12-19 14:05:41 -080054 set(_gRPC_FIND_SSL "if(NOT OPENSSL_FOUND)\n find_package(OpenSSL)\nendif()")
55endif()