Skip to content

Commit

Permalink
lzham: Add 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
partiallyderived committed Oct 20, 2022
1 parent 5a274d8 commit f4e3f4b
Show file tree
Hide file tree
Showing 8 changed files with 187 additions and 0 deletions.
4 changes: 4 additions & 0 deletions recipes/lzham/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
sources:
"1.0.0":
sha256: "4f4f874706763b3a6e3d6dfff666a1e850ca1d92fd9240b2a14365c5864a0057"
url: "https://github.com/richgel999/lzham_codec/archive/refs/tags/v1_0_stable1.tar.gz"
96 changes: 96 additions & 0 deletions recipes/lzham/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import (
apply_conandata_patches, copy, export_conandata_patches, get, rmdir
)

required_conan_version = ">=1.52.0"


class PackageConan(ConanFile):
name = "lzham"

description = (
"Compression algorithm similar compression ratio and faster "
"decompression than LZMA."
)

license = "LicenseRef-LICENSE"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/richgel999/lzham_codec"
topics = ("compression", "lz-compression")
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

def export_sources(self):
export_conandata_patches(self)

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

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

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

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

def generate(self):
tc = CMakeToolchain(self)
tc.generate()

def build(self):
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(
self,
pattern="LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder
)
cmake = CMake(self)
cmake.install()

rmdir(self, 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, "res"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
self.cpp_info.libs.extend(["lzhamdecomp", "lzhamcomp", "lzhamdll"])
self.cpp_info.set_property("cmake_file_name", "lzham")
self.cpp_info.set_property("cmake_target_name", "lzham::lzham")
self.cpp_info.set_property("pkg_config_name", "lzham")

if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["m", "pthread"])

# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = "lzham"
self.cpp_info.names["cmake_find_package_multi"] = "lzham"
self.cpp_info.names["pkg_config"] = "lzham"
7 changes: 7 additions & 0 deletions recipes/lzham/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.8)
project(test_package CXX)

find_package(lzham REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC lzham::lzham)
27 changes: 27 additions & 0 deletions recipes/lzham/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import os

from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake


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

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

def layout(self):
cmake_layout(self)

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

def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
23 changes: 23 additions & 0 deletions recipes/lzham/all/test_package/test_package.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include <cstdlib>
#include <cstring>

#include <lzham_static_lib.h>

int main() {
unsigned char in[] = "Hello Conan Center!";
unsigned char out[sizeof(in)];

lzham_z_stream stream;
std::memset(&stream, 0, sizeof(stream));
stream.next_in = in;
stream.avail_in = sizeof(in);
stream.next_out = out;
stream.avail_out = sizeof(out);
if (lzham_z_deflateInit(&stream, LZHAM_Z_BEST_COMPRESSION) != LZHAM_Z_OK)
return EXIT_FAILURE;

if (lzham_z_deflate(&stream, LZHAM_Z_FULL_FLUSH) != LZHAM_Z_OK)
return EXIT_FAILURE;

return EXIT_SUCCESS;
}
10 changes: 10 additions & 0 deletions recipes/lzham/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.8)
project(test_package CXX)

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

find_package(lzham REQUIRED CONFIG)

add_executable(${PROJECT_NAME} ../test_package/test_package.cpp)
target_link_libraries(${PROJECT_NAME} PUBLIC lzham::lzham)
17 changes: 17 additions & 0 deletions recipes/lzham/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 TestPackageV1Conan(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)
3 changes: 3 additions & 0 deletions recipes/lzham/config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
versions:
"1.0.0":
folder: all

0 comments on commit f4e3f4b

Please sign in to comment.