Add the zlib package

This commit is contained in:
Sameer Rahmani 2023-04-07 11:08:47 +01:00
parent 5330b6ec00
commit a25529ed05
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
2 changed files with 94 additions and 0 deletions

View File

@ -0,0 +1,92 @@
# Toolchain builder for the Serene programming language
#
# Copyright (c) 2019-2023 Sameer Rahmani <lxsameer@gnu.org>
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import os
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get, copy
from conf.versions import *
class Zlib(ConanFile):
name = "zlib"
version = ZLIB_VERSION
settings = "os", "arch", "build_type", "compiler"
exports = "*.cmake"
cmake_setup_file = "zlib_setup.cmake"
def requirements(self):
self.tool_requires(f"cmake/{CMAKE_VERSION}@{self.user}/{self.channel}")
self.tool_requires(f"ninja/{NINJA_VERSION}@{self.user}/{self.channel}")
def source(self):
get(
self,
f"https://github.com/madler/zlib/archive/v{self.version}.tar.gz",
)
def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_SHARED_LIBS"] = False
tc.generate()
deps = CMakeDeps(self)
deps.generate()
def build(self):
cmake = CMake(self)
cmake.configure(
{
"BUILD_SHARED_LIBS": False,
"CMAKE_POSITION_INDEPENDENT_CODE": "ON",
},
build_script_folder=f"zlib-{self.version}",
)
# cmake.build()
self.run("ninja zlibstatic")
# cmake.install()
def package(self):
copy(self, "*.a", self.build_folder, os.path.join(self.package_folder, "lib"))
copy(self, self.cmake_setup_file, self.recipe_folder, self.package_folder)
copy(
self,
"zconf.h",
self.build_folder,
os.path.join(self.package_folder, "include"),
)
copy(
self,
"zlib.h",
os.path.join(self.build_folder, f"zlib-{self.version}"),
os.path.join(self.package_folder, "include"),
)
copy(
self,
"zlib.pc",
self.build_folder,
os.path.join(self.package_folder, "share", "pkgconfig"),
)
def package_info(self):
self.cpp_info.set_property("cmake_build_modules", [self.cmake_setup_file])
self.cpp_info.set_property("cmake_find_mode", "module")
self.cpp_info.set_property("cmake_file_name", "ZLIB")
self.cpp_info.set_property("cmake_target_name", "ZLIB::ZLIB")
self.cpp_info.set_property("pkg_config_name", "zlib")
self.cpp_info.libs = ["z"]
self.cpp_info.set_property("cmake_find_package", "ZLIB")
self.cpp_info.set_property("cmake_find_package_multi", "ZLIB")

View File

@ -0,0 +1,2 @@
message(STATUS "AAAA ${zlib_INCLUDE_DIRS_RELEASE} -- ${CMAKE_FIND_LIBRARY_SUFFIXES}")
set_target_properties(ZLIB::ZLIB PROPERTIES LOCATION ${zlib_LIB_DIRS_RELEASE}/libz.a)