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

minizip-ng: conan v2 support #14446

Merged
merged 1 commit into from
Dec 2, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 0 additions & 9 deletions recipes/minizip-ng/all/CMakeLists.txt

This file was deleted.

55 changes: 55 additions & 0 deletions recipes/minizip-ng/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,58 @@ sources:
"3.0.1":
url: "https://github.com/zlib-ng/minizip-ng/archive/3.0.1.tar.gz"
sha256: "96c95b274dd535984ce0e87691691388f2b976106e8cf8d527b15da552ac94e4"
patches:
"3.0.7":
- patch_file: "patches/3.0.7-0001-fix-cmake-project.patch"
patch_description: "CMake: declare project() sooner"
patch_type: "conan"
- patch_file: "patches/3.0.6-0002-fix-lzma-libdir.patch"
patch_description: "CMake: inject libdir of lzma"
patch_type: "conan"
patch_source: "https://github.com/zlib-ng/minizip-ng/pull/658"
"3.0.6":
- patch_file: "patches/3.0.6-0001-fix-cmake-project.patch"
patch_description: "CMake: declare project() sooner"
patch_type: "conan"
- patch_file: "patches/3.0.6-0002-fix-lzma-libdir.patch"
patch_description: "CMake: inject libdir of lzma"
patch_type: "conan"
patch_source: "https://github.com/zlib-ng/minizip-ng/pull/658"
"3.0.5":
- patch_file: "patches/3.0.5-0001-fix-cmake-project.patch"
patch_description: "CMake: declare project() sooner"
patch_type: "conan"
- patch_file: "patches/3.0.5-0002-fix-lzma-libdir.patch"
patch_description: "CMake: inject libdir of lzma"
patch_type: "conan"
patch_source: "https://github.com/zlib-ng/minizip-ng/pull/658"
"3.0.4":
- patch_file: "patches/3.0.4-0001-fix-cmake-project.patch"
- patch_file: "patches/3.0.1-0002-fix-lzma-libdir.patch"
patch_description: "CMake: inject libdir of lzma"
patch_type: "conan"
patch_source: "https://github.com/zlib-ng/minizip-ng/pull/658"
"3.0.3":
- patch_file: "patches/3.0.3-0001-fix-cmake-project.patch"
patch_description: "CMake: declare project() sooner"
patch_type: "conan"
- patch_file: "patches/3.0.1-0002-fix-lzma-libdir.patch"
patch_description: "CMake: inject libdir of lzma"
patch_type: "conan"
patch_source: "https://github.com/zlib-ng/minizip-ng/pull/658"
"3.0.2":
- patch_file: "patches/3.0.2-0001-fix-cmake-project.patch"
patch_description: "CMake: declare project() sooner"
patch_type: "conan"
- patch_file: "patches/3.0.1-0002-fix-lzma-libdir.patch"
patch_description: "CMake: inject libdir of lzma"
patch_type: "conan"
patch_source: "https://github.com/zlib-ng/minizip-ng/pull/658"
"3.0.1":
- patch_file: "patches/3.0.1-0001-fix-cmake-project.patch"
patch_description: "CMake: declare project() sooner"
patch_type: "conan"
- patch_file: "patches/3.0.1-0002-fix-lzma-libdir.patch"
patch_description: "CMake: inject libdir of lzma"
patch_type: "conan"
patch_source: "https://github.com/zlib-ng/minizip-ng/pull/658"
115 changes: 67 additions & 48 deletions recipes/minizip-ng/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,14 @@
from conan import ConanFile
from conan.tools.apple import is_apple_os
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.env import Environment, VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, replace_in_file, rmdir
from conan.tools.gnu import PkgConfigDeps
from conan.tools.microsoft import is_msvc
from conans import ConanFile, tools, CMake
import functools
from conan.tools.scm import Version
import os

required_conan_version = ">=1.45.0"
required_conan_version = ">=1.53.0"


class MinizipNgConan(ConanFile):
Expand Down Expand Up @@ -42,95 +47,110 @@ class MinizipNgConan(ConanFile):
"with_libcomp": True,
}

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

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

@property
def _build_subfolder(self):
return "build_subfolder"
def _needs_pkg_config(self):
return self.options.with_lzma or self.options.with_zstd or self.options.with_openssl

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

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC
del self.options.with_iconv
del self.options.with_libbsd
if not tools.is_apple_os(self.settings.os):
if not is_apple_os(self):
del self.options.with_libcomp

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.cppstd
del self.settings.compiler.libcxx
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")
if self.options.mz_compatibility:
self.provides = "minizip"
if self.options.get_safe("with_libcomp"):
del self.options.with_zlib

