FindLdap.cmake 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. # https://github.com/KDE/kldap/blob/master/cmake/FindLdap.cmake
  2. # .rst:
  3. # FindLdap
  4. # --------
  5. #
  6. # Try to find the LDAP client libraries.
  7. #
  8. # This will define the following variables:
  9. #
  10. # ``Ldap_FOUND``
  11. # True if libldap is available.
  12. #
  13. # ``Ldap_VERSION``
  14. # The version of libldap
  15. #
  16. # ``Ldap_INCLUDE_DIRS``
  17. # This should be passed to target_include_directories() if
  18. # the target is not used for linking
  19. #
  20. # ``Ldap_LIBRARIES``
  21. # The LDAP libraries (libldap + liblber if available)
  22. # This can be passed to target_link_libraries() instead of
  23. # the ``Ldap::Ldap`` target
  24. #
  25. # If ``Ldap_FOUND`` is TRUE, the following imported target
  26. # will be available:
  27. #
  28. # ``Ldap::Ldap``
  29. # The LDAP library
  30. #
  31. # Since pre-5.0.0.
  32. #
  33. # Imported target since 5.1.41
  34. #
  35. #=============================================================================
  36. # SPDX-FileCopyrightText: 2006 Szombathelyi György <[email protected]>
  37. # SPDX-FileCopyrightText: 2007-2024 Laurent Montel <[email protected]>
  38. #
  39. # SPDX-License-Identifier: BSD-3-Clause
  40. #=============================================================================
  41. find_path(Ldap_INCLUDE_DIRS NAMES ldap.h)
  42. if(APPLE)
  43. find_library(
  44. Ldap_LIBRARIES
  45. NAMES LDAP
  46. PATHS /System/Library/Frameworks /Library/Frameworks
  47. )
  48. else()
  49. find_library(Ldap_LIBRARY NAMES ldap)
  50. find_library(Lber_LIBRARY NAMES lber)
  51. endif()
  52. if(Ldap_LIBRARY AND Lber_LIBRARY)
  53. set(Ldap_LIBRARIES ${Ldap_LIBRARY} ${Lber_LIBRARY})
  54. endif()
  55. if(EXISTS ${Ldap_INCLUDE_DIRS}/ldap_features.h)
  56. file(READ ${Ldap_INCLUDE_DIRS}/ldap_features.h LDAP_FEATURES_H_CONTENT)
  57. string(REGEX MATCH "#define LDAP_VENDOR_VERSION_MAJOR[ ]+[0-9]+" _LDAP_VERSION_MAJOR_MATCH
  58. ${LDAP_FEATURES_H_CONTENT}
  59. )
  60. string(REGEX MATCH "#define LDAP_VENDOR_VERSION_MINOR[ ]+[0-9]+" _LDAP_VERSION_MINOR_MATCH
  61. ${LDAP_FEATURES_H_CONTENT}
  62. )
  63. string(REGEX MATCH "#define LDAP_VENDOR_VERSION_PATCH[ ]+[0-9]+" _LDAP_VERSION_PATCH_MATCH
  64. ${LDAP_FEATURES_H_CONTENT}
  65. )
  66. string(REGEX REPLACE ".*_MAJOR[ ]+(.*)" "\\1" LDAP_VERSION_MAJOR ${_LDAP_VERSION_MAJOR_MATCH})
  67. string(REGEX REPLACE ".*_MINOR[ ]+(.*)" "\\1" LDAP_VERSION_MINOR ${_LDAP_VERSION_MINOR_MATCH})
  68. string(REGEX REPLACE ".*_PATCH[ ]+(.*)" "\\1" LDAP_VERSION_PATCH ${_LDAP_VERSION_PATCH_MATCH})
  69. set(Ldap_VERSION "${LDAP_VERSION_MAJOR}.${LDAP_VERSION_MINOR}.${LDAP_VERSION_PATCH}")
  70. endif()
  71. include(FindPackageHandleStandardArgs)
  72. find_package_handle_standard_args(
  73. Ldap
  74. FOUND_VAR Ldap_FOUND
  75. REQUIRED_VARS Ldap_LIBRARIES Ldap_INCLUDE_DIRS
  76. VERSION_VAR Ldap_VERSION
  77. )
  78. if(Ldap_FOUND AND NOT TARGET Lber::Lber)
  79. add_library(Lber::Lber UNKNOWN IMPORTED)
  80. set_target_properties(Lber::Lber PROPERTIES IMPORTED_LOCATION "${Lber_LIBRARY}")
  81. endif()
  82. if(Ldap_FOUND AND NOT TARGET Ldap::Ldap)
  83. add_library(Ldap::Ldap UNKNOWN IMPORTED)
  84. set_target_properties(
  85. Ldap::Ldap
  86. PROPERTIES IMPORTED_LOCATION "${Ldap_LIBRARY}"
  87. INTERFACE_INCLUDE_DIRECTORIES "${Ldap_INCLUDE_DIRS}"
  88. INTERFACE_LINK_LIBRARIES Lber::Lber
  89. )
  90. endif()
  91. mark_as_advanced(Ldap_INCLUDE_DIRS Ldap_LIBRARY Lber_LIBRARY Ldap_LIBRARIES)
  92. include(FeatureSummary)
  93. set_package_properties(
  94. Ldap PROPERTIES
  95. URL "https://www.openldap.org/"
  96. DESCRIPTION "LDAP (Lightweight Directory Access Protocol) libraries."
  97. )