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: add 1.2.13 + conan v2 support #13863

Merged
merged 2 commits into from
Nov 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
82 changes: 41 additions & 41 deletions recipes/minizip/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,75 +1,75 @@
# This CMake file has been extracted from VCPKG and is under MIT license:
# https://github.com/microsoft/vcpkg/blob/master/ports/minizip/CMakeLists.txt
cmake_minimum_required(VERSION 3.4)
project(minizip C)
project(minizip LANGUAGES C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(KEEP_RPATHS)

option(ENABLE_BZIP2 "Build minizip with bzip2 support" ON)
option(BUILD_TOOLS "Build minizip tool" OFF)
option(MINIZIP_ENABLE_BZIP2 "Build minizip with bzip2 support" ON)
option(MINIZIP_BUILD_TOOLS "Build minizip tool" OFF)

include(GNUInstallDirs)

set(CMAKE_WINDOWS_EXPORT_ALL_SYMBOLS ON)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY "${PROJECT_BINARY_DIR}/bin")

set(MIN_SRC "${CMAKE_CURRENT_SOURCE_DIR}/source_subfolder/contrib/minizip")
include_directories(${MIN_SRC})
find_package(ZLIB REQUIRED)
if(MINIZIP_ENABLE_BZIP2)
find_package(BZip2 REQUIRED)
endif()

set(SOURCE_FILES
${MIN_SRC}/ioapi.c
${MIN_SRC}/unzip.c
${MIN_SRC}/zip.c
${MIN_SRC}/mztools.c
${MINIZIP_SRC_DIR}/ioapi.c
${MINIZIP_SRC_DIR}/unzip.c
${MINIZIP_SRC_DIR}/zip.c
${MINIZIP_SRC_DIR}/mztools.c
)
if(WIN32)
list(APPEND SOURCE_FILES ${MIN_SRC}/iowin32.c)
list(APPEND SOURCE_FILES ${MINIZIP_SRC_DIR}/iowin32.c)
endif()

set(HEADER_FILES
${MIN_SRC}/ioapi.h
${MIN_SRC}/unzip.h
${MIN_SRC}/zip.h
${MIN_SRC}/mztools.h
${MINIZIP_SRC_DIR}/ioapi.h
${MINIZIP_SRC_DIR}/unzip.h
${MINIZIP_SRC_DIR}/zip.h
${MINIZIP_SRC_DIR}/mztools.h
)
if(WIN32)
list(APPEND HEADER_FILES ${MIN_SRC}/iowin32.h)
list(APPEND HEADER_FILES ${MINIZIP_SRC_DIR}/iowin32.h)
endif()

add_library(minizip ${SOURCE_FILES})
target_link_libraries(minizip PUBLIC ${CONAN_LIBS})
target_link_libraries(minizip PUBLIC ZLIB::ZLIB)
target_compile_definitions(minizip PRIVATE -D_ZLIB_H)
target_include_directories(minizip PUBLIC ${MINIZIP_SRC_DIR})
set_target_properties(minizip PROPERTIES WINDOWS_EXPORT_ALL_SYMBOLS ON)

if(ENABLE_BZIP2)
target_compile_definitions(minizip PRIVATE -DHAVE_BZIP2=1)
if(MINIZIP_ENABLE_BZIP2)
target_compile_definitions(minizip PUBLIC HAVE_BZIP2=1)
target_link_libraries(minizip PUBLIC BZip2::BZip2)
endif()
if(MSVC)
target_compile_options(minizip PUBLIC /W3 /wd4005 /wd4996 /wd4018 -D_CRT_SECURE_NO_WARNINGS)
target_compile_options(minizip PRIVATE /wd4005 /wd4996 /wd4018 -D_CRT_SECURE_NO_WARNINGS)
endif()

if (BUILD_TOOLS)
add_executable(minizip_bin ${MIN_SRC}/minizip.c)
add_executable(miniunz_bin ${MIN_SRC}/miniunz.c)
install(
TARGETS minizip
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(FILES ${HEADER_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/minizip)

if(MINIZIP_BUILD_TOOLS)
add_executable(minizip_bin ${MINIZIP_SRC_DIR}/minizip.c)
add_executable(miniunz_bin ${MINIZIP_SRC_DIR}/miniunz.c)

target_link_libraries(minizip_bin minizip ${CONAN_LIBS})
target_link_libraries(miniunz_bin minizip ${CONAN_LIBS})
target_link_libraries(minizip_bin PRIVATE minizip)
target_link_libraries(miniunz_bin PRIVATE minizip)

set_target_properties(minizip_bin PROPERTIES OUTPUT_NAME minizip)
set_target_properties(miniunz_bin PROPERTIES OUTPUT_NAME miniunz)

if(MSVC)
target_compile_options(minizip_bin PUBLIC /W3 /wd4005 /wd4996 /wd4018 -D_CRT_SECURE_NO_WARNINGS)
target_compile_options(miniunz_bin PUBLIC /W3 /wd4005 /wd4996 /wd4018 -D_CRT_SECURE_NO_WARNINGS)
target_compile_options(minizip_bin PRIVATE /wd4005 /wd4996 /wd4018 -D_CRT_SECURE_NO_WARNINGS)
target_compile_options(miniunz_bin PRIVATE /wd4005 /wd4996 /wd4018 -D_CRT_SECURE_NO_WARNINGS)
endif()

install(TARGETS minizip_bin miniunz_bin DESTINATION ${CMAKE_INSTALL_BINDIR})
endif()

install(
TARGETS minizip
RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR}
LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR}
ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR}
)