def layout(self):
cmake_layout(self, src_folder="src")

def requirements(self):
if self.options.get_safe("with_zlib"):
self.requires("zlib/1.2.12")
self.requires("zlib/1.2.13")
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.2")
if self.options.with_openssl:
self.requires("openssl/1.1.1q")
self.requires("openssl/1.1.1s")
if self.settings.os != "Windows":
if self.options.get_safe("with_iconv"):
self.requires("libiconv/1.17")

def build_requirements(self):
self.build_requires("pkgconf/1.7.4")
if self._needs_pkg_config:
self.tool_requires("pkgconf/1.9.3")

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):
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)

get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate(self):
if self._needs_pkg_config:
env = VirtualBuildEnv(self)
env.generate()

tc = CMakeToolchain(self)
tc.cache_variables["MZ_FETCH_LIBS"] = False
tc.cache_variables["MZ_COMPAT"] = self.options.mz_compatibility
tc.cache_variables["MZ_ZLIB"] = self.options.get_safe("with_zlib", False)
tc.cache_variables["MZ_BZIP2"] = self.options.with_bzip2
tc.cache_variables["MZ_LZMA"] = self.options.with_lzma
tc.cache_variables["MZ_ZSTD"] = self.options.with_zstd
tc.cache_variables["MZ_OPENSSL"] = self.options.with_openssl
tc.cache_variables["MZ_LIBCOMP"] = self.options.get_safe("with_libcomp", False)
if self.settings.os != "Windows":
cmake.definitions["MZ_ICONV"] = self.options.with_iconv
cmake.definitions["MZ_LIBBSD"] = self.options.with_libbsd

cmake.configure(build_folder=self._build_subfolder)
return cmake
tc.cache_variables["MZ_ICONV"] = self.options.with_iconv
tc.cache_variables["MZ_LIBBSD"] = self.options.with_libbsd
tc.variables["CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS"] = True
tc.generate()

deps = CMakeDeps(self)
deps.generate()

if self._needs_pkg_config:
deps = PkgConfigDeps(self)
deps.generate()
# TODO: to remove when properly handled by conan (see https://github.com/conan-io/conan/issues/11962)
env = Environment()
env.prepend_path("PKG_CONFIG_PATH", self.generators_folder)
env.vars(self).save_script("conanbuild_pkg_config_path")

def _patch_sources(self):
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
apply_conandata_patches(self)
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"set_target_properties(${PROJECT_NAME} PROPERTIES POSITION_INDEPENDENT_CODE 1)",
"")

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

def package(self):
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
copy(self, "LICENSE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "cmake"))
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "minizip")
Expand All @@ -139,11 +159,11 @@ def package_info(self):

# 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"
suffix = "" if 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"):
if is_apple_os(self) 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")
Expand All @@ -153,7 +173,6 @@ def package_info(self):
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"].set_property("cmake_target_name", "MINIZIP::minizip")
Expand Down
22 changes: 22 additions & 0 deletions recipes/minizip-ng/all/patches/3.0.1-0001-fix-cmake-project.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -63,10 +63,10 @@ endif()
# BZIP2_ROOT - Parent directory of BZip2 installation
# OPENSSL_ROOT - Parent directory of OpenSSL installation

-enable_language(C)

# Library version
set(VERSION "3.0.1")
+project(minizip${MZ_PROJECT_SUFFIX} VERSION ${VERSION} LANGUAGES C)

# API version
set(SOVERSION "3.0")
@@ -677,7 +677,6 @@ endif()
list(APPEND MINIZIP_INC ${CMAKE_CURRENT_SOURCE_DIR})

# Create minizip library
-project(minizip${MZ_PROJECT_SUFFIX} VERSION ${VERSION})

if(NOT ${MZ_PROJECT_SUFFIX} STREQUAL "")
message(STATUS "Project configured as ${PROJECT_NAME}")
10 changes: 10 additions & 0 deletions recipes/minizip-ng/all/patches/3.0.1-0002-fix-lzma-libdir.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -312,6 +312,7 @@ if(MZ_LZMA)

list(APPEND MINIZIP_INC ${LIBLZMA_INCLUDE_DIRS})
list(APPEND MINIZIP_LIB ${LIBLZMA_LIBRARIES})
+ list(APPEND MINIZIP_LBD ${LIBLZMA_LIBRARY_DIRS})

