Skip to content

Commit

Permalink
(#10564) minizip-ng: bump dependencies + modernize
Browse files Browse the repository at this point in the history
* bump dependencies

* modernize

* explicit cpp_info.libs
  • Loading branch information
SpaceIm authored May 5, 2022
1 parent 9e031f0 commit 4f087e5
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 41 deletions.
4 changes: 2 additions & 2 deletions recipes/minizip-ng/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
cmake_minimum_required(VERSION 3.4)
project(cmake_wrapper)
project(cmake_wrapper C)

include(conanbuildinfo.cmake)
conan_basic_setup()
conan_basic_setup(KEEP_RPATHS)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)

Expand Down
88 changes: 52 additions & 36 deletions recipes/minizip-ng/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
import os
from conan.tools.microsoft import is_msvc
from conans import ConanFile, tools, CMake
import functools
import os

required_conan_version = ">=1.45.0"


class MinizipNgConan(ConanFile):
name = "minizip-ng"
description = "Fork of the popular zip manipulation library found in the zlib distribution."
topics = ("conan", "compression", "zip")
topics = ("compression", "zip")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/zlib-ng/minizip-ng"
license = "Zlib"
exports_sources = "CMakeLists.txt"
generators = "cmake", "cmake_find_package", "pkg_config"
settings = "os", "compiler", "build_type", "arch"

settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand Down Expand Up @@ -39,7 +42,8 @@ class MinizipNgConan(ConanFile):
"with_libcomp": True,
}

_cmake = None
exports_sources = "CMakeLists.txt"
generators = "cmake", "cmake_find_package", "pkg_config"

@property
def _source_subfolder(self):
Expand All @@ -49,6 +53,10 @@ def _source_subfolder(self):
def _build_subfolder(self):
return "build_subfolder"

@property
def _is_clang_cl(self):
return self.settings.os == "Windows" and self.settings.compiler == "clang"

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
Expand All @@ -57,9 +65,6 @@ def config_options(self):
if not tools.is_apple_os(self.settings.os):
del self.options.with_libcomp

def build_requirements(self):
self.build_requires('pkgconf/1.7.3')

def configure(self):
if self.options.shared:
del self.options.fPIC
Expand All @@ -72,41 +77,43 @@ def configure(self):

def requirements(self):
if self.options.get_safe("with_zlib"):
self.requires("zlib/1.2.11")
self.requires("zlib/1.2.12")
if self.options.with_bzip2:
self.requires("bzip2/1.0.8")
if self.options.with_lzma:
self.requires("xz_utils/5.2.5")
if self.options.with_zstd:
self.requires("zstd/1.5.0")
self.requires("zstd/1.5.2")
if self.options.with_openssl:
self.requires("openssl/1.1.1l")
self.requires("openssl/1.1.1n")
if self.settings.os != "Windows":
if self.options.get_safe("with_iconv"):
self.requires("libiconv/1.16")

def build_requirements(self):
self.build_requires("pkgconf/1.7.4")

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

@functools.lru_cache(1)
def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.definitions["MZ_FETCH_LIBS"] = False
self._cmake.definitions["MZ_COMPAT"] = self.options.mz_compatibility
self._cmake.definitions["MZ_ZLIB"] = self.options.get_safe("with_zlib", False)
self._cmake.definitions["MZ_BZIP2"] = self.options.with_bzip2
self._cmake.definitions["MZ_LZMA"] = self.options.with_lzma
self._cmake.definitions["MZ_ZSTD"] = self.options.with_zstd
self._cmake.definitions["MZ_OPENSSL"] = self.options.with_openssl
self._cmake.definitions["MZ_LIBCOMP"] = self.options.get_safe("with_libcomp", False)
cmake = CMake(self)
cmake.definitions["MZ_FETCH_LIBS"] = False
cmake.definitions["MZ_COMPAT"] = self.options.mz_compatibility
cmake.definitions["MZ_ZLIB"] = self.options.get_safe("with_zlib", False)
cmake.definitions["MZ_BZIP2"] = self.options.with_bzip2
cmake.definitions["MZ_LZMA"] = self.options.with_lzma
cmake.definitions["MZ_ZSTD"] = self.options.with_zstd
cmake.definitions["MZ_OPENSSL"] = self.options.with_openssl
cmake.definitions["MZ_LIBCOMP"] = self.options.get_safe("with_libcomp", False)

