Skip to content

Commit

Permalink
(conan-io#19476) zlib-ng: provide better compatibility with zlib
Browse files Browse the repository at this point in the history
  • Loading branch information
Nekto89 authored and Ahajha committed Feb 10, 2024
1 parent 919f592 commit 255c9d2
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
8 changes: 8 additions & 0 deletions recipes/zlib-ng/all/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ def configure(self):
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")
if self.options.zlib_compat:
self.provides = ["zlib"]

def layout(self):
cmake_layout(self, src_folder="src")
Expand Down Expand Up @@ -106,6 +108,12 @@ def package_info(self):
self.cpp_info.libs = [f"z{suffix}"]
if self.options.zlib_compat:
self.cpp_info.defines.append("ZLIB_COMPAT")
#copied from zlib
self.cpp_info.set_property("cmake_find_mode", "both")
self.cpp_info.set_property("cmake_file_name", "ZLIB")
self.cpp_info.set_property("cmake_target_name", "ZLIB::ZLIB")
self.cpp_info.names["cmake_find_package"] = "ZLIB"
self.cpp_info.names["cmake_find_package_multi"] = "ZLIB"
if self.options.with_gzfileop:
self.cpp_info.defines.append("WITH_GZFILEOP")
if not self.options.with_new_strategies:
Expand Down
10 changes: 8 additions & 2 deletions recipes/zlib-ng/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES C)

find_package(zlib-ng REQUIRED CONFIG)
if (ZLIB_COMPAT)
set(zlib_name ZLIB)
else()
set(zlib_name zlib-ng)
endif()

find_package(${zlib_name} REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE zlib-ng::zlib-ng)
target_link_libraries(${PROJECT_NAME} PRIVATE ${zlib_name}::${zlib_name})
target_compile_features(${PROJECT_NAME} PRIVATE c_std_99)
9 changes: 7 additions & 2 deletions recipes/zlib-ng/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
import os


class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
generators = "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def layout(self):
Expand All @@ -15,6 +15,11 @@ def layout(self):
def requirements(self):
self.requires(self.tested_reference_str)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["ZLIB_COMPAT"] = bool(self.dependencies["zlib-ng"].options.zlib_compat)
tc.generate()

def build(self):
cmake = CMake(self)
cmake.configure()
Expand Down
1 change: 1 addition & 0 deletions recipes/zlib-ng/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class TestPackageConan(ConanFile):

def build(self):
cmake = CMake(self)
cmake.definitions["ZLIB_COMPAT"] = self.options["zlib-ng"].zlib_compat
cmake.configure()
cmake.build()

Expand Down

0 comments on commit 255c9d2

Please sign in to comment.