-
Notifications
You must be signed in to change notification settings - Fork 1.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
lzham: Add cci.20220103 #13646
lzham: Add cci.20220103 #13646
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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: official | ||
|
||
- patch_file: "patches/aarch64-yield-1.0.0.patch" | ||
patch_description: 'Uses "yield" rather than "pause" mneumonic to fix | ||
aarch64 build' | ||
patch_type: portability | ||
|
||
- patch_file: "patches/cmake-min-req-swap-1.0.0.patch" | ||
patch_description: 'Puts cmake_minimum_required before project in all | ||
CMakeLists' | ||
patch_type: portability | ||
|
||
- patch_file: "patches/fix-osx-1.0.0.patch" | ||
patch_description: "Fixes building on OSX" | ||
patch_type: portability | ||
|
||
- patch_file: "patches/use-lzham-types-1.0.0.patch" | ||
patch_description: 'Uses typedefs prefixed with LZHAM to fix linux build | ||
errors' | ||
patch_type: portability |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,221 @@ | ||
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. | ||
partiallyderived marked this conversation as resolved.
Show resolved
Hide resolved
|
||
replace_in_file( | ||
self, | ||
os.path.join(self.source_folder, "CMakeLists.txt"), | ||
"add_subdirectory(lzhamtest)\n", | ||
"" | ||
) | ||
|
||
# This line in the root CMakeLists.txt can cause issues, see | ||
# https://cmake.org/cmake/help/latest/policy/CMP0077.html. | ||
replace_in_file( | ||
self, | ||
os.path.join(self.source_folder, "CMakeLists.txt"), | ||
"option(BUILD_SHARED_LIBS \"build shared/static libs\" ON)", | ||
"" | ||
) | ||
partiallyderived marked this conversation as resolved.
Show resolved
Hide resolved
|
||
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) | ||
Comment on lines
+68
to
+70
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why not build all platform with CMake? https://github.com/richgel999/lzham_codec/blob/master/CMakeLists.txt There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thanks for the review! Part of the reason is that the CMakeLists configure compiler arguments that MSVC does not understand, leading to errors like
Another reason is that I suspect that the MSVC project is "fine-tuned" for Windows and it is the recommended way to compile for Windows, so I believe it would be less optimal to make a patch adapt the CMakeLists so that MSVC is handled, not to mention a bit of a pain! |
||
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", "lzhamcomp", "lzhamdecomp"] | ||
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" |
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() \ |
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}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oof, this is going to be a very tough sell 🙊
Thats a massive patch....
Couple suggestions for you to get this to move forward
The other options is we do have "unofficial releases" https://github.com/conan-io/conan-center-index/blob/master/docs/faqs.md#what-version-should-packages-use-for-libraries-without-official-releases and that would be something you could add in addition to the official one
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The first option is ideal and I've made an issue for it. Unfortunately the maintainers are pretty unresponsive so I doubt it will come to pass haha. I think the second option doesn't apply as this code is already part of the upstream, though maybe I misunderstood. I made pull requests for my other patches where they did not already exist.
I think it is likely that I will go for the "unofficial releases" option
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also, is it acceptable if I supported only the unofficial release? I ask because it contains many portability fixes, and the official would basically have to be patched to include the fixes anyway if I include it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it makes sense in this case given how much differences there are