if self.settings.os != "Windows":
self._cmake.definitions["MZ_ICONV"] = self.options.with_iconv
self._cmake.definitions["MZ_LIBBSD"] = self.options.with_libbsd
cmake.definitions["MZ_ICONV"] = self.options.with_iconv
cmake.definitions["MZ_LIBBSD"] = self.options.with_libbsd

self._cmake.configure(build_folder=self._build_subfolder)
return self._cmake
cmake.configure(build_folder=self._build_subfolder)
return cmake

def _patch_sources(self):
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
Expand All @@ -126,15 +133,31 @@ def package(self):
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "minizip")
self.cpp_info.set_property("cmake_target_name", "MINIZIP::minizip")
self.cpp_info.set_property("pkg_config_name", "minizip")

# TODO: back to global scope in conan v2 once cmake_find_package_* generators removed
prefix = "lib" if is_msvc(self) or self._is_clang_cl else ""
suffix = "" if tools.Version(self.version) < "3.0.5" or self.options.mz_compatibility else "-ng"
self.cpp_info.components["minizip"].libs = [f"{prefix}minizip{suffix}"]
if self.options.with_lzma:
self.cpp_info.components["minizip"].defines.append("HAVE_LZMA")
if tools.is_apple_os(self.settings.os) and self.options.get_safe("with_libcomp"):
self.cpp_info.components["minizip"].defines.append("HAVE_LIBCOMP")
if self.options.with_bzip2:
self.cpp_info.components["minizip"].defines.append("HAVE_BZIP2")

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.filenames["cmake_find_package"] = "minizip"
self.cpp_info.filenames["cmake_find_package_multi"] = "minizip"
self.cpp_info.names["cmake_find_package"] = "MINIZIP"
self.cpp_info.names["cmake_find_package_multi"] = "MINIZIP"
self.cpp_info.names["pkg_config"] = "minizip"
self.cpp_info.components["minizip"].names["cmake_find_package"] = "minizip"
self.cpp_info.components["minizip"].names["cmake_find_package_multi"] = "minizip"
self.cpp_info.components["minizip"].libs = tools.collect_libs(self)

self.cpp_info.components["minizip"].set_property("cmake_target_name", "MINIZIP::minizip")
self.cpp_info.components["minizip"].set_property("pkg_config_name", "minizip")
if self.options.get_safe("with_zlib"):
self.cpp_info.components["minizip"].requires.append("zlib::zlib")
if self.options.with_bzip2:
Expand All @@ -147,10 +170,3 @@ def package_info(self):
self.cpp_info.components["minizip"].requires.append("openssl::openssl")
if self.settings.os != "Windows" and self.options.with_iconv:
self.cpp_info.components["minizip"].requires.append("libiconv::libiconv")

if self.options.with_lzma:
self.cpp_info.components["minizip"].defines.append('HAVE_LZMA')
if tools.is_apple_os(self.settings.os) and self.options.get_safe("with_libcomp"):
self.cpp_info.components["minizip"].defines.append('HAVE_LIBCOMP')
if self.options.with_bzip2:
self.cpp_info.components["minizip"].defines.append('HAVE_BZIP2')
2 changes: 1 addition & 1 deletion recipes/minizip-ng/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
Expand Down
4 changes: 2 additions & 2 deletions recipes/minizip-ng/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


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

def build(self):
Expand All @@ -12,6 +12,6 @@ def build(self):
cmake.build()

def test(self):
if not tools.cross_building(self.settings):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

0 comments on commit 4f087e5

Please sign in to comment.