Repository: conan-io/conan-center-index

Issue:
[request] liblzf
### Package Name/Version

liblzf/3.6

### Webpage

http://software.schmorp.de/pkg/liblzf.html

### Source code

http://cvs.schmorp.de/liblzf/

### Description of the library/tool

A small pure-C library for compressing / decompressing the LZF format.

> LZF is an extremely fast (not that much slower than a pure memcpy) compression algorithm. It is ideal for applications where you want to save *some* space but not at the cost of speed. It is ideal for repetitive data as well. The module is self-contained and very small.

[![Packaging status](https://repology.org/badge/tiny-repos/liblzf.svg)](https://repology.org/project/liblzf/versions)


Discussion:

Resolving patch:
diff --git a/recipes/liblzf/all/conanfile.py b/recipes/liblzf/all/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/liblzf/all/conanfile.py
@@ -0,0 +1,67 @@
+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
+import os
+
+required_conan_version = ">=1.53.0"
+
+
+class LiblzfConan(ConanFile):
+    name = "liblzf"
+    description = (
+        "LZF is an extremely fast (not that much slower than a pure memcpy) "
+        "compression algorithm. It is ideal for applications where you want to "
+        "save *some* space but not at the cost of speed."
+    )
+    url = "https://github.com/conan-io/conan-center-index"
+    homepage = "http://software.schmorp.de/pkg/liblzf.html"
+    topics = ("lzf", "compression")
+    license = "BSD-2-Clause", "GPL-2.0-or-later"
+    package_type = "library"
+    settings = "os", "arch", "compiler", "build_type"
+    options = {
+        "shared": [True, False],
+        "fPIC": [True, False],
+    }
+    default_options = {
+        "shared": False,
+        "fPIC": True,
+    }
+
+    def export_sources(self):
+        copy(self, "CMakeLists.txt", src=self.recipe_folder, dst=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:
+            self.options.rm_safe("fPIC")
+        self.settings.rm_safe("compiler.libcxx")
+        self.settings.rm_safe("compiler.cppstd")
+
+    def layout(self):
+        cmake_layout(self, src_folder="src")
+
+    def source(self):
+        get(self, **self.conan_data["sources"][self.version], strip_root=True)
+
+    def generate(self):
+        tc = CMakeToolchain(self)
+        tc.generate()
+
+    def build(self):
+        apply_conandata_patches(self)
+        cmake = CMake(self)
+        cmake.configure(build_script_folder=os.path.join(self.source_folder, os.pardir))
+        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()
+
+    def package_info(self):
+        self.cpp_info.libs = ["lzf"]


Test patch:
diff --git a/recipes/liblzf/all/test_package/CMakeLists.txt b/recipes/liblzf/all/test_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/liblzf/all/test_package/CMakeLists.txt
@@ -0,0 +1,7 @@
+cmake_minimum_required(VERSION 3.15)
+project(test_package LANGUAGES CXX)
+
+find_package(liblzf REQUIRED CONFIG)
+
+add_executable(${PROJECT_NAME} test_package.cpp)
+target_link_libraries(${PROJECT_NAME} PRIVATE liblzf::liblzf)
diff --git a/recipes/liblzf/all/test_package/conanfile.py b/recipes/liblzf/all/test_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/liblzf/all/test_package/conanfile.py
@@ -0,0 +1,27 @@
+from conan import ConanFile
+from conan.tools.build import can_run
+from conan.tools.cmake import cmake_layout, CMake
+import os
+
+
+# It will become the standard on Conan 2.x
+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.bindir, "test_package")
+            self.run(bin_path, env="conanrun")
diff --git a/recipes/liblzf/all/test_package/test_package.cpp b/recipes/liblzf/all/test_package/test_package.cpp
new file mode 100644
--- /dev/null
+++ b/recipes/liblzf/all/test_package/test_package.cpp
@@ -0,0 +1,16 @@
+#include <cstdlib>
+#include <iostream>
+#include <lzf.h>
+
+int main(void) {
+  const char in_data[] = "AAAAAAAAAAAAAAAAAAAAA";
+  const unsigned int buf_len = 100;
+  char compressed_data[buf_len];
+  char decompressed_data[buf_len];
+  unsigned int compressed_len = lzf_compress(in_data, sizeof(in_data), compressed_data, buf_len);
+  unsigned int decompressed_len = lzf_decompress(compressed_data, compressed_len, decompressed_data, buf_len);
+  if (compressed_len >= 10 || decompressed_len != sizeof(in_data)) {
+    return EXIT_FAILURE;
+  }
+  return EXIT_SUCCESS;
+}
diff --git a/recipes/liblzf/all/test_v1_package/CMakeLists.txt b/recipes/liblzf/all/test_v1_package/CMakeLists.txt
new file mode 100644
--- /dev/null
+++ b/recipes/liblzf/all/test_v1_package/CMakeLists.txt
@@ -0,0 +1,8 @@
+cmake_minimum_required(VERSION 3.15)
+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/)
diff --git a/recipes/liblzf/all/test_v1_package/conanfile.py b/recipes/liblzf/all/test_v1_package/conanfile.py
new file mode 100644
--- /dev/null
+++ b/recipes/liblzf/all/test_v1_package/conanfile.py
@@ -0,0 +1,19 @@
+from conans import ConanFile, CMake
+from conan.tools.build import cross_building
+import os
+
+
+# legacy validation with Conan 1.x
+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 cross_building(self):
+            bin_path = os.path.join("bin", "test_package")
+            self.run(bin_path, run_environment=True)