ssl.cmake 3.2 KB

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