FindLdap.cmake 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  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]+"
  58. _LDAP_VERSION_MAJOR_MATCH ${LDAP_FEATURES_H_CONTENT}
  59. )
  60. string(REGEX MATCH "#define LDAP_VENDOR_VERSION_MINOR[ ]+[0-9]+"
  61. _LDAP_VERSION_MINOR_MATCH ${LDAP_FEATURES_H_CONTENT}
  62. )
  63. string(REGEX MATCH "#define LDAP_VENDOR_VERSION_PATCH[ ]+[0-9]+"
  64. _LDAP_VERSION_PATCH_MATCH ${LDAP_FEATURES_H_CONTENT}
  65. )
  66. string(REGEX REPLACE ".*_MAJOR[ ]+(.*)" "\\1" LDAP_VERSION_MAJOR
  67. ${_LDAP_VERSION_MAJOR_MATCH}
  68. )
  69. string(REGEX REPLACE ".*_MINOR[ ]+(.*)" "\\1" LDAP_VERSION_MINOR
  70. ${_LDAP_VERSION_MINOR_MATCH}
  71. )
  72. string(REGEX REPLACE ".*_PATCH[ ]+(.*)" "\\1" LDAP_VERSION_PATCH
  73. ${_LDAP_VERSION_PATCH_MATCH}
  74. )
  75. set(Ldap_VERSION
  76. "${LDAP_VERSION_MAJOR}.${LDAP_VERSION_MINOR}.${LDAP_VERSION_PATCH}"
  77. )
  78. endif()
  79. include(FindPackageHandleStandardArgs)
  80. find_package_handle_standard_args(
  81. Ldap
  82. FOUND_VAR Ldap_FOUND
  83. REQUIRED_VARS Ldap_LIBRARIES Ldap_INCLUDE_DIRS
  84. VERSION_VAR Ldap_VERSION
  85. )
  86. if(Ldap_FOUND AND NOT TARGET Lber::Lber)
  87. add_library(Lber::Lber UNKNOWN IMPORTED)
  88. set_target_properties(
  89. Lber::Lber PROPERTIES IMPORTED_LOCATION "${Lber_LIBRARY}"
  90. )
  91. endif()
  92. if(Ldap_FOUND AND NOT TARGET Ldap::Ldap)
  93. add_library(Ldap::Ldap UNKNOWN IMPORTED)
  94. set_target_properties(
  95. Ldap::Ldap
  96. PROPERTIES IMPORTED_LOCATION "${Ldap_LIBRARY}"
  97. INTERFACE_INCLUDE_DIRECTORIES "${Ldap_INCLUDE_DIRS}"
  98. INTERFACE_LINK_LIBRARIES Lber::Lber
  99. )
  100. endif()
  101. mark_as_advanced(Ldap_INCLUDE_DIRS Ldap_LIBRARY Lber_LIBRARY Ldap_LIBRARIES)
  102. include(FeatureSummary)
  103. set_package_properties(
  104. Ldap PROPERTIES
  105. URL "https://www.openldap.org/"
  106. DESCRIPTION "LDAP (Lightweight Directory Access Protocol) libraries."
  107. )