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

conanized zlib-ng 2.0.0 #5264

Merged
merged 17 commits into from
May 4, 2021
Merged
Show file tree
Hide file tree
Changes from 14 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
7 changes: 7 additions & 0 deletions recipes/zlib-ng/all/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 2.8.11)
project(cmake_wrapper)

include(conanbuildinfo.cmake)
conan_basic_setup()

add_subdirectory("source_subfolder")
4 changes: 4 additions & 0 deletions recipes/zlib-ng/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"2.0.2":
sha256: "dd37886f22ca6890e403ea6c1d60f36eab1d08d2f232a35f5b02126621149d28"
url: "https://github.com/Dead2/zlib-ng/archive/2.0.2.tar.gz"
98 changes: 98 additions & 0 deletions recipes/zlib-ng/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration

import os

class ZlibNgConan(ConanFile):
name = "zlib-ng"
description = "zlib data compression library for the next generation systems"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/Dead2/zlib-ng/"
license ="Zlib"
topics = ("conan", "zlib", "compression")
exports_sources = ["CMakeLists.txt"]
generators = "cmake", "cmake_find_package"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False],
"zlib_compat": [True, False],
"with_gzfileop": [True, False],
"with_optim": [True, False],
"with_new_strategies": [True, False],
"with_native_instructions": [True, False],
"fPIC": [True, False]}
default_options = {"shared": False,
"zlib_compat": False,
"with_gzfileop": True,
"with_optim": False,
"with_new_strategies": True,
"with_native_instructions": False,
"fPIC": True}
_cmake = None

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

@property
def _build_subfolder(self):
return "build_subfolder"

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

def source(self):
tools.get(**self.conan_data["sources"][self.version])
os.rename("zlib-ng-{}".format(self.version), self._source_subfolder)

def validate(self):
if self.options.zlib_compat and not self.options.with_gzfileop:
raise ConanInvalidConfiguration("The option 'with_gzfileop' must be True when 'zlib_compat' is True.")

def _configure_cmake(self):
if not self._cmake:
self._cmake = CMake(self)
self._cmake.definitions["ZLIB_ENABLE_TESTS"] = False
self._cmake.definitions["ZLIB_COMPAT"] = self.options.zlib_compat
self._cmake.definitions["WITH_GZFILEOP"] = self.options.with_gzfileop
self._cmake.definitions["WITH_OPTIM"] = self.options.with_optim
self._cmake.definitions["WITH_NEW_STRATEGIES"] = self.options.with_new_strategies
self._cmake.definitions["WITH_NATIVE_INSTRUCTIONS"] = self.options.with_native_instructions

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

def build(self):
cmake = self._configure_cmake()
cmake.build()

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

def package_info(self):
self.cpp_info.names["cmake_find_package"] = "ZLIB"
self.cpp_info.names["cmake_find_package_multi"] = "ZLIB"
tomas-krupa marked this conversation as resolved.
Show resolved Hide resolved
suffix = "" if self.options.zlib_compat else "-ng"
if self.settings.os == "Windows":
if self.settings.build_type == "Debug":
self.cpp_info.libs = ["zlib{}d".format(suffix)]
else:
self.cpp_info.libs = ["zlib{}".format(suffix)]

else:
self.cpp_info.libs = ["z{}".format(suffix)]
if self.options.zlib_compat:
self.cpp_info.defines.append("ZLIB_COMPAT")
if self.options.with_gzfileop:
self.cpp_info.defines.append("WITH_GZFILEOP")
if not self.options.with_new_strategies:
self.cpp_info.defines.extend(["NO_QUICK_STRATEGY", "NO_MEDIUM_STRATEGY"])
11 changes: 11 additions & 0 deletions recipes/zlib-ng/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)

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

find_package(ZLIB REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ZLIB::ZLIB)
tomas-krupa marked this conversation as resolved.
Show resolved Hide resolved
tomas-krupa marked this conversation as resolved.
Show resolved Hide resolved
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99)
17 changes: 17 additions & 0 deletions recipes/zlib-ng/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import os
from conans import ConanFile, CMake, tools


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
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.settings):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
15 changes: 15 additions & 0 deletions recipes/zlib-ng/all/test_package/test_package.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#include <stdio.h>
#include <stdlib.h>

#ifdef ZLIB_COMPAT
# include "zlib.h"
# define ZLIB_VERSION zlibVersion
#else
# include "zlib-ng.h"
# define ZLIB_VERSION zlibng_version
#endif

int main(void) {
printf("ZLIB NG VERSION: %s\n", ZLIB_VERSION());
return EXIT_SUCCESS;
}
3 changes: 3 additions & 0 deletions recipes/zlib-ng/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"2.0.2":
folder: all