xref: /curl/CMake/FindLibgsasl.cmake (revision 7c0b6eb3)
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 libgsasl library
25#
26# Input variables:
27#
28# LIBGSASL_INCLUDE_DIR   The libgsasl include directory
29# LIBGSASL_LIBRARY       Path to libgsasl library
30#
31# Result variables:
32#
33# LIBGSASL_FOUND         System has libgsasl
34# LIBGSASL_INCLUDE_DIRS  The libgsasl include directories
35# LIBGSASL_LIBRARIES     The libgsasl library names
36# LIBGSASL_LIBRARY_DIRS  The libgsasl library directories
37# LIBGSASL_CFLAGS        Required compiler flags
38# LIBGSASL_VERSION       Version of libgsasl
39
40if(CURL_USE_PKGCONFIG AND
41   NOT DEFINED LIBGSASL_INCLUDE_DIR AND
42   NOT DEFINED LIBGSASL_LIBRARY)
43  find_package(PkgConfig QUIET)
44  pkg_check_modules(LIBGSASL "libgsasl")
45endif()
46
47if(LIBGSASL_FOUND)
48  string(REPLACE ";" " " LIBGSASL_CFLAGS "${LIBGSASL_CFLAGS}")
49  message(STATUS "Found Libgsasl (via pkg-config): ${LIBGSASL_INCLUDE_DIRS} (found version \"${LIBGSASL_VERSION}\")")
50else()
51  find_path(LIBGSASL_INCLUDE_DIR NAMES "gsasl.h")
52  find_library(LIBGSASL_LIBRARY NAMES "gsasl" "libgsasl")
53
54  if(LIBGSASL_INCLUDE_DIR AND EXISTS "${LIBGSASL_INCLUDE_DIR}/gsasl-version.h")
55    set(_version_regex "#[\t ]*define[\t ]+GSASL_VERSION[\t ]+\"([^\"]*)\"")
56    file(STRINGS "${LIBGSASL_INCLUDE_DIR}/gsasl-version.h" _version_str REGEX "${_version_regex}")
57    string(REGEX REPLACE "${_version_regex}" "\\1" _version_str "${_version_str}")
58    set(LIBGSASL_VERSION "${_version_str}")
59    unset(_version_regex)
60    unset(_version_str)
61  endif()
62
63  include(FindPackageHandleStandardArgs)
64    find_package_handle_standard_args(Libgsasl
65    REQUIRED_VARS
66      LIBGSASL_INCLUDE_DIR
67      LIBGSASL_LIBRARY
68    VERSION_VAR
69      LIBGSASL_VERSION
70  )
71
72  if(LIBGSASL_FOUND)
73    set(LIBGSASL_INCLUDE_DIRS ${LIBGSASL_INCLUDE_DIR})
74    set(LIBGSASL_LIBRARIES    ${LIBGSASL_LIBRARY})
75  endif()
76
77  mark_as_advanced(LIBGSASL_INCLUDE_DIR LIBGSASL_LIBRARY)
78endif()
79