Skip to content

Commit

Permalink
lzham: Add 1.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
partiallyderived committed Nov 30, 2022
1 parent 3f85925 commit 1177828
Show file tree
Hide file tree
Showing 13 changed files with 1,652 additions and 0 deletions.
29 changes: 29 additions & 0 deletions recipes/lzham/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
sources:
"1.0.0":
sha256: "4f4f874706763b3a6e3d6dfff666a1e850ca1d92fd9240b2a14365c5864a0057"
url: "https://github.com/richgel999/lzham_codec/archive/refs/tags/v1_0_stable1.tar.gz"
patches:
"1.0.0":
- patch_file: "patches/commits-1.0.0.patch"
patch_description: 'Updates code to latest commit for the repo
https://github.com/richgel999/lzham_codec'
patch_type: backport

- patch_file: "patches/aarch64-yield-1.0.0.patch"
patch_description: 'Uses "yield" rather than "pause" mneumonic to fix
aarch64 build'
patch_type: backport

- patch_file: "patches/cmake-min-req-swap-1.0.0.patch"
patch_description: 'Puts cmake_minimum_required before project in all
CMakeLists'
patch_type: backport

- patch_file: "patches/fix-osx-1.0.0.patch"
patch_description: "Fixes building on OSX"
patch_type: backport

- patch_file: "patches/use-lzham-types-1.0.0.patch"
patch_description: 'Uses typedefs prefixed with LZHAM to fix linux build
errors'
patch_type: backport
212 changes: 212 additions & 0 deletions recipes/lzham/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
import os

from conan import ConanFile
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import (
apply_conandata_patches,
copy,
export_conandata_patches,
get,
replace_in_file,
rmdir
)
from conan.tools.microsoft import (
MSBuild, MSBuildDeps, MSBuildToolchain, VCVars, is_msvc, vs_layout
)

required_conan_version = ">=1.52.0"

SLN_FILE = "lzham.sln"


class PackageConan(ConanFile):
name = "lzham"

description = (
"Compression algorithm similar compression ratio and faster "
"decompression than LZMA."
)

license = "LicenseRef-LICENSE"
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://github.com/richgel999/lzham_codec"
topics = ("compression", "lz-compression")
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
}

def _patch_sources(self):
apply_conandata_patches(self)

if not is_msvc(self):
# Remove lzhamtest from root CMakeLists.txt.
replace_in_file(
self,
os.path.join(self.source_folder, "CMakeLists.txt"),
"add_subdirectory(lzhamtest)\n",
""
)
return
new_sln = []
# Remove example and test projects from sln.
with open(os.path.join(
self.source_folder, "lzham.sln"
), encoding="utf-8") as f:
line = f.readline()
while line:
if (
line.startswith("Project(")
and ("lzhamtest" in line or "example" in line)
):
# Don't write the current line and skip the "EndProject"
# line.
f.readline()
else:
new_sln.append(line)
line = f.readline()
with open(os.path.join(
self.source_folder, "lzham.sln"
), "w", encoding="utf-8") as f:
f.write("".join(new_sln))

# Inject conantoolchain.props so that correct platform toolset is used.
projects = [(x, f"{x}.vcxproj") for x in (
"lzhamcomp",
"lzhamdecomp",
"lzhamlib",
)]
projects.append(("lzhamdll", "lzham.vcxproj"))
search_str = (
' <Import Project='
'"$(VCTargetsPath)\\Microsoft.Cpp.Default.props" />'
)

for p in projects:
replace_in_file(
self,
os.path.join(self.source_folder, *p),
search_str,
' <ImportGroup Label="PropertySheets">\n'
' <Import Project="..\\conan\\conantoolchain.props" />\n'
' </ImportGroup>\n'
+ search_str
)

def export_sources(self):
export_conandata_patches(self)

def config_options(self):
if self.settings.os == "Windows":
del self.options.fPIC

def configure(self):
if self.options.shared:
self.options.rm_safe("fPIC")

def layout(self):
if is_msvc(self):
vs_layout(self)
else:
cmake_layout(self, src_folder="src")

def source(self):
get(
self,
**self.conan_data["sources"][self.version],
destination=self.source_folder,
strip_root=True
)

def generate(self):
if is_msvc(self):
tc = MSBuildToolchain(self)
tc.generate()
tc = MSBuildDeps(self)
tc.generate()
tc = VCVars(self)
tc.generate()
else:
tc = CMakeToolchain(self)
tc.generate()

def build(self):
self._patch_sources()
if is_msvc(self):
msbuild = MSBuild(self)
msbuild.build_type = (
"Debug" if self.settings.build_type == "Debug" else "Release"
)
msbuild.platform = (
"Win32" if self.settings.arch == "x86" else msbuild.platform
)
msbuild.build(sln="lzham.sln")
else:
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
copy(
self,
pattern="LICENSE",
dst=os.path.join(self.package_folder, "licenses"),
src=self.source_folder
)

