Skip to content

Commit

Permalink
(conan-io#5264) conanized zlib-ng 2.0.0
Browse files Browse the repository at this point in the history
* conanized zlib-ng 2.0.0

Signed-off-by: tkrupa <tomas@krupa.hu>

* removed win static lib suffix

Signed-off-by: tkrupa <tomas@krupa.hu>

* conanized useful cmake options

Signed-off-by: tkrupa <tomas@krupa.hu>

* Update recipes/zlib-ng/all/test_package/conanfile.py

Test package following common template

Co-authored-by: Chris Mc <prince.chrismc@gmail.com>

* reduced test package

Signed-off-by: tkrupa <tomas@krupa.hu>

* test_package depending on zlib.ng explicitely

Signed-off-by: tkrupa <tomas@krupa.hu>

* using upstream cmake install

Signed-off-by: tkrupa <tomas@krupa.hu>

* Update recipes/zlib-ng/all/test_package/test_package.c

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* using cmake wrapper

Signed-off-by: tkrupa <tomas@krupa.hu>

* Improve zlib-ng

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Update recipes/zlib-ng/all/conandata.yml

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Update recipes/zlib-ng/config.yml

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Update recipes/zlib-ng/all/test_package/test_package.c

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Update recipes/zlib-ng/all/conanfile.py

Co-authored-by: Chris Mc <prince.chrismc@gmail.com>

* Update recipes/zlib-ng/all/test_package/CMakeLists.txt

Co-authored-by: Chris Mc <prince.chrismc@gmail.com>

* Update recipes/zlib-ng/all/conanfile.py

Co-authored-by: Chris Mc <prince.chrismc@gmail.com>

Co-authored-by: Chris Mc <prince.chrismc@gmail.com>
Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
3 people authored and AlvaroFS committed May 7, 2021
1 parent 1f89642 commit b03ff45
Show file tree
Hide file tree
Showing 7 changed files with 153 additions and 0 deletions.
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):
#FIXME: CMake targets are https://github.com/zlib-ng/zlib-ng/blob/29fd4672a2279a0368be936d7cd44d013d009fae/CMakeLists.txt#L914
suffix = "" if self.options.zlib_compat else "-ng"
self.cpp_info.names["pkg_config"] = "zlib" + suffix
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"])
9 changes: 9 additions & 0 deletions recipes/zlib-ng/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)

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

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} CONAN_PKG::zlib-ng)
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

0 comments on commit b03ff45

Please sign in to comment.