Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

openldap: migrate to Conan v2 #18800

Merged
merged 14 commits into from
Apr 19, 2024
Merged
11 changes: 5 additions & 6 deletions recipes/openldap/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
sources:
"2.6.7":
url: "https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-2.6.7.tgz"
sha256: "cd775f625c944ed78a3da18a03b03b08eea73c8aabc97b41bb336e9a10954930"
"2.6.1":
url: https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-2.6.1.tgz
sha256: 9d576ea6962d7db8a2e2808574e8c257c15aef55f403a1fb5a0faf35de70e6f3
patches:
"2.6.1":
- base_path: source_subfolder
patch_file: patches/configure-2.6.1.patch
url: "https://www.openldap.org/software/download/OpenLDAP/openldap-release/openldap-2.6.1.tgz"
sha256: "9d576ea6962d7db8a2e2808574e8c257c15aef55f403a1fb5a0faf35de70e6f3"
152 changes: 78 additions & 74 deletions recipes/openldap/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
12 changes: 0 additions & 12 deletions recipes/openldap/all/patches/configure-2.6.1.patch

This file was deleted.

13 changes: 6 additions & 7 deletions recipes/openldap/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
21 changes: 15 additions & 6 deletions recipes/openldap/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,26 @@
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)
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)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindir, "test_package")
self.run(bin_path, env="conanrun")
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
8 changes: 8 additions & 0 deletions recipes/openldap/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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/)
17 changes: 17 additions & 0 deletions recipes/openldap/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -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)
2 changes: 2 additions & 0 deletions recipes/openldap/config.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
versions:
"2.6.7":
folder: all
"2.6.1":
folder: all
Loading