Repository: conan-io/conan-center-index

Issue:
(#16749) openldap: conan v2 support
Specify library name and version:  **openldap/2.6.1**

It solves the issue #16749 


---

- [x] I've read the [contributing guidelines](https://github.com/conan-io/conan-center-index/blob/master/CONTRIBUTING.md).
- [x] I've used a [recent](https://github.com/conan-io/conan/releases/latest) Conan client version close to the [currently deployed](https://github.com/conan-io/conan-center-index/blob/master/.c3i/config_v1.yml#L6).
- [x] I've tried at least one configuration locally with the [conan-center hook](https://github.com/conan-io/hooks.git) activated.



Discussion:
[![CLA assistant check](https://cla-assistant.io/pull/badge/not_signed)](https://cla-assistant.io/conan-io/conan-center-index?pullRequest=16762) <br/>Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you all sign our [Contributor License Agreement](https://cla-assistant.io/conan-io/conan-center-index?pullRequest=16762) before we can accept your contribution.<br/>**1** out of **2** committers have signed the CLA.<br/><br/>:white_check_mark: jcar87<br/>:x: grabowski-d<br/><sub>You have signed the CLA already but the status is still pending? Let us [recheck](https://cla-assistant.io/check/conan-io/conan-center-index?pullRequest=16762) it.</sub>
### Conan v1 pipeline :x:

Sorry, the build is only launched for Access Request users. You can request access [writing in this issue](https://github.com/conan-io/conan-center-index/issues/4).

----------

### Conan v2 pipeline (informative, not required for merge) :x:

> **Note**: Conan v2 builds are informative and they are not required for the PR to be merged.

The v2 pipeline failed. Please, review the errors and note this will be required for pull requests to be merged in the near future.

<details>

<summary> See details: </summary>

Sorry, the build is only launched for Access Request users. You can request access [writing in this issue](https://github.com/conan-io/conan-center-index/issues/4).

</details>
### Conan v1 pipeline :x:

Sorry, the build is only launched for Access Request users. You can request access [writing in this issue](https://github.com/conan-io/conan-center-index/issues/4).

----------

### Conan v2 pipeline (informative, not required for merge) :x:

> **Note**: Conan v2 builds are informative and they are not required for the PR to be merged.

The v2 pipeline failed. Please, review the errors and note this will be required for pull requests to be merged in the near future.

<details>

<summary> See details: </summary>

Sorry, the build is only launched for Access Request users. You can request access [writing in this issue](https://github.com/conan-io/conan-center-index/issues/4).

</details>

Resolving patch:
diff --git a/recipes/openldap/all/conanfile.py b/recipes/openldap/all/conanfile.py
--- a/recipes/openldap/all/conanfile.py
+++ b/recipes/openldap/all/conanfile.py
@@ -1,110 +1,114 @@
 import os
-from conans import ConanFile, AutoToolsBuildEnvironment, tools
-from conans.errors import ConanInvalidConfiguration
-required_conan_version = ">=1.43.0"
+
+from conan import ConanFile
+from conan.errors import ConanInvalidConfiguration
+from conan.tools.build import cross_building
+from conan.tools.env import VirtualRunEnv
+from conan.tools.files import chdir, copy, get, rm, rmdir, replace_in_file
+from conan.tools.gnu import Autotools, AutotoolsDeps, AutotoolsToolchain
+from conan.tools.layout import basic_layout
+
+required_conan_version = ">=1.53.0"
 
 
 class OpenldapConan(ConanFile):
     name = "openldap"
-    description = "OpenLDAP C++ library"
+    description = "OpenLDAP C library"
+    license = "OLDAP-2.8"
     url = "https://github.com/conan-io/conan-center-index"
     homepage = "https://www.openldap.org/"
-    license = "OLDAP-2.8"
     topics = ("ldap", "load-balancer", "directory-access")
-    exports_sources = ["patches/*"]
-    settings = settings = "os", "compiler", "build_type", "arch"
+
+    package_type = "library"
+    settings = "os", "arch", "compiler", "build_type"
     options = {
         "shared": [True, False],
         "fPIC": [True, False],
-        "with_cyrus_sasl": [True, False]
+        "with_cyrus_sasl": [True, False],
     }
     default_options = {
         "shared": False,
         "fPIC": True,
-        "with_cyrus_sasl": True
-
+        "with_cyrus_sasl": True,
     }
-    _autotools = None
-    _configure_vars = None
-
-    @property
-    def _source_subfolder(self):
-        return "source_subfolder"
 
     def configure(self):
         if self.options.shared:
-            del self.options.fPIC
+            self.options.rm_safe("fPIC")
+        self.settings.rm_safe("compiler.cppstd")
+        self.settings.rm_safe("compiler.libcxx")
 
-    def source(self):
-        tools.get(**self.conan_data["sources"][self.version],
-                  strip_root=True, destination=self._source_subfolder)
+    def layout(self):
+        basic_layout(self, src_folder="src")
 
     def requirements(self):
-        self.requires("openssl/1.1.1q")
+        self.requires("openssl/[>=1.1 <4]")
         if self.options.with_cyrus_sasl:
-            self.requires("cyrus-sasl/2.1.27")
+            self.requires("cyrus-sasl/2.1.28")
 
     def validate(self):
-        if self.settings.os != "Linux":
-            raise ConanInvalidConfiguration(
-                f"{self.name} is only supported on Linux")
-
-    def _configure_autotools(self):
-        if self._autotools:
-            return self._autotools
-
-        def yes_no(v): return "yes" if v else "no"
-        self._autotools = AutoToolsBuildEnvironment(self)
-        configure_args = [
-            "--enable-shared={}".format(yes_no(self.options.shared)),
-            "--enable-static={}".format(yes_no(not self.options.shared)),
+        if self.settings.os not in ["Linux", "FreeBSD"]:
+            raise ConanInvalidConfiguration(f"{self.name} is only supported on Linux")
+
+    def source(self):
+        get(self, **self.conan_data["sources"][self.version], strip_root=True)
+
+    def generate(self):
+        if not cross_building(self):
+            env = VirtualRunEnv(self)
+            env.generate(scope="build")
+
+        def yes_no(v):
+            return "yes" if v else "no"
+
+        tc = AutotoolsToolchain(self)
+        tc.configure_args += [
             "--with-cyrus_sasl={}".format(yes_no(self.options.with_cyrus_sasl)),
-            "--with-pic={}".format(yes_no(self.options.get_safe("fPIC", True))),
             "--without-fetch",
             "--with-tls=openssl",
-            "--enable-auditlog"]
-        self._configure_vars = self._autotools.vars
-        self._configure_vars["systemdsystemunitdir"] = os.path.join(
-            self.package_folder, "res")
-
-        # Need to link to -pthread instead of -lpthread for gcc 8 shared=True
-        # on CI job. Otherwise, linking fails.
-        self._autotools.libs.remove("pthread")
-        self._configure_vars["LIBS"] = self._configure_vars["LIBS"].replace(
-            "-lpthread", "-pthread")
-
-        self._autotools.configure(
-            args=configure_args,
-            configure_dir=self._source_subfolder,
-            vars=self._configure_vars)
-        return self._autotools
+            "--enable-auditlog",
+            "--libexecdir=${prefix}/bin",
+            f"systemdsystemunitdir={os.path.join(self.package_folder, 'res')}",
+        ]
+        tc.generate()
+        tc = AutotoolsDeps(self)
+        tc.generate()
+
+    def _patch_sources(self):
+        replace_in_file(self, os.path.join(self.source_folder, "configure"),
+                        "WITH_SYSTEMD=no\nsystemdsystemunitdir=", "WITH_SYSTEMD=no")
 
     def build(self):
-        for patch in self.conan_data["patches"][self.version]:
-            tools.patch(**patch)
-        autotools = self._configure_autotools()
-
-        autotools.make(vars=self._configure_vars)
+        self._patch_sources()
+        with chdir(self, self.source_folder):
+            autotools = Autotools(self)
+            autotools.configure()
+            autotools.make()
 
     def package(self):
-        autotools = self._configure_autotools()
-        autotools.install(vars=self._configure_vars)
-        self.copy("LICENSE", dst="licenses", src=self._source_subfolder)
-        self.copy("COPYRIGHT", dst="licenses", src=self._source_subfolder)
-        for folder in ["var", "share", "etc", "lib/pkgconfig", "res"]:
-            tools.rmdir(os.path.join(self.package_folder, folder))
-        tools.remove_files_by_mask(
-            os.path.join(
-                self.package_folder,
-                "lib"),
-            "*.la")
+        with chdir(self, self.source_folder):
+            autotools = Autotools(self)
+            autotools.install()
+        copy(self, "LICENSE", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
+        copy(self, "COPYRIGHT", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
+        rm(self, "*.la", self.package_folder, recursive=True)
+        for folder in ["var", "share", "etc", os.path.join("lib", "pkgconfig"), "home"]:
+            rmdir(self, os.path.join(self.package_folder, folder))
 
     def package_info(self):
-        bin_path = os.path.join(self.package_folder, "bin")
-        self.env_info.PATH.append(bin_path)
-        self.output.info(
-            "Appending PATH environment variable: {}".format(bin_path))
+        self.cpp_info.components["ldap"].set_property("pkg_config_name", "ldap")
+        self.cpp_info.components["ldap"].libs = ["ldap"]
+        if self.settings.os in ["Linux", "FreeBSD"]:
+            self.cpp_info.components["ldap"].system_libs = ["pthread", "resolv"]
+        self.cpp_info.components["ldap"].requires = ["lber", "openssl::ssl", "openssl::crypto"]
+        if self.options.with_cyrus_sasl:
+            self.cpp_info.components["ldap"].requires.append("cyrus-sasl::cyrus-sasl")
 
-        self.cpp_info.libs = ["ldap", "lber"]
+        self.cpp_info.components["lber"].set_property("pkg_config_name", "lber")
+        self.cpp_info.components["lber"].libs = ["lber"]
         if self.settings.os in ["Linux", "FreeBSD"]:
-            self.cpp_info.system_libs = ["pthread"]
+            self.cpp_info.components["lber"].system_libs = ["pthread"]
+
+        # TODO: to remove in conan v2
+        bin_path = os.path.join(self.package_folder, "bin")
+        self.env_info.PATH.append(bin_path)


Test patch:
diff --git a/recipes/openldap/all/test_package/CMakeLists.txt b/recipes/openldap/all/test_package/CMakeLists.txt
--- a/recipes/openldap/all/test_package/CMakeLists.txt
+++ b/recipes/openldap/all/test_package/CMakeLists.txt
@@ -1,8 +1,7 @@
-cmake_minimum_required(VERSION 3.1)
-project(test_package)
-include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
-conan_basic_setup(TARGETS)
-find_package(openldap CONFIG REQUIRED)
-add_executable(${PROJECT_NAME} test_package.cpp)
+cmake_minimum_required(VERSION 3.15)
+project(test_package LANGUAGES C)
+
+find_package(openldap REQUIRED CONFIG)
+
+add_executable(${PROJECT_NAME} test_package.c)
 target_link_libraries(${PROJECT_NAME} openldap::openldap)
-set_property(TARGET ${PROJECT_NAME} PROPERTY CXX_STANDARD 11)
diff --git a/recipes/openldap/all/test_package/conanfile.py b/recipes/openldap/all/test_package/conanfile.py
--- a/recipes/openldap/all/test_package/conanfile.py
+++ b/recipes/openldap/all/test_package/conanfile.py
@@ -1,10 +1,19 @@
-from conans import ConanFile, CMake, tools
+from conan import ConanFile
+from conan.tools.build import can_run
+from conan.tools.cmake import cmake_layout, CMake
 import os
 
 
 class TestPackageConan(ConanFile):
-    settings = "os", "compiler", "build_type", "arch"
-    generators = "cmake", "cmake_find_package_multi"
+    settings = "os", "arch", "compiler", "build_type"
+    generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
+    test_type = "explicit"
+
+    def requirements(self):
+        self.requires(self.tested_reference_str)
+
+    def layout(self):
+        cmake_layout(self)
 
     def build(self):
         cmake = CMake(self)
@@ -12,6 +21,6 @@ def build(self):
         cmake.build()
 
     def test(self):
-        if not tools.cross_building(self):
-            bin_path = os.path.join("bin", "test_package")
-            self.run(bin_path, run_environment=True)
+        if can_run(self):
+            bin_path = os.path.join(self.cpp.build.bindir, "test_package")
+            self.run(bin_path, env="conanrun")
diff --git a/recipes/openldap/all/test_package/test_package.cpp b/recipes/openldap/all/test_package/test_package.c
similarity index 99%
rename from recipes/openldap/all/test_package/test_package.cpp
rename to recipes/openldap/all/test_package/test_package.c
--- a/recipes/openldap/all/test_package/test_package.cpp
+++ b/recipes/openldap/all/test_package/test_package.c
@@ -29,10 +29,11 @@
  * for inclusion in OpenLDAP software.
  */
 
-#include <stdio.h>
-#include <cstdlib>
 #include "openldap.h"
 
+#include <stdio.h>
+#include <stdlib.h>
+
 static int do_uri_create(LDAPURLDesc *lud) {
   char *uri;
 
diff --git a/recipes/openldap/all/test_v1_package/CMakeLists.txt b/recipes/openldap/all/test_v1_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/openldap/all/test_v1_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.15)
+project(test_package)
+
+include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
+conan_basic_setup(TARGETS)
+
+add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package/
+                 ${CMAKE_CURRENT_BINARY_DIR}/test_package/)
diff --git a/recipes/openldap/all/test_v1_package/conanfile.py b/recipes/openldap/all/test_v1_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/openldap/all/test_v1_package/conanfile.py
@@ -0,0 +1,17 @@
+from conans import ConanFile, CMake, tools
+import os
+
+
+class TestPackageConan(ConanFile):
+    settings = "os", "compiler", "build_type", "arch"
+    generators = "cmake", "cmake_find_package_multi"
+
+    def build(self):
+        cmake = CMake(self)
+        cmake.configure()
+        cmake.build()
+
+    def test(self):
+        if not tools.cross_building(self):
+            bin_path = os.path.join("bin", "test_package")
+            self.run(bin_path, run_environment=True)