Skip to content

Commit

Permalink
(conan-io#16749) openldap: conan v2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
grabowski-d committed Mar 29, 2023
1 parent d94d343 commit 65c3417
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 58 deletions.
85 changes: 34 additions & 51 deletions recipes/openldap/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import os
from conans import ConanFile, AutoToolsBuildEnvironment, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.tools.files import get, apply_conandata_patches, rmdir, rm, copy
from conan.tools.gnu import AutotoolsToolchain, Autotools, AutotoolsDeps
from conan.tools.apple import fix_apple_shared_install_name
from conan.errors import ConanInvalidConfiguration
required_conan_version = ">=1.43.0"


Expand All @@ -22,25 +25,22 @@ class OpenldapConan(ConanFile):
"shared": False,
"fPIC": 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

def source(self):
tools.get(**self.conan_data["sources"][self.version],
get(self, **self.conan_data["sources"][self.version],
strip_root=True, destination=self._source_subfolder)

def requirements(self):
self.requires("openssl/1.1.1q")
self.requires("openssl/1.1.1t")
if self.options.with_cyrus_sasl:
self.requires("cyrus-sasl/2.1.27")

Expand All @@ -49,55 +49,38 @@ def validate(self):
raise ConanInvalidConfiguration(
f"{self.name} is only supported on Linux")

def _configure_autotools(self):
if self._autotools:
return self._autotools

def generate(self):
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)),
"--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
autotools_tc = AutotoolsToolchain(self)
autotools_tc.update_configure_args({
"--with-cyrus_sasl": yes_no(self.options.with_cyrus_sasl),
"--with-pic": yes_no(self.options.get_safe("fPIC", True)),
"--without-fetch": "",
"--with-tls": "openssl",
"--enable-auditlog": ""})

env = autotools_tc.environment()
env.define("systemdsystemunitdir", os.path.join(self.package_folder, "res"))
autotools_tc.generate(env)

deps = AutotoolsDeps(self)
deps.generate()

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)
apply_conandata_patches(self)
autotools = Autotools(self)
autotools.configure(build_script_folder=self._source_subfolder)
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)
autotools = Autotools(self)
autotools.install()
fix_apple_shared_install_name(self)
copy(self, "LICENSE", dst="licenses", src=self._source_subfolder)
copy(self, "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")
rmdir(self, os.path.join(self.package_folder, folder))
rm(self, pattern="*.la", folder=os.path.join( self.package_folder,"lib"), recursive=True)

def package_info(self):
bin_path = os.path.join(self.package_folder, "bin")
Expand Down
2 changes: 0 additions & 2 deletions recipes/openldap/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
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)
target_link_libraries(${PROJECT_NAME} openldap::openldap)
Expand Down
19 changes: 14 additions & 5 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.cmake import CMake
from conan.tools.build import cross_building
from conan.tools.layout import basic_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeToolchain", "CMakeDeps"

def requirements(self):
self.requires(self.tested_reference_str)

def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()

def layout(self):
basic_layout(self)

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 not cross_building(self):
cmd = os.path.join(self.cpp.build.bindir, "test_package")
self.run(cmd, env="conanrun")

0 comments on commit 65c3417

Please sign in to comment.