From ee4f40d46f12faff414a1548a2f09031cb730103 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 13 Feb 2020 10:09:27 +0100 Subject: [PATCH 1/2] Add libqrencode/4.0.0 recipe --- recipes/libqrencode/all/CMakeLists.txt | 7 + recipes/libqrencode/all/conandata.yml | 10 + recipes/libqrencode/all/conanfile.py | 77 +++++ .../0001-remove-deprecated-attribute.patch | 11 + .../all/patches/0002-cmake-fix-install.patch | 11 + .../all/test_package/CMakeLists.txt | 10 + .../libqrencode/all/test_package/conanfile.py | 17 ++ recipes/libqrencode/all/test_package/genqr.c | 265 ++++++++++++++++++ recipes/libqrencode/all/test_package/genqr.h | 8 + .../all/test_package/test_package.cpp | 10 + recipes/libqrencode/config.yml | 3 + 11 files changed, 429 insertions(+) create mode 100644 recipes/libqrencode/all/CMakeLists.txt create mode 100644 recipes/libqrencode/all/conandata.yml create mode 100644 recipes/libqrencode/all/conanfile.py create mode 100644 recipes/libqrencode/all/patches/0001-remove-deprecated-attribute.patch create mode 100644 recipes/libqrencode/all/patches/0002-cmake-fix-install.patch create mode 100644 recipes/libqrencode/all/test_package/CMakeLists.txt create mode 100644 recipes/libqrencode/all/test_package/conanfile.py create mode 100644 recipes/libqrencode/all/test_package/genqr.c create mode 100644 recipes/libqrencode/all/test_package/genqr.h create mode 100644 recipes/libqrencode/all/test_package/test_package.cpp create mode 100644 recipes/libqrencode/config.yml diff --git a/recipes/libqrencode/all/CMakeLists.txt b/recipes/libqrencode/all/CMakeLists.txt new file mode 100644 index 0000000000000..a69305eb3971f --- /dev/null +++ b/recipes/libqrencode/all/CMakeLists.txt @@ -0,0 +1,7 @@ +cmake_minimum_required(VERSION 2.8.12) +project(cmake_wrapper) + +include(conanbuildinfo.cmake) +conan_basic_setup() + +add_subdirectory(source_subfolder) diff --git a/recipes/libqrencode/all/conandata.yml b/recipes/libqrencode/all/conandata.yml new file mode 100644 index 0000000000000..d42aead4c533b --- /dev/null +++ b/recipes/libqrencode/all/conandata.yml @@ -0,0 +1,10 @@ +sources: + "4.0.0": + url: "https://github.com/fukuchi/libqrencode/archive/v4.0.0.tar.gz" + sha256: "c2c8a8110354463a3332cb48abf8581c8d94136af4dc1418f891cc9c7719e3c1" +patches: + "4.0.0": + - base_path: "source_subfolder" + patch_file: "patches/0001-remove-deprecated-attribute.patch" + - base_path: "source_subfolder" + patch_file: "patches/0002-cmake-fix-install.patch" diff --git a/recipes/libqrencode/all/conanfile.py b/recipes/libqrencode/all/conanfile.py new file mode 100644 index 0000000000000..91f34fcdd2403 --- /dev/null +++ b/recipes/libqrencode/all/conanfile.py @@ -0,0 +1,77 @@ +from conans import CMake, ConanFile, tools +import os + + +class LibqrencodeConan(ConanFile): + name = "libqrencode" + description = "A fast and compact QR Code encoding library" + url = "https://github.com/conan-io/conan-center-index" + homepage = "https://github.com/fukuchi/libqrencode" + license = ("LGPL-2.1, LGPL-3.0") + exports_sources = "CMakeLists.txt", "patches/**" + generators = "cmake", "cmake_find_package" + settings = "os", "arch", "compiler", "build_type" + options = { + "shared": [True, False], + "fPIC": [True, False], + } + default_options = { + "shared": False, + "fPIC": True, + } + requires = ( + "libiconv/1.15", + "libpng/1.6.37", + ) + + @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.cppstd + del self.settings.compiler.libcxx + + def source(self): + tools.get(**self.conan_data["sources"][self.version]) + os.rename("libqrencode-{}".format(self.version), self._source_subfolder) + + def _configure_cmake(self): + cmake = CMake(self) + cmake.definitions["WITH_TOOLS"] = False + cmake.definitions["WITH_TESTS"] = False + cmake.configure(build_folder=self._build_subfolder) + return cmake + + def _patch_sources(self): + for patch in self.conan_data["patches"][self.version]: + tools.patch(**patch) + + def build(self): + self._patch_sources() + cmake = self._configure_cmake() + cmake.build() + + def package(self): + self.copy(pattern="COPYING", src=self._source_subfolder, dst="licenses") + cmake = self._configure_cmake() + cmake.install() + + tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig")) + tools.rmdir(os.path.join(self.package_folder, "share")) + + def package_info(self): + lib = "qrencode" + if self.settings.compiler == "Visual Studio" and self.settings.build_type == "Debug": + lib += "d" + self.cpp_info.libs = [lib] diff --git a/recipes/libqrencode/all/patches/0001-remove-deprecated-attribute.patch b/recipes/libqrencode/all/patches/0001-remove-deprecated-attribute.patch new file mode 100644 index 0000000000000..19b9901a21f53 --- /dev/null +++ b/recipes/libqrencode/all/patches/0001-remove-deprecated-attribute.patch @@ -0,0 +1,11 @@ +--- a/qrencode.h ++++ b/qrencode.h +@@ -555,7 +555,7 @@ extern char *QRcode_APIVersionString(void); + /** + * @deprecated + */ +-extern void QRcode_clearCache(void) __attribute__ ((deprecated)); ++extern void QRcode_clearCache(void); + + #if defined(__cplusplus) + } diff --git a/recipes/libqrencode/all/patches/0002-cmake-fix-install.patch b/recipes/libqrencode/all/patches/0002-cmake-fix-install.patch new file mode 100644 index 0000000000000..de88544935ad4 --- /dev/null +++ b/recipes/libqrencode/all/patches/0002-cmake-fix-install.patch @@ -0,0 +1,11 @@ +--- CMakeLists.txt ++++ CMakeLists.txt +@@ -120,7 +120,7 @@ + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/qrencode.1 DESTINATION share/man/man1) + install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libqrencode.pc DESTINATION lib/pkgconfig) + install(FILES qrencode.h DESTINATION include) +-install(TARGETS qrencode DESTINATION lib) ++install(TARGETS qrencode ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin) + + ## Build utility tools + if(WITH_TOOLS AND TARGET PNG::PNG) diff --git a/recipes/libqrencode/all/test_package/CMakeLists.txt b/recipes/libqrencode/all/test_package/CMakeLists.txt new file mode 100644 index 0000000000000..45cd29d9f4688 --- /dev/null +++ b/recipes/libqrencode/all/test_package/CMakeLists.txt @@ -0,0 +1,10 @@ +cmake_minimum_required(VERSION 2.8.11) +project(test_package) + +set(CMAKE_VERBOSE_MAKEFILE TRUE) + +include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake) +conan_basic_setup() + +add_executable(${PROJECT_NAME} test_package.cpp genqr.h genqr.c) +target_link_libraries(${PROJECT_NAME} ${CONAN_LIBS}) diff --git a/recipes/libqrencode/all/test_package/conanfile.py b/recipes/libqrencode/all/test_package/conanfile.py new file mode 100644 index 0000000000000..bd7165a553cf4 --- /dev/null +++ b/recipes/libqrencode/all/test_package/conanfile.py @@ -0,0 +1,17 @@ +from conans import ConanFile, CMake, tools +import os + + +class TestPackageConan(ConanFile): + settings = "os", "compiler", "build_type", "arch" + generators = "cmake" + + 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) diff --git a/recipes/libqrencode/all/test_package/genqr.c b/recipes/libqrencode/all/test_package/genqr.c new file mode 100644 index 0000000000000..9eafafa23ad5f --- /dev/null +++ b/recipes/libqrencode/all/test_package/genqr.c @@ -0,0 +1,265 @@ +#include +#include +#include +#include + +#include "png.h" +#include "qrencode.h" +#include "genqr.h" + +#define INCHES_PER_METER (100.0/2.54) + +enum imageType { + PNG_TYPE, + PNG32_TYPE, +}; + +static int casesensitive = 1; +static int eightbit = 0; +static int version = 0; +static int size = 10; +static int margin = 1; +static int dpi = 96; +static int structured = 0; +static int rle = 0; +static int svg_path = 0; +static int micro = 0; +static QRecLevel level = QR_ECLEVEL_L; +static QRencodeMode hint = QR_MODE_8; +static unsigned char fg_color[4] = { 0, 0, 0, 255 }; +static unsigned char bg_color[4] = { 255, 255, 255, 255 }; + +static int verbose = 0; +static void fillRow(unsigned char *row, int num, const unsigned char color[]) +{ + int i; + + for (i = 0; i < num; i++) { + memcpy(row, color, 4); + row += 4; + } +} + +static int writePNG(const QRcode *qrcode, const char *outfile, enum imageType type) +{ + static FILE *fp; // avoid clobbering by setjmp. + png_structp png_ptr; + png_infop info_ptr; + png_colorp palette = NULL; + png_byte alpha_values[2]; + unsigned char *row, *p, *q; + int x, y, xx, yy, bit; + int realwidth; + + realwidth = (qrcode->width + margin * 2) * size; + if (type == PNG_TYPE) { + row = (unsigned char *)malloc((realwidth + 7) / 8); + } + else if (type == PNG32_TYPE) { + row = (unsigned char *)malloc(realwidth * 4); + } + else { + fprintf(stderr, "Internal error.\n"); + return 1; + } + if (row == NULL) { + fprintf(stderr, "Failed to allocate memory.\n"); + return 1; + } + + if (outfile[0] == '-' && outfile[1] == '\0') { + fp = stdout; + } + else { + fp = fopen(outfile, "wb"); + if (fp == NULL) { + fprintf(stderr, "Failed to create file: %s\n", outfile); + perror(NULL); + return 1; + } + } + + png_ptr = png_create_write_struct(PNG_LIBPNG_VER_STRING, NULL, NULL, NULL); + if (png_ptr == NULL) { + fprintf(stderr, "Failed to initialize PNG writer.\n"); + return 1; + } + + info_ptr = png_create_info_struct(png_ptr); + if (info_ptr == NULL) { + fprintf(stderr, "Failed to initialize PNG write.\n"); + return 1; + } + + if (setjmp(png_jmpbuf(png_ptr))) { + png_destroy_write_struct(&png_ptr, &info_ptr); + fprintf(stderr, "Failed to write PNG image.\n"); + return 1; + } + + if (type == PNG_TYPE) { + palette = (png_colorp)malloc(sizeof(png_color) * 2); + if (palette == NULL) { + fprintf(stderr, "Failed to allocate memory.\n"); + return 1; + } + palette[0].red = fg_color[0]; + palette[0].green = fg_color[1]; + palette[0].blue = fg_color[2]; + palette[1].red = bg_color[0]; + palette[1].green = bg_color[1]; + palette[1].blue = bg_color[2]; + alpha_values[0] = fg_color[3]; + alpha_values[1] = bg_color[3]; + png_set_PLTE(png_ptr, info_ptr, palette, 2); + png_set_tRNS(png_ptr, info_ptr, alpha_values, 2, NULL); + } + + png_init_io(png_ptr, fp); + if (type == PNG_TYPE) { + png_set_IHDR(png_ptr, info_ptr, + realwidth, realwidth, + 1, + PNG_COLOR_TYPE_PALETTE, + PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, + PNG_FILTER_TYPE_DEFAULT); + } + else { + png_set_IHDR(png_ptr, info_ptr, + realwidth, realwidth, + 8, + PNG_COLOR_TYPE_RGB_ALPHA, + PNG_INTERLACE_NONE, + PNG_COMPRESSION_TYPE_DEFAULT, + PNG_FILTER_TYPE_DEFAULT); + } + png_set_pHYs(png_ptr, info_ptr, + dpi * INCHES_PER_METER, + dpi * INCHES_PER_METER, + PNG_RESOLUTION_METER); + png_write_info(png_ptr, info_ptr); + + if (type == PNG_TYPE) { + /* top margin */ + memset(row, 0xff, (realwidth + 7) / 8); + for (y = 0; y < margin * size; y++) { + png_write_row(png_ptr, row); + } + + /* data */ + p = qrcode->data; + for (y = 0; y < qrcode->width; y++) { + memset(row, 0xff, (realwidth + 7) / 8); + q = row; + q += margin * size / 8; + bit = 7 - (margin * size % 8); + for (x = 0; x < qrcode->width; x++) { + for (xx = 0; xx < size; xx++) { + *q ^= (*p & 1) << bit; + bit--; + if (bit < 0) { + q++; + bit = 7; + } + } + p++; + } + for (yy = 0; yy < size; yy++) { + png_write_row(png_ptr, row); + } + } + /* bottom margin */ + memset(row, 0xff, (realwidth + 7) / 8); + for (y = 0; y < margin * size; y++) { + png_write_row(png_ptr, row); + } + } + else { + /* top margin */ + fillRow(row, realwidth, bg_color); + for (y = 0; y < margin * size; y++) { + png_write_row(png_ptr, row); + } + + /* data */ + p = qrcode->data; + for (y = 0; y < qrcode->width; y++) { + fillRow(row, realwidth, bg_color); + for (x = 0; x < qrcode->width; x++) { + for (xx = 0; xx < size; xx++) { + if (*p & 1) { + memcpy(&row[((margin + x) * size + xx) * 4], fg_color, 4); + } + } + p++; + } + for (yy = 0; yy < size; yy++) { + png_write_row(png_ptr, row); + } + } + /* bottom margin */ + fillRow(row, realwidth, bg_color); + for (y = 0; y < margin * size; y++) { + png_write_row(png_ptr, row); + } + } + + png_write_end(png_ptr, info_ptr); + png_destroy_write_struct(&png_ptr, &info_ptr); + + fclose(fp); + free(row); + free(palette); + + return 0; +} + +static QRcode *encode(const char *intext) +{ + QRcode *code; + + code = QRcode_encodeString(intext, version, level, hint, casesensitive); + + return code; +} + + +static int qrencode(const char *intext, const char *outfile, enum imageType image_type) +{ + int result = 0; + QRcode *qrcode = encode(intext); + + if (qrcode == NULL) { + if (errno == ERANGE) { + fprintf(stderr, "Failed to encode the input data: Input data too large\n"); + } + else { + perror("Failed to encode the input data"); + } + return 1; + } + + if (verbose) { + fprintf(stderr, "File: %s, Version: %d\n", (outfile != NULL) ? outfile : "(stdout)", qrcode->version); + } + + switch (image_type) { + case PNG_TYPE: + case PNG32_TYPE: + result = writePNG(qrcode, outfile, image_type); + break; + default: + fprintf(stderr, "Unknown image type.\n"); + return 1; + } + + QRcode_free(qrcode); + + return result; +} + +int genqr(const char * intext, const char * outfile) +{ + return qrencode(intext, outfile, PNG_TYPE); +} diff --git a/recipes/libqrencode/all/test_package/genqr.h b/recipes/libqrencode/all/test_package/genqr.h new file mode 100644 index 0000000000000..5819fcb4ca10a --- /dev/null +++ b/recipes/libqrencode/all/test_package/genqr.h @@ -0,0 +1,8 @@ +#pragma once +#ifdef __cplusplus +extern "C" { +#endif +int genqr(const char* text, const char* file); +#ifdef __cplusplus +} +#endif diff --git a/recipes/libqrencode/all/test_package/test_package.cpp b/recipes/libqrencode/all/test_package/test_package.cpp new file mode 100644 index 0000000000000..0af80a648de57 --- /dev/null +++ b/recipes/libqrencode/all/test_package/test_package.cpp @@ -0,0 +1,10 @@ +#include +#include + +#include "genqr.h" + +int main() +{ + std::cout << "Generating QR code for the 'dummy.png' text and store to the dummy.png file\n"; + return genqr("dummy.png", "dummy.png"); +} diff --git a/recipes/libqrencode/config.yml b/recipes/libqrencode/config.yml new file mode 100644 index 0000000000000..d2be8f453d7c0 --- /dev/null +++ b/recipes/libqrencode/config.yml @@ -0,0 +1,3 @@ +versions: + "4.0.0": + folder: all From 3a9ee314911ca1b7373b10b911e22917cefe53d5 Mon Sep 17 00:00:00 2001 From: Anonymous Maarten Date: Thu, 13 Feb 2020 20:10:03 +0100 Subject: [PATCH 2/2] libqrencode: fix license Co-Authored-By: Uilian Ries --- recipes/libqrencode/all/conanfile.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/recipes/libqrencode/all/conanfile.py b/recipes/libqrencode/all/conanfile.py index 91f34fcdd2403..650db135348f3 100644 --- a/recipes/libqrencode/all/conanfile.py +++ b/recipes/libqrencode/all/conanfile.py @@ -7,7 +7,7 @@ class LibqrencodeConan(ConanFile): description = "A fast and compact QR Code encoding library" url = "https://github.com/conan-io/conan-center-index" homepage = "https://github.com/fukuchi/libqrencode" - license = ("LGPL-2.1, LGPL-3.0") + license = ("LGPL-2.1-or-later") exports_sources = "CMakeLists.txt", "patches/**" generators = "cmake", "cmake_find_package" settings = "os", "arch", "compiler", "build_type"