set(PC_PRIVATE_LIBS "${PC_PRIVATE_LIBS} -lliblzma")
elseif(MZ_FETCH_LIBS)
22 changes: 22 additions & 0 deletions recipes/minizip-ng/all/patches/3.0.2-0001-fix-cmake-project.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -63,10 +63,10 @@ endif()
# BZIP2_ROOT - Parent directory of BZip2 installation
# OPENSSL_ROOT - Parent directory of OpenSSL installation

-enable_language(C)

# Library version
set(VERSION "3.0.2")
+project(minizip${MZ_PROJECT_SUFFIX} VERSION ${VERSION} LANGUAGES C)

# API version
set(SOVERSION "3.0")
@@ -681,7 +681,6 @@ endif()
list(APPEND MINIZIP_INC ${CMAKE_CURRENT_SOURCE_DIR})

# Create minizip library
-project(minizip${MZ_PROJECT_SUFFIX} VERSION ${VERSION})

if(NOT ${MZ_PROJECT_SUFFIX} STREQUAL "")
message(STATUS "Project configured as ${PROJECT_NAME}")
22 changes: 22 additions & 0 deletions recipes/minizip-ng/all/patches/3.0.3-0001-fix-cmake-project.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -63,10 +63,10 @@ endif()
# BZIP2_ROOT - Parent directory of BZip2 installation
# OPENSSL_ROOT - Parent directory of OpenSSL installation

-enable_language(C)

# Library version
set(VERSION "3.0.3")
+project(minizip${MZ_PROJECT_SUFFIX} VERSION ${VERSION} LANGUAGES C)

# API version
set(SOVERSION "3")
@@ -681,7 +681,6 @@ endif()
list(APPEND MINIZIP_INC ${CMAKE_CURRENT_SOURCE_DIR})

# Create minizip library
-project(minizip${MZ_PROJECT_SUFFIX} VERSION ${VERSION})

if(NOT ${MZ_PROJECT_SUFFIX} STREQUAL "")
message(STATUS "Project configured as ${PROJECT_NAME}")
22 changes: 22 additions & 0 deletions recipes/minizip-ng/all/patches/3.0.4-0001-fix-cmake-project.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -63,10 +63,10 @@ endif()
# BZIP2_ROOT - Parent directory of BZip2 installation
# OPENSSL_ROOT - Parent directory of OpenSSL installation

-enable_language(C)

# Library version
set(VERSION "3.0.4")
+project(minizip${MZ_PROJECT_SUFFIX} VERSION ${VERSION} LANGUAGES C)

# API version
set(SOVERSION "3")
@@ -681,7 +681,6 @@ endif()
list(APPEND MINIZIP_INC ${CMAKE_CURRENT_SOURCE_DIR})

# Create minizip library
-project(minizip${MZ_PROJECT_SUFFIX} VERSION ${VERSION})

if(NOT ${MZ_PROJECT_SUFFIX} STREQUAL "")
message(STATUS "Project configured as ${PROJECT_NAME}")
22 changes: 22 additions & 0 deletions recipes/minizip-ng/all/patches/3.0.5-0001-fix-cmake-project.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -66,10 +66,10 @@ endif()
# BZIP2_ROOT - Parent directory of BZip2 installation
# OPENSSL_ROOT - Parent directory of OpenSSL installation

-enable_language(C)

# Library version
set(VERSION "3.0.5")
+project(minizip${MZ_PROJECT_SUFFIX} VERSION ${VERSION} LANGUAGES C)

# API version
set(SOVERSION "3")
@@ -661,7 +661,6 @@ endif()
list(APPEND MINIZIP_INC ${CMAKE_CURRENT_SOURCE_DIR})

# Create minizip library
-project(minizip${MZ_PROJECT_SUFFIX} VERSION ${VERSION})

if(NOT ${MZ_PROJECT_SUFFIX} STREQUAL "")
message(STATUS "Project configured as ${PROJECT_NAME}")
10 changes: 10 additions & 0 deletions recipes/minizip-ng/all/patches/3.0.5-0002-fix-lzma-libdir.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -303,6 +303,7 @@ if(MZ_LZMA)

list(APPEND MINIZIP_INC ${LIBLZMA_INCLUDE_DIRS})
list(APPEND MINIZIP_LIB ${LIBLZMA_LIBRARIES})
+ list(APPEND MINIZIP_LBD ${LIBLZMA_LIBRARY_DIRS})

set(PC_PRIVATE_LIBS "${PC_PRIVATE_LIBS} -lliblzma")
elseif(MZ_FETCH_LIBS)
Loading