FindLDAP.cmake 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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. if(CURL_USE_PKGCONFIG AND
  42. NOT DEFINED LDAP_INCLUDE_DIR AND
  43. NOT DEFINED LDAP_LIBRARY AND
  44. NOT DEFINED LDAP_LBER_LIBRARY)
  45. find_package(PkgConfig QUIET)
  46. pkg_check_modules(LDAP "ldap")
  47. pkg_check_modules(LDAP_LBER "lber")
  48. endif()
  49. if(LDAP_FOUND AND LDAP_LBER_FOUND)
  50. list(APPEND LDAP_LIBRARIES ${LDAP_LBER_LIBRARIES})
  51. list(REVERSE LDAP_LIBRARIES)
  52. list(REMOVE_DUPLICATES LDAP_LIBRARIES)
  53. list(REVERSE LDAP_LIBRARIES)
  54. set(LDAP_PC_REQUIRES "ldap")
  55. string(REPLACE ";" " " LDAP_CFLAGS "${LDAP_CFLAGS}")
  56. message(STATUS "Found LDAP (via pkg-config): ${LDAP_INCLUDE_DIRS} (found version \"${LDAP_VERSION}\")")
  57. else()
  58. # On Apple the SDK LDAP gets picked up from
  59. # 'MacOSX.sdk/System/Library/Frameworks/LDAP.framework/Headers', which contains
  60. # ldap.h and lber.h both being stubs to include <ldap.h> and <lber.h>.
  61. # This causes an infinite inclusion loop in compile.
  62. set(_save_cmake_system_framework_path ${CMAKE_SYSTEM_FRAMEWORK_PATH})
  63. set(CMAKE_SYSTEM_FRAMEWORK_PATH "")
  64. find_path(LDAP_INCLUDE_DIR NAMES "ldap.h")
  65. set(CMAKE_SYSTEM_FRAMEWORK_PATH ${_save_cmake_system_framework_path})
  66. find_library(LDAP_LIBRARY NAMES "ldap")
  67. find_library(LDAP_LBER_LIBRARY NAMES "lber")
  68. unset(LDAP_VERSION CACHE)
  69. if(LDAP_INCLUDE_DIR AND EXISTS "${LDAP_INCLUDE_DIR}/ldap_features.h")
  70. set(_version_regex1 "#[\t ]*define[\t ]+LDAP_VENDOR_VERSION_MAJOR[\t ]+([0-9]+).*")
  71. set(_version_regex2 "#[\t ]*define[\t ]+LDAP_VENDOR_VERSION_MINOR[\t ]+([0-9]+).*")
  72. set(_version_regex3 "#[\t ]*define[\t ]+LDAP_VENDOR_VERSION_PATCH[\t ]+([0-9]+).*")
  73. file(STRINGS "${LDAP_INCLUDE_DIR}/ldap_features.h" _version_str1 REGEX "${_version_regex1}")
  74. file(STRINGS "${LDAP_INCLUDE_DIR}/ldap_features.h" _version_str2 REGEX "${_version_regex2}")
  75. file(STRINGS "${LDAP_INCLUDE_DIR}/ldap_features.h" _version_str3 REGEX "${_version_regex3}")
  76. string(REGEX REPLACE "${_version_regex1}" "\\1" _version_str1 "${_version_str1}")
  77. string(REGEX REPLACE "${_version_regex2}" "\\1" _version_str2 "${_version_str2}")
  78. string(REGEX REPLACE "${_version_regex3}" "\\1" _version_str3 "${_version_str3}")
  79. set(LDAP_VERSION "${_version_str1}.${_version_str2}.${_version_str3}")
  80. unset(_version_regex1)
  81. unset(_version_regex2)
  82. unset(_version_regex3)
  83. unset(_version_str1)
  84. unset(_version_str2)
  85. unset(_version_str3)
  86. endif()
  87. include(FindPackageHandleStandardArgs)
  88. find_package_handle_standard_args(LDAP
  89. REQUIRED_VARS
  90. LDAP_INCLUDE_DIR
  91. LDAP_LIBRARY
  92. LDAP_LBER_LIBRARY
  93. VERSION_VAR
  94. LDAP_VERSION
  95. )
  96. if(LDAP_FOUND)
  97. set(LDAP_INCLUDE_DIRS ${LDAP_INCLUDE_DIR})
  98. set(LDAP_LIBRARIES ${LDAP_LIBRARY} ${LDAP_LBER_LIBRARY})
  99. endif()
  100. mark_as_advanced(LDAP_INCLUDE_DIR LDAP_LIBRARY LDAP_LBER_LIBRARY)
  101. endif()