Skip to content
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

Merged
merged 3 commits into from
Jan 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 33 additions & 0 deletions recipes/lzham/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
sources:
"cci.20220103":
sha256: "3e3ccf7a57b1e6a90099784597aa7da30de3249a5f7fe532cefb3a77db5acbfb"
url: "https://github.com/richgel999/lzham_codec/archive/d379b1f9121e2197881c61cfc4713c78848bdfe7.zip"
patches:
"cci.20220103":
- patch_file: "patches/aarch64-yield-cci.20220103.patch"
patch_description: 'Uses "yield" rather than "pause" mneumonic to fix
aarch64 build'
patch_type: portability

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

- patch_file: "patches/fix-osx-cci.20220103.patch"
patch_description: "Fixes building on OSX"
patch_type: portability

- patch_file: "patches/use-lzham-types-cci.20220103.patch"
patch_description: 'Uses typedefs prefixed with LZHAM to fix linux build
errors'
patch_type: portability

- patch_file: "patches/cmake-rm-tests-cci.20220103.patch"
patch_description: "Skips building of lzhamtest for CMake"
patch_type: conan

- patch_file: "patches/msvc-conan-cci.20220103.patch"
patch_description: 'Skips building of lzhamtest and examples for MSVC,
and injects conan toolchain for MSVC'
patch_type: conan
158 changes: 158 additions & 0 deletions recipes/lzham/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
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,
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 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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The 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

cl : command line  error D8021: invalid numeric argument '/Wextra' [C:\Users\Babbo\.conan\data\lzham\1.0.0\_\_\build\5a
61a86bb3e07ce4262c80e1510f9c05e9b6d48b\build\lzhamdecomp\lzhamdecomp.vcxproj]

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)

# Honor BUILD_SHARED_LIBS from conan_toolchain (see
# https://github.com/conan-io/conan/issues/11840)
tc.cache_variables["CMAKE_POLICY_DEFAULT_CMP0077"] = "NEW"
tc.generate()

def build(self):
apply_conandata_patches(self)
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"
16 changes: 16 additions & 0 deletions recipes/lzham/all/patches/aarch64-yield-cci.20220103.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-cci.20220103.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}")
12 changes: 12 additions & 0 deletions recipes/lzham/all/patches/cmake-rm-tests-cci.20220103.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 428cdfc..1857db2 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -6,7 +6,6 @@ option(BUILD_SHARED_LIBS "build shared/static libs" ON)
add_subdirectory(lzhamdecomp)
add_subdirectory(lzhamcomp)
add_subdirectory(lzhamdll)
-add_subdirectory(lzhamtest)

