Debian Codegraph @

extra/curl/curl-8.14.1/CMake/FindLDAP.cmake

raw
1 #***************************************************************************
2 # _ _ ____ _
3 # Project ___| | | | _ \| |
4 # / __| | | | |_) | |
5 # | (__| |_| | _ <| |___
6 # \___|\___/|_| \_\_____|
7 #
8 # Copyright (C) Daniel Stenberg, <[email protected]>, 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 ldap library
25 #
26 # Input variables:
27 #
28 # - `LDAP_INCLUDE_DIR`: The ldap include directory.
29 # - `LDAP_LIBRARY`: Path to `ldap` library.
30 # - `LDAP_LBER_LIBRARY`: Path to `lber` library.
31 #
32 # Result variables:
33 #
34 # - `LDAP_FOUND`: System has ldap.
35 # - `LDAP_INCLUDE_DIRS`: The ldap include directories.
36 # - `LDAP_LIBRARIES`: The ldap library names.
37 # - `LDAP_LIBRARY_DIRS`: The ldap library directories.
38 # - `LDAP_PC_REQUIRES`: The ldap pkg-config packages.
39 # - `LDAP_CFLAGS`: Required compiler flags.
40 # - `LDAP_VERSION`: Version of ldap.
41
42 set(LDAP_PC_REQUIRES "ldap" "lber")
43
44 if(CURL_USE_PKGCONFIG AND
45 NOT DEFINED LDAP_INCLUDE_DIR AND
46 NOT DEFINED LDAP_LIBRARY AND
47 NOT DEFINED LDAP_LBER_LIBRARY)
48 find_package(PkgConfig QUIET)
49 pkg_check_modules(LDAP ${LDAP_PC_REQUIRES})
50 endif()
51
52 if(LDAP_FOUND)
53 set(LDAP_VERSION "${LDAP_ldap_VERSION}")
54 string(REPLACE ";" " " LDAP_CFLAGS "${LDAP_CFLAGS}")
55 message(STATUS "Found LDAP (via pkg-config): ${LDAP_INCLUDE_DIRS} (found version \"${LDAP_VERSION}\")")
56 else()
57 set(LDAP_PC_REQUIRES "") # Depend on pkg-config only when found via pkg-config
58
59 # On Apple the SDK LDAP gets picked up from
60 # 'MacOSX.sdk/System/Library/Frameworks/LDAP.framework/Headers', which contains
61 # ldap.h and lber.h both being stubs to include <ldap.h> and <lber.h>.
62 # This causes an infinite inclusion loop in compile. Also do this for libraries
63 # to avoid picking up the 'ldap.framework' with a full path.
64 set(_save_cmake_system_framework_path ${CMAKE_SYSTEM_FRAMEWORK_PATH})
65 set(CMAKE_SYSTEM_FRAMEWORK_PATH "")
66 find_path(LDAP_INCLUDE_DIR NAMES "ldap.h")
67 find_library(LDAP_LIBRARY NAMES "ldap")
68 find_library(LDAP_LBER_LIBRARY NAMES "lber")
69 set(CMAKE_SYSTEM_FRAMEWORK_PATH ${_save_cmake_system_framework_path})
70
71 unset(LDAP_VERSION CACHE)
72 if(LDAP_INCLUDE_DIR AND EXISTS "${LDAP_INCLUDE_DIR}/ldap_features.h")
73 set(_version_regex1 "#[\t ]*define[\t ]+LDAP_VENDOR_VERSION_MAJOR[\t ]+([0-9]+).*")
74 set(_version_regex2 "#[\t ]*define[\t ]+LDAP_VENDOR_VERSION_MINOR[\t ]+([0-9]+).*")
75 set(_version_regex3 "#[\t ]*define[\t ]+LDAP_VENDOR_VERSION_PATCH[\t ]+([0-9]+).*")
76 file(STRINGS "${LDAP_INCLUDE_DIR}/ldap_features.h" _version_str1 REGEX "${_version_regex1}")
77 file(STRINGS "${LDAP_INCLUDE_DIR}/ldap_features.h" _version_str2 REGEX "${_version_regex2}")
78 file(STRINGS "${LDAP_INCLUDE_DIR}/ldap_features.h" _version_str3 REGEX "${_version_regex3}")
79 string(REGEX REPLACE "${_version_regex1}" "\\1" _version_str1 "${_version_str1}")
80 string(REGEX REPLACE "${_version_regex2}" "\\1" _version_str2 "${_version_str2}")
81 string(REGEX REPLACE "${_version_regex3}" "\\1" _version_str3 "${_version_str3}")
82 set(LDAP_VERSION "${_version_str1}.${_version_str2}.${_version_str3}")
83 unset(_version_regex1)
84 unset(_version_regex2)
85 unset(_version_regex3)
86 unset(_version_str1)
87 unset(_version_str2)
88 unset(_version_str3)
89 endif()
90
91 include(FindPackageHandleStandardArgs)
92 find_package_handle_standard_args(LDAP
93 REQUIRED_VARS
94 LDAP_INCLUDE_DIR
95 LDAP_LIBRARY
96 LDAP_LBER_LIBRARY
97 VERSION_VAR
98 LDAP_VERSION
99 )
100
101 if(LDAP_FOUND)
102 set(LDAP_INCLUDE_DIRS ${LDAP_INCLUDE_DIR})
103 set(LDAP_LIBRARIES ${LDAP_LIBRARY} ${LDAP_LBER_LIBRARY})
104 endif()
105
106 mark_as_advanced(LDAP_INCLUDE_DIR LDAP_LIBRARY LDAP_LBER_LIBRARY)
107 endif()