Skip to content

Commit

Permalink
(#18826) zstd/*: Added "build_programs" option
Browse files Browse the repository at this point in the history
* zstd: Added "build_programs" option to allow client to decide whether to build executables or not

* validate zstd lib in test package

Signed-off-by: Uilian Ries <uilianries@gmail.com>

* Updated test package to use build_env instead of run_env to run the newly built ztsd executable

* Update recipes/zstd/all/conanfile.py

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* Added qnx support in platform.h

* Implemented better way to run binaries from the package in the test() method

* Update recipes/zstd/all/conandata.yml

Co-authored-by: Uilian Ries <uilianries@gmail.com>

* zstd: Fixed spelling error in conandata.yml

---------

Signed-off-by: Uilian Ries <uilianries@gmail.com>
Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
klausholstjacobsen and uilianries authored Oct 18, 2023
1 parent 0b17150 commit 8e2022d
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 9 deletions.
4 changes: 4 additions & 0 deletions recipes/zstd/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,10 @@ patches:
- patch_file: "patches/1.5.2-cmake-remove-asm-except-x86_64.patch"
patch_description: "use assembler codes only on x86_64"
patch_type: "portability"
- patch_file: "patches/1.5.5-qnx_support.patch"
patch_description: "Add qnx to platform"
patch_type: "portability"
patch_source: "https://github.com/facebook/zstd/pull/3745"
"1.5.4":
- patch_file: "patches/1.5.2-cmake-remove-asm-except-x86_64.patch"
patch_description: "use assembler codes only on x86_64"
Expand Down
25 changes: 21 additions & 4 deletions recipes/zstd/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import apply_conandata_patches, collect_libs, copy, export_conandata_patches, get, replace_in_file, rmdir
from conan.tools.files import apply_conandata_patches, collect_libs, copy, export_conandata_patches, get, replace_in_file, rmdir, rm
from conan.tools.scm import Version
from conan.tools.microsoft import is_msvc
import os

required_conan_version = ">=1.53.0"


class ZstdConan(ConanFile):
name = "zstd"
url = "https://github.com/conan-io/conan-center-index"
Expand All @@ -21,11 +21,13 @@ class ZstdConan(ConanFile):
"shared": [True, False],
"fPIC": [True, False],
"threading": [True, False],
"build_programs": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"threading": True,
"build_programs": True,
}

def export_sources(self):
Expand All @@ -49,10 +51,14 @@ def source(self):

def generate(self):
tc = CMakeToolchain(self)
tc.variables["ZSTD_BUILD_PROGRAMS"] = False
tc.variables["ZSTD_BUILD_STATIC"] = not self.options.shared
tc.variables["ZSTD_BUILD_PROGRAMS"] = self.options.build_programs
tc.variables["ZSTD_BUILD_STATIC"] = not self.options.shared or self.options.build_programs
tc.variables["ZSTD_BUILD_SHARED"] = self.options.shared
tc.variables["ZSTD_MULTITHREAD_SUPPORT"] = self.options.threading

if not is_msvc(self):
tc.variables["CMAKE_C_FLAGS"] = "-Wno-maybe-uninitialized"

if Version(self.version) < "1.4.3":
# Generate a relocatable shared lib on Macos
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0042"] = "NEW"
Expand All @@ -77,6 +83,12 @@ def package(self):
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))

if self.options.shared and self.options.build_programs:
#If we built programs we always build static libs,
#but if we only want shared libs in the package then remove the static libs
rm(self, "*.a", os.path.join(self.package_folder, "lib"))

def package_info(self):
zstd_cmake = "libzstd_shared" if self.options.shared else "libzstd_static"
Expand All @@ -90,3 +102,8 @@ def package_info(self):
self.cpp_info.components["zstdlib"].libs = collect_libs(self)
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.components["zstdlib"].system_libs.append("pthread")

if self.options.build_programs:
# TODO: Remove after dropping Conan 1.x from ConanCenterIndex
bindir = os.path.join(self.package_folder, "bin")
self.env_info.PATH.append(bindir)
11 changes: 11 additions & 0 deletions recipes/zstd/all/patches/1.5.5-qnx_support.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
--- programs/platform.h 2023-04-04 22:13:52.000000000 +0200
+++ programs/platform.h 2023-09-03 10:01:58.930595800 +0200
@@ -89,7 +89,7 @@
*/
# elif !defined(_WIN32) \
&& ( defined(__unix__) || defined(__unix) \
- || defined(__midipix__) || defined(__VMS) || defined(__HAIKU__) )
+ || defined(_QNX_SOURCE) || defined(__midipix__) || defined(__VMS) || defined(__HAIKU__) )

# if defined(__linux__) || defined(__linux) || defined(__CYGWIN__)
# ifndef _POSIX_C_SOURCE
14 changes: 9 additions & 5 deletions recipes/zstd/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,19 @@ def layout(self):
cmake_layout(self)

def requirements(self):
self.requires(self.tested_reference_str)
self.requires(self.tested_reference_str, run=True)

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.bindirs[0], "test_package")
png_file = os.path.join(self.source_folder, "logo.png")
self.run(f"{bin_path} {png_file}", env="conanrun")
if not can_run(self):
return

bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
png_file = os.path.join(self.source_folder, "logo.png")
self.run(f"{bin_path} {png_file}", env="conanrun")

self.run(f"zstd --version", env="conanrun")

0 comments on commit 8e2022d

Please sign in to comment.