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 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 42if(CURL_USE_PKGCONFIG AND 43 NOT DEFINED LDAP_INCLUDE_DIR AND 44 NOT DEFINED LDAP_LIBRARY AND 45 NOT DEFINED LDAP_LBER_LIBRARY) 46 find_package(PkgConfig QUIET) 47 pkg_check_modules(LDAP "ldap") 48 pkg_check_modules(LDAP_LBER "lber") 49endif() 50 51if(LDAP_FOUND AND LDAP_LBER_FOUND) 52 list(APPEND LDAP_LIBRARIES ${LDAP_LBER_LIBRARIES}) 53 list(REVERSE LDAP_LIBRARIES) 54 list(REMOVE_DUPLICATES LDAP_LIBRARIES) 55 list(REVERSE LDAP_LIBRARIES) 56 set(LDAP_PC_REQUIRES "ldap") 57 string(REPLACE ";" " " LDAP_CFLAGS "${LDAP_CFLAGS}") 58 message(STATUS "Found LDAP (via pkg-config): ${LDAP_INCLUDE_DIRS} (found version \"${LDAP_VERSION}\")") 59else() 60 # On Apple the SDK LDAP gets picked up from 61 # 'MacOSX.sdk/System/Library/Frameworks/LDAP.framework/Headers', which contains 62 # ldap.h and lber.h both being stubs to include <ldap.h> and <lber.h>. 63 # This causes an infinite inclusion loop in compile. 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 set(CMAKE_SYSTEM_FRAMEWORK_PATH ${_save_cmake_system_framework_path}) 68 find_library(LDAP_LIBRARY NAMES "ldap") 69 find_library(LDAP_LBER_LIBRARY NAMES "lber") 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) 107endif() 108