install(FILES include/lzham_dynamic_lib.h
include/lzham_exports.inc
28 changes: 28 additions & 0 deletions recipes/lzham/all/patches/fix-osx-cci.20220103.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
diff --git a/lzhamdecomp/lzham_platform.cpp b/lzhamdecomp/lzham_platform.cpp
index cfc85c1..599a847 100644
--- a/lzhamdecomp/lzham_platform.cpp
+++ b/lzhamdecomp/lzham_platform.cpp
@@ -61,7 +61,7 @@ void lzham_debug_break(void)
{
#if LZHAM_USE_WIN32_API
DebugBreak();
-#elif (TARGET_OS_MAC == 1) && (TARGET_IPHONE_SIMULATOR == 0) && (TARGET_OS_IPHONE == 0)
+#elif (TARGET_OS_MAC == 1) && (TARGET_IPHONE_SIMULATOR == 0) && (TARGET_OS_IPHONE == 0) && !defined(__clang__)
__asm {int 3}
#else
assert(0);
diff --git a/lzhamdecomp/lzham_traits.h b/lzhamdecomp/lzham_traits.h
index ea7214f..e103bad 100644
--- a/lzhamdecomp/lzham_traits.h
+++ b/lzhamdecomp/lzham_traits.h
@@ -67,7 +67,9 @@ namespace lzham
// Defines type Q as bitwise copyable.
#define LZHAM_DEFINE_BITWISE_COPYABLE(Q) template<> struct bitwise_copyable<Q> { enum { cFlag = true }; };

-#if defined(__APPLE__) || defined(__NetBSD__)
+#if defined(__APPLE__)
+ #define LZHAM_IS_POD(T) std::is_pod<T>::value
+#elif defined(__NetBSD__)
#define LZHAM_IS_POD(T) std::__is_pod<T>::__value
#else
#define LZHAM_IS_POD(T) __is_pod(T)
83 changes: 83 additions & 0 deletions recipes/lzham/all/patches/msvc-conan-cci.20220103.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
diff --git a/lzham.sln b/lzham.sln
index 5c0edb6..63343f3 100644
--- a/lzham.sln
+++ b/lzham.sln
@@ -3,22 +3,12 @@ Microsoft Visual Studio Solution File, Format Version 11.00
# Visual Studio 2010
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lzhamdll", "lzhamdll\lzham.vcxproj", "{763BE79D-1280-41B7-81C5-7DC41E2BDB44}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lzhamtest", "lzhamtest\lzhamtest.vcxproj", "{BBE16587-150E-460C-8AB4-F18B92D0B981}"
-EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lzhamdecomp", "lzhamdecomp\lzhamdecomp.vcxproj", "{8DA0CD32-701D-48D7-AE92-728338501500}"
EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lzhamcomp", "lzhamcomp\lzhamcomp.vcxproj", "{8DA0CD46-791D-48D7-AE92-728338501500}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example1", "example1\example1.vcxproj", "{BBE16587-150E-460C-8AB4-E18B92D0B982}"
-EndProject
Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "lzhamlib", "lzhamlib\lzhamlib.vcxproj", "{83A2F0B5-1D02-4A13-B579-714F60E31774}"
EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example2", "example2\example2.vcxproj", "{CBE16587-150E-460C-8AB4-E18B92D0B983}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example3", "example3\example3.vcxproj", "{1BE16587-150E-460C-8AB4-E18B92D0BA87}"
-EndProject
-Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "example4", "example4\example4.vcxproj", "{1BE16587-260E-460C-8AB4-E18B92D0BA87}"
-EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Win32 = Debug|Win32
diff --git a/lzhamcomp/lzhamcomp.vcxproj b/lzhamcomp/lzhamcomp.vcxproj
index 5fd6155..b45f3dc 100644
--- a/lzhamcomp/lzhamcomp.vcxproj
+++ b/lzhamcomp/lzhamcomp.vcxproj
@@ -23,6 +23,9 @@
<RootNamespace>lzhamcomp</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
+ <ImportGroup Label="PropertySheets">
+ <Import Project="..\conan\conantoolchain.props" />
+ </ImportGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
diff --git a/lzhamdecomp/lzhamdecomp.vcxproj b/lzhamdecomp/lzhamdecomp.vcxproj
index dbaf54c..5f78ca5 100644
--- a/lzhamdecomp/lzhamdecomp.vcxproj
+++ b/lzhamdecomp/lzhamdecomp.vcxproj
@@ -23,6 +23,9 @@
<RootNamespace>lzhamdecomp</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
+ <ImportGroup Label="PropertySheets">
+ <Import Project="..\conan\conantoolchain.props" />
+ </ImportGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
diff --git a/lzhamdll/lzham.vcxproj b/lzhamdll/lzham.vcxproj
index ec0a280..5536234 100644
--- a/lzhamdll/lzham.vcxproj
+++ b/lzhamdll/lzham.vcxproj
@@ -24,6 +24,9 @@
<RootNamespace>lzham</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
+ <ImportGroup Label="PropertySheets">
+ <Import Project="..\conan\conantoolchain.props" />
+ </ImportGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>DynamicLibrary</ConfigurationType>
diff --git a/lzhamlib/lzhamlib.vcxproj b/lzhamlib/lzhamlib.vcxproj
index 954dd99..cdd2c26 100644
--- a/lzhamlib/lzhamlib.vcxproj
+++ b/lzhamlib/lzhamlib.vcxproj
@@ -23,6 +23,9 @@
<RootNamespace>lzhamlib</RootNamespace>
<Keyword>Win32Proj</Keyword>
</PropertyGroup>
+ <ImportGroup Label="PropertySheets">
+ <Import Project="..\conan\conantoolchain.props" />
+ </ImportGroup>
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.Default.props" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'" Label="Configuration">
<ConfigurationType>StaticLibrary</ConfigurationType>
Loading