• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1#***************************************************************************
2#                                  _   _ ____  _
3#  Project                     ___| | | |  _ \| |
4#                             / __| | | | |_) | |
5#                            | (__| |_| |  _ <| |___
6#                             \___|\___/|_| \_\_____|
7#
8# Copyright (C) Daniel Stenberg, <daniel@haxx.se>, et al.
9#
10# This software is licensed as described in the file COPYING, which
11# you should have received as part of this distribution. The terms
12# are also available at https://curl.se/docs/copyright.html.
13#
14# You may opt to use, copy, modify, merge, publish, distribute and/or sell
15# copies of the Software, and permit persons to whom the Software is
16# furnished to do so, under the terms of the COPYING file.
17#
18# This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19# KIND, either express or implied.
20#
21# SPDX-License-Identifier: curl
22#
23###########################################################################
24# Find the Rustls library
25#
26# Input variables:
27#
28# - `RUSTLS_INCLUDE_DIR`:   The Rustls include directory.
29# - `RUSTLS_LIBRARY`:       Path to `rustls` library.
30#
31# Result variables:
32#
33# - `RUSTLS_FOUND`:         System has Rustls.
34# - `RUSTLS_INCLUDE_DIRS`:  The Rustls include directories.
35# - `RUSTLS_LIBRARIES`:     The Rustls library names.
36# - `RUSTLS_LIBRARY_DIRS`:  The Rustls library directories.
37# - `RUSTLS_PC_REQUIRES`:   The Rustls pkg-config packages.
38# - `RUSTLS_CFLAGS`:        Required compiler flags.
39# - `RUSTLS_VERSION`:       Version of Rustls.
40
41set(RUSTLS_PC_REQUIRES "rustls")
42
43if(CURL_USE_PKGCONFIG AND
44   NOT DEFINED RUSTLS_INCLUDE_DIR AND
45   NOT DEFINED RUSTLS_LIBRARY)
46  find_package(PkgConfig QUIET)
47  pkg_check_modules(RUSTLS ${RUSTLS_PC_REQUIRES})
48endif()
49
50if(RUSTLS_FOUND)
51  string(REPLACE ";" " " RUSTLS_CFLAGS "${RUSTLS_CFLAGS}")
52  message(STATUS "Found Rustls (via pkg-config): ${RUSTLS_INCLUDE_DIRS} (found version \"${RUSTLS_VERSION}\")")
53else()
54  set(RUSTLS_PC_REQUIRES "")  # Depend on pkg-config only when found via pkg-config
55
56  find_path(RUSTLS_INCLUDE_DIR NAMES "rustls.h")
57  find_library(RUSTLS_LIBRARY NAMES "rustls")
58
59  include(FindPackageHandleStandardArgs)
60  find_package_handle_standard_args(Rustls
61    REQUIRED_VARS
62      RUSTLS_INCLUDE_DIR
63      RUSTLS_LIBRARY
64  )
65
66  if(RUSTLS_FOUND)
67    set(RUSTLS_INCLUDE_DIRS ${RUSTLS_INCLUDE_DIR})
68    set(RUSTLS_LIBRARIES    ${RUSTLS_LIBRARY})
69  endif()
70
71  mark_as_advanced(RUSTLS_INCLUDE_DIR RUSTLS_LIBRARY)
72endif()
73
74if(RUSTLS_FOUND)
75  if(APPLE)
76    find_library(SECURITY_FRAMEWORK NAMES "Security")
77    mark_as_advanced(SECURITY_FRAMEWORK)
78    if(NOT SECURITY_FRAMEWORK)
79      message(FATAL_ERROR "Security framework not found")
80    endif()
81    list(APPEND RUSTLS_LIBRARIES "-framework Security")
82
83    find_library(FOUNDATION_FRAMEWORK NAMES "Foundation")
84    mark_as_advanced(FOUNDATION_FRAMEWORK)
85    if(NOT FOUNDATION_FRAMEWORK)
86      message(FATAL_ERROR "Foundation framework not found")
87    endif()
88    list(APPEND RUSTLS_LIBRARIES "-framework Foundation")
89  elseif(NOT WIN32)
90    find_library(PTHREAD_LIBRARY NAMES "pthread")
91    if(PTHREAD_LIBRARY)
92      list(APPEND RUSTLS_LIBRARIES ${PTHREAD_LIBRARY})
93    endif()
94    mark_as_advanced(PTHREAD_LIBRARY)
95
96    find_library(DL_LIBRARY NAMES "dl")
97    if(DL_LIBRARY)
98      list(APPEND RUSTLS_LIBRARIES ${DL_LIBRARY})
99    endif()
100    mark_as_advanced(DL_LIBRARY)
101
102    find_library(MATH_LIBRARY NAMES "m")
103    if(MATH_LIBRARY)
104      list(APPEND RUSTLS_LIBRARIES ${MATH_LIBRARY})
105    endif()
106    mark_as_advanced(MATH_LIBRARY)
107  endif()
108endif()
109