[DO-984] add-zlib-recipe (!4)

Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/4
This commit is contained in:
Aleksandr Vodyanov
2024-11-22 17:15:46 +03:00
parent e3106d807c
commit 4bbce79e03
15 changed files with 743 additions and 0 deletions

View File

@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)
find_package(ZLIB REQUIRED)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE ZLIB::ZLIB)

View File

@@ -0,0 +1,27 @@
from conan import ConanFile
from conan.tools.build import can_run, cross_building
from conan.tools.cmake import CMake, cmake_layout
import os
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires(self.tested_reference_str)
def build(self):
if not cross_building(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
if can_run(self) and not cross_building(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")

View File

@@ -0,0 +1,32 @@
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <zlib.h>
int main(void) {
char buffer_in [32] = {"Conan Package Manager"};
char buffer_out [32] = {0};
z_stream defstream;
defstream.zalloc = Z_NULL;
defstream.zfree = Z_NULL;
defstream.opaque = Z_NULL;
defstream.avail_in = (uInt) strlen(buffer_in);
defstream.next_in = (Bytef *) buffer_in;
defstream.avail_out = (uInt) sizeof(buffer_out);
defstream.next_out = (Bytef *) buffer_out;
deflateInit(&defstream, Z_BEST_COMPRESSION);
deflate(&defstream, Z_FINISH);
deflateEnd(&defstream);
printf("Compressed size is: %lu\n", strlen(buffer_in));
printf("Compressed string is: %s\n", buffer_in);
printf("Compressed size is: %lu\n", strlen(buffer_out));
printf("Compressed string is: %s\n", buffer_out);
printf("ZLIB VERSION: %s\n", zlibVersion());
return EXIT_SUCCESS;
}