Add libc option to zlib and zstd

This commit is contained in:
Sameer Rahmani 2023-04-14 18:26:58 +01:00
parent 37e75b9f09
commit 68701215bb
Signed by: lxsameer
GPG Key ID: B0A4AF28AB9FD90B
6 changed files with 40 additions and 7 deletions

View File

@ -78,3 +78,11 @@ def with_static_flags(cmake_vars):
"CMAKE_EXE_LINKER_FLAGS_INIT"
] = f"-static {cmake_vars.get('CMAKE_EXE_LINKER_FLAGS_INIT', '')}"
return cmake_vars
def with_musl_toolchain(conanfile, tc):
if conanfile.options.libc == "musl":
target = os.environ["TARGET"]
tc.variables["CMAKE_C_COMPILER_TARGET"] = target
tc.variables["CMAKE_CXX_COMPILER_TARGET"] = target

View File

@ -19,7 +19,7 @@ from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get, copy
from conf.utils import get_version
from conf.utils import get_version, with_musl_toolchain
class Zlib(ConanFile):
@ -29,10 +29,23 @@ class Zlib(ConanFile):
exports = "*.cmake"
cmake_setup_file = "zlib_setup.cmake"
options = {
"libc": ["gnu", "musl"],
}
default_options = {"libc": "gnu"}
def build_requirements(self):
self.tool_requires(f"cmake/{get_version('cmake')}@{self.user}/{self.channel}")
self.tool_requires(f"ninja/{get_version('ninja')}@{self.user}/{self.channel}")
if self.options.libc == "musl":
self.tool_requires(
f"clang-bootstrap/{get_version('llvm')}@{self.user}/{self.channel}"
)
self.requires(f"musl/{get_version('musl')}@{self.user}/{self.channel}")
def source(self):
get(
self,
@ -42,6 +55,7 @@ class Zlib(ConanFile):
def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_SHARED_LIBS"] = False
with_musl_toolchain(self, tc)
tc.generate()
deps = CMakeDeps(self)
deps.generate()
@ -55,9 +69,7 @@ class Zlib(ConanFile):
},
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"))

View File

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

View File

@ -19,7 +19,7 @@ from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, CMakeDeps
from conan.tools.files import get, copy
from conf.utils import get_version
from conf.utils import get_version, with_musl_toolchain
class Zstd(ConanFile):
@ -28,6 +28,12 @@ class Zstd(ConanFile):
settings = "os", "arch", "build_type", "compiler"
exports = "*.cmake"
options = {
"libc": ["gnu", "musl"],
}
default_options = {"libc": "gnu"}
def build_requirements(self):
self.tool_requires(f"cmake/{get_version('cmake')}@{self.user}/{self.channel}")
self.tool_requires(f"ninja/{get_version('ninja')}@{self.user}/{self.channel}")
@ -41,6 +47,8 @@ class Zstd(ConanFile):
def generate(self):
tc = CMakeToolchain(self)
tc.variables["BUILD_SHARED_LIBS"] = False
with_musl_toolchain(self, tc)
tc.generate()
deps = CMakeDeps(self)
deps.generate()

View File

@ -9,6 +9,9 @@ compiler=gcc
compiler.version=12.2
compiler.libcxx=libstdc++
[options]
*/*:libc = gnu
[buildenv]
LD=lld

View File

@ -13,14 +13,17 @@ clang-bootstrap/*:compiler=gcc
clang-bootstrap/*:compiler.version=12.2
clang-bootstrap/*:compiler.libcxx=libstdc++
[options]
zlib/*:libc = musl
# [tool_requires]
# musl/*:clang-bootstrap/{{ LLVM_VERSION }}@serene/stable
# zlib/*:clang-bootstrap/{{ LLVM_VERSION }}@serene/stable
[buildenv]
CC=clang
CXX=clang++
LD=lld
[runenv]
STAGE="1"
[conf]
tools.cmake.cmaketoolchain:generator=Ninja