install(FILES ${HEADER_FILES} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/minizip)
9 changes: 5 additions & 4 deletions recipes/minizip/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
sources:
"1.2.13":
url: "https://github.com/madler/zlib/archive/refs/tags/v1.2.13.tar.gz"
sha256: "1525952a0a567581792613a9723333d7f8cc20b87a81f920fb8bc7e3f2251428"
"1.2.12":
url: "https://github.com/madler/zlib/archive/refs/tags/v1.2.12.tar.gz"
sha256: "d8688496ea40fb61787500e863cc63c9afcbc524468cedeb478068924eb54932"
"1.2.11":
url: "https://github.com/madler/zlib/archive/v1.2.11.tar.gz"
sha256: "629380c90a77b964d896ed37163f5c3a34f6e6d897311f1df2a7016355c45eff"
patches:
"1.2.13":
- patch_file: "patches/minizip.patch"
"1.2.12":
- patch_file: "patches/minizip.patch"
base_path: "source_subfolder"
- patch_file: "patches/ioapi.patch"
base_path: "source_subfolder"
"1.2.11":
- patch_file: "patches/minizip.patch"
base_path: "source_subfolder"
- patch_file: "patches/miniunz.patch"
base_path: "source_subfolder"
82 changes: 42 additions & 40 deletions recipes/minizip/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
from conan import ConanFile
from conan.tools import files
from conans import CMake
import functools
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, copy, export_conandata_patches, get, load, save
import os

required_conan_version = ">=1.46.0"
required_conan_version = ">=1.52.0"


class MinizipConan(ConanFile):
Expand All @@ -28,68 +28,70 @@ class MinizipConan(ConanFile):
"tools": False,
}

generators = "cmake"

@property
def _source_subfolder(self):
return "source_subfolder"

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
copy(self, "CMakeLists.txt", self.recipe_folder, self.export_sources_folder)
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
try:
del self.options.fPIC
except Exception:
pass
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass

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

def requirements(self):
self.requires("zlib/1.2.12")
self.requires("zlib/1.2.13")
if self.options.bzip2:
self.requires("bzip2/1.0.8")

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

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["ENABLE_BZIP2"] = self.options.bzip2
cmake.definitions["BUILD_TOOLS"] = self.options.tools
cmake.configure()
return cmake
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

def generate(self):
tc = CMakeToolchain(self)
tc.variables["MINIZIP_SRC_DIR"] = os.path.join(self.source_folder, "contrib", "minizip").replace("\\", "/")
tc.variables["MINIZIP_ENABLE_BZIP2"] = self.options.bzip2
tc.variables["MINIZIP_BUILD_TOOLS"] = self.options.tools
tc.generate()
deps = CMakeDeps(self)
deps.generate()

def build(self):
files.apply_conandata_patches(self)
cmake = self._configure_cmake()
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
cmake.build()

def _extract_license(self):
with files.chdir(self, f"{self.source_folder}/{self._source_subfolder}"):
tmp = files.load(self, "zlib.h")
license_contents = tmp[2:tmp.find("*/", 1)]
files.save(self, "LICENSE", license_contents)
zlib_h = load(self, os.path.join(self.source_folder, "zlib.h"))
return zlib_h[2:zlib_h.find("*/", 1)]

def package(self):
self._extract_license()
self.copy("LICENSE", src=self._source_subfolder, dst="licenses")
cmake = self._configure_cmake()
save(self, os.path.join(self.package_folder, "licenses", "LICENSE"), self._extract_license())
cmake = CMake(self)
cmake.install()

def package_info(self):
self.cpp_info.libs = ["minizip"]
self.cpp_info.includedirs = ["include", "include/minizip"]
self.cpp_info.includedirs.append(os.path.join("include", "minizip"))
if self.options.bzip2:
self.cpp_info.defines.append("HAVE_BZIP2")

if self.options.tools:
bin_path = f"{self.package_folder}/bin"
self.output.info(f"Appending PATH environment variable: {bin_path}")
self.env_info.PATH.append(bin_path)
self.env_info.PATH.append(os.path.join(self.package_folder, "bin"))
9 changes: 3 additions & 6 deletions recipes/minizip/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
project(test_package LANGUAGES C)

find_package(minizip REQUIRED CONFIG)

add_executable(test_package test_package.c)
target_link_libraries(test_package minizip::minizip)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE minizip::minizip)
22 changes: 15 additions & 7 deletions recipes/minizip/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,18 +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, cmake_layout
import os


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

def layout(self):
cmake_layout(self)

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

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.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
1 change: 0 additions & 1 deletion recipes/minizip/all/test_package/test_package.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,3 @@ int main(int argc, char** argv) {

return EXIT_SUCCESS;
}

8 changes: 8 additions & 0 deletions recipes/minizip/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.1)
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/minizip/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", "arch", "compiler", "build_type"
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/minizip/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
versions:
"1.2.13":
folder: all
"1.2.12":
folder: all
"1.2.11":
Expand Down