cmake: fix HAVE_LDAP_SSL, HAVE_LDAP_URL_PARSE on non-Windows

- set `HAVE_LDAP_URL_PARSE` if `ldap_url_parse` function exists.
  Before this patch we set it based it on the presence of `stricmp`,
  which correctly enabled it on e.g. Windows, but was inaccurate for
  other platforms.

- always set `HAVE_LDAP_SSL` if an LDAP backend is detected and
  LDAPS is not explicitly disabled. This mimics autotools behaviour.
  Previously we set it only for Windows LDAP. After this fix, LDAPS is
  correctly enabled in default macOS builds.

- enable LDAP[S] for a CMake macOS CI job. Target OS X 10.9 (Mavericks)
  to avoid deprecation warnings for LDAP API.

- always detect `HAVE_LDAP_SSL_H`, even with LDAPS explicitly disabled.
  This doesn't make much sense, but let's do it to sync behaviour with
  autotools.

- fix benign typo in variable name.

Ref: #11964 (effort to sync cmake detections with autotools)

Closes #12006
This commit is contained in:
Viktor Szakats 2023-10-02 09:57:14 +00:00
parent 4c6365af02
commit 772f0d8edf
No known key found for this signature in database
GPG Key ID: B5ABD165E2AEF201
2 changed files with 18 additions and 13 deletions

View File

@ -205,7 +205,7 @@ jobs:
build: build:
- name: OpenSSL - name: OpenSSL
install: nghttp2 openssl install: nghttp2 openssl
generate: -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DCURL_DISABLE_LDAP=ON -DCURL_DISABLE_LDAPS=ON generate: -DOPENSSL_ROOT_DIR=/usr/local/opt/openssl -DCMAKE_OSX_DEPLOYMENT_TARGET=10.9
- name: LibreSSL - name: LibreSSL
install: nghttp2 libressl install: nghttp2 libressl
generate: -DOPENSSL_ROOT_DIR=/usr/local/opt/libressl -DCURL_DISABLE_LDAP=ON -DCURL_DISABLE_LDAPS=ON -DCMAKE_UNITY_BUILD=ON generate: -DOPENSSL_ROOT_DIR=/usr/local/opt/libressl -DCURL_DISABLE_LDAP=ON -DCURL_DISABLE_LDAPS=ON -DCMAKE_UNITY_BUILD=ON

View File

@ -797,11 +797,17 @@ if(NOT CURL_DISABLE_LDAP)
endif() endif()
list(APPEND _HEADER_LIST "ldap.h") list(APPEND _HEADER_LIST "ldap.h")
set(_SRC_STRING "") set(_INCLUDE_STRING "")
foreach(_HEADER ${_HEADER_LIST}) foreach(_HEADER ${_HEADER_LIST})
set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n") set(_INCLUDE_STRING "${_INCLUDE_STRING}#include <${_HEADER}>\n")
endforeach() endforeach()
list(APPEND CMAKE_REQUIRED_DEFINITIONS -DLDAP_DEPRECATED=1)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
if(HAVE_LIBLBER)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
endif()
set(_SRC_STRING set(_SRC_STRING
" "
${_INCLUDE_STRING} ${_INCLUDE_STRING}
@ -813,19 +819,22 @@ if(NOT CURL_DISABLE_LDAP)
return 0; return 0;
}" }"
) )
list(APPEND CMAKE_REQUIRED_DEFINITIONS -DLDAP_DEPRECATED=1)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LDAP_LIB})
if(HAVE_LIBLBER)
list(APPEND CMAKE_REQUIRED_LIBRARIES ${CMAKE_LBER_LIB})
endif()
check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H) check_c_source_compiles("${_SRC_STRING}" NOT_NEED_LBER_H)
unset(CMAKE_REQUIRED_LIBRARIES)
if(NOT_NEED_LBER_H) if(NOT_NEED_LBER_H)
set(NEED_LBER_H OFF) set(NEED_LBER_H OFF)
else() else()
set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H") set(CURL_TEST_DEFINES "${CURL_TEST_DEFINES} -DNEED_LBER_H")
endif() endif()
check_function_exists(ldap_url_parse HAVE_LDAP_URL_PARSE)
unset(CMAKE_REQUIRED_LIBRARIES)
check_include_file("ldap_ssl.h" HAVE_LDAP_SSL_H)
if(NOT CURL_DISABLE_LDAPS)
set(HAVE_LDAP_SSL ON)
endif()
endif() endif()
endif() endif()
endif() endif()
@ -838,10 +847,6 @@ if(CURL_DISABLE_LDAP)
endif() endif()
endif() endif()
if(NOT CURL_DISABLE_LDAPS)
check_include_file_concat("ldap_ssl.h" HAVE_LDAP_SSL_H)
endif()
# Check for idn2 # Check for idn2
option(USE_LIBIDN2 "Use libidn2 for IDN support" ON) option(USE_LIBIDN2 "Use libidn2 for IDN support" ON)
if(USE_LIBIDN2) if(USE_LIBIDN2)