5 # Try to find the LDAP client libraries.
7 # This will define the following variables:
10 # True if libldap is available.
13 # The version of libldap
15 # ``Ldap_INCLUDE_DIRS``
16 # This should be passed to target_include_directories() if
17 # the target is not used for linking
20 # The LDAP libraries (libldap + liblber if available)
21 # This can be passed to target_link_libraries() instead of
22 # the ``Ldap::Ldap`` target
24 # If ``Ldap_FOUND`` is TRUE, the following imported target
30 #=============================================================================
31 # Copyright 2006 Szombathelyi György <gyurco@freemail.hu>
32 # Copyright 2007-2016 Laurent Montel <montel@kde.org>
34 # Redistribution and use in source and binary forms, with or without
35 # modification, are permitted provided that the following conditions
38 # 1. Redistributions of source code must retain the copyright
39 # notice, this list of conditions and the following disclaimer.
40 # 2. Redistributions in binary form must reproduce the copyright
41 # notice, this list of conditions and the following disclaimer in the
42 # documentation and/or other materials provided with the distribution.
43 # 3. The name of the author may not be used to endorse or promote products
44 # derived from this software without specific prior written permission.
46 # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
47 # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
48 # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
49 # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
50 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
51 # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
52 # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
53 # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
54 # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
55 # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
56 #=============================================================================
59 find_path(Ldap_INCLUDE_DIRS NAMES ldap.h)
60 find_library(Ldap_LIBRARY NAMES ldap)
61 find_library(Lber_LIBRARY NAMES lber)
63 # OSX ships with an LDAP.framework which seems to be completely broken.
64 # Force using the working version in /usr instead.
65 find_path(Ldap_INCLUDE_DIRS NAMES ldap.h PATHS /usr/include NO_CMAKE_SYSTEM_PATH)
66 find_library(Ldap_LIBRARY NAMES ldap PATHS /usr/lib NO_CMAKE_SYSTEM_PATH)
67 find_library(Lber_LIBRARY NAMES lber PATHS /usr/lib NO_CMAKE_SYSTEM_PATH)
70 set(Ldap_LIBRARIES ${Ldap_LIBRARY})
71 if (Ldap_LIBRARY AND Lber_LIBRARY)
72 list(APPEND Ldap_LIBRARIES ${Lber_LIBRARY})
75 if(EXISTS ${Ldap_INCLUDE_DIRS}/ldap_features.h)
76 file(READ ${Ldap_INCLUDE_DIRS}/ldap_features.h LDAP_FEATURES_H_CONTENT)
77 string(REGEX MATCH "#define LDAP_VENDOR_VERSION_MAJOR[ ]+[0-9]+" _LDAP_VERSION_MAJOR_MATCH ${LDAP_FEATURES_H_CONTENT})
78 string(REGEX MATCH "#define LDAP_VENDOR_VERSION_MINOR[ ]+[0-9]+" _LDAP_VERSION_MINOR_MATCH ${LDAP_FEATURES_H_CONTENT})
79 string(REGEX MATCH "#define LDAP_VENDOR_VERSION_PATCH[ ]+[0-9]+" _LDAP_VERSION_PATCH_MATCH ${LDAP_FEATURES_H_CONTENT})
81 string(REGEX REPLACE ".*_MAJOR[ ]+(.*)" "\\1" LDAP_VERSION_MAJOR ${_LDAP_VERSION_MAJOR_MATCH})
82 string(REGEX REPLACE ".*_MINOR[ ]+(.*)" "\\1" LDAP_VERSION_MINOR ${_LDAP_VERSION_MINOR_MATCH})
83 string(REGEX REPLACE ".*_PATCH[ ]+(.*)" "\\1" LDAP_VERSION_PATCH ${_LDAP_VERSION_PATCH_MATCH})
85 set(Ldap_VERSION "${LDAP_VERSION_MAJOR}.${LDAP_VERSION_MINOR}.${LDAP_VERSION_PATCH}")
88 include(FindPackageHandleStandardArgs)
89 find_package_handle_standard_args(Ldap
91 REQUIRED_VARS Ldap_LIBRARIES Ldap_INCLUDE_DIRS
92 VERSION_VAR Ldap_VERSION
95 if (Ldap_FOUND AND NOT TARGET Ldap::Ldap)
96 add_library(Ldap::Ldap UNKNOWN IMPORTED)
97 set_target_properties(Ldap::Ldap PROPERTIES
98 IMPORTED_LOCATION "${Ldap_LIBRARY}"
99 INTERFACE_LINK_LIBRARIES "${Lber_LIBRARY}"
100 INTERFACE_INCLUDE_DIRECTORIES "${Ldap_INCLUDE_DIRS}"
104 mark_as_advanced(Ldap_INCLUDE_DIRS Ldap_LIBRARY Lber_LIBRARY Ldap_LIBRARIES Ldap_VERSION)