if is_msvc(self):
suffix = "x64D" if self.settings.build_type == "Debug" else "x64"
copy(
self,
pattern=f"lzham_{suffix}.lib",
dst=os.path.join(self.package_folder, "lib"),
src=os.path.join(self.build_folder, "lib", "x64"),
keep_path=False
)
copy(
self,
pattern=f"lzham_{suffix}.dll",
dst=os.path.join(self.package_folder, "bin"),
src=os.path.join(self.build_folder, "bin"),
keep_path=False
)
copy(
self,
pattern="*.h",
dst=os.path.join(self.package_folder, "include"),
src=os.path.join(self.source_folder, "include"),
)
else:
cmake = CMake(self)
cmake.install()

rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
rmdir(self, os.path.join(self.package_folder, "res"))
rmdir(self, os.path.join(self.package_folder, "share"))

def package_info(self):
if self.settings.os in ["Linux", "FreeBSD"]:
self.cpp_info.system_libs.extend(["m", "pthread"])

if is_msvc(self):
lib_name = "lzham_x64"
if self.settings.build_type == "Debug":
lib_name += "D"
self.cpp_info.libs = [lib_name]
else:
self.cpp_info.libs = ["lzhamdll"]
self.cpp_info.set_property("cmake_file_name", "lzham")
self.cpp_info.set_property("cmake_target_name", "lzham::lzham")
self.cpp_info.set_property("pkg_config_name", "lzham")

# TODO: to remove in conan v2 once cmake_find_package_* generators
# removed
self.cpp_info.names["cmake_find_package"] = "lzham"
self.cpp_info.names["cmake_find_package_multi"] = "lzham"
self.cpp_info.names["pkg_config"] = "lzham"
16 changes: 16 additions & 0 deletions recipes/lzham/all/patches/aarch64-yield-1.0.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
diff --git a/lzhamdecomp/lzham_platform.h b/lzhamdecomp/lzham_platform.h
index 01704be..920a8f4 100644
--- a/lzhamdecomp/lzham_platform.h
+++ b/lzhamdecomp/lzham_platform.h
@@ -24,7 +24,11 @@ void lzham_fail(const char* pExp, const char* pFile, unsigned line);
#if defined(__GNUC__) && LZHAM_PLATFORM_PC
extern __inline__ __attribute__((__always_inline__,__gnu_inline__)) void lzham_yield_processor()
{
+ #if defined(__aarch64__)
+ __asm__ __volatile__("yield");
+ #else
__asm__ __volatile__("pause");
+ #endif
}
#elif LZHAM_PLATFORM_X360
#define lzham_yield_processor() \
55 changes: 55 additions & 0 deletions recipes/lzham/all/patches/cmake-min-req-swap-1.0.0.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 428cdfc..b8980e5 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,5 +1,5 @@
-# PROJECT(lzham)
cmake_minimum_required(VERSION 2.8)
+PROJECT(lzham)
option(BUILD_X64 "build 64-bit" ON)
option(BUILD_SHARED_LIBS "build shared/static libs" ON)

diff --git a/lzhamcomp/CMakeLists.txt b/lzhamcomp/CMakeLists.txt
index c80cc66..a3f77e7 100644
--- a/lzhamcomp/CMakeLists.txt
+++ b/lzhamcomp/CMakeLists.txt
@@ -1,5 +1,5 @@
-PROJECT(lzhamcomp)
cmake_minimum_required(VERSION 2.8)
+PROJECT(lzhamcomp)
option(BUILD_X64 "build 64-bit" TRUE)

message("Initial BUILD_X64=${BUILD_X64}")
diff --git a/lzhamdecomp/CMakeLists.txt b/lzhamdecomp/CMakeLists.txt
index bf87a02..723379e 100644
--- a/lzhamdecomp/CMakeLists.txt
+++ b/lzhamdecomp/CMakeLists.txt
@@ -1,5 +1,5 @@
-PROJECT(lzhamdecomp)
cmake_minimum_required(VERSION 2.8)
+PROJECT(lzhamdecomp)
option(BUILD_X64 "build 64-bit" TRUE)

message("Initial BUILD_X64=${BUILD_X64}")
diff --git a/lzhamdll/CMakeLists.txt b/lzhamdll/CMakeLists.txt
index f77f3fe..5a162b6 100644
--- a/lzhamdll/CMakeLists.txt
+++ b/lzhamdll/CMakeLists.txt
@@ -1,5 +1,5 @@
-PROJECT(lzhamdll)
cmake_minimum_required(VERSION 2.8)
+PROJECT(lzhamdll)
option(BUILD_X64 "build 64-bit" TRUE)

message("Initial BUILD_X64=${BUILD_X64}")
diff --git a/lzhamtest/CMakeLists.txt b/lzhamtest/CMakeLists.txt
index 3349911..b8833b9 100644
--- a/lzhamtest/CMakeLists.txt
+++ b/lzhamtest/CMakeLists.txt
@@ -1,5 +1,5 @@
-PROJECT(lzhamtest)
cmake_minimum_required(VERSION 2.8)
+PROJECT(lzhamtest)
option(BUILD_X64 "build 64-bit" TRUE)

message("Initial BUILD_X64=${BUILD_X64}")
Loading

0 comments on commit 1177828

Please sign in to comment.