Skip to content

Commit

Permalink
libaec: add v1.1.2, modernize, add compnents, simplify patching
Browse files Browse the repository at this point in the history
  • Loading branch information
valgur committed Dec 27, 2023
1 parent be77f29 commit 6a76abc
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 347 deletions.
25 changes: 5 additions & 20 deletions recipes/libaec/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
sources:
"1.1.2":
url: "https://gitlab.dkrz.de/k202009/libaec/-/archive/v1.1.2/libaec-v1.1.2.tar.bz2"
sha256: "bdad8c7923537c3695327aa85afdcd714fb3d30a5f956a27ba2971ef98c043ac"
"1.0.6":
url: "https://gitlab.dkrz.de/k202009/libaec/uploads/45b10e42123edd26ab7b3ad92bcf7be2/libaec-1.0.6.tar.gz"
sha256: "032961877231113bb094ef224085e6d66fd670f85a3e17f53d0f131abf24f2fd"
"1.0.4":
url: "https://gitlab.dkrz.de/k202009/libaec/uploads/ea0b7d197a950b0c110da8dfdecbb71f/libaec-1.0.4.tar.gz"
sha256: "f2b1b232083bd8beaf8a54a024225de3dd72a673a9bcdf8c3ba96c39483f4309"
patches:
"1.0.4":
- patch_file: "patches/1.0.4-0001-Fix-static-library-builds.patch"
patch_type: "conan"
patch_description: "Fix static library builds"
- patch_file: "patches/1.0.4-0002-fix-install-ios.patch"
patch_type: "conan"
patch_description: "Fix install iOS"
"1.0.6":
- patch_file: "patches/1.0.6-0001-fix-library-builds.patch"
patch_type: "conan"
patch_description: "Fix library builds"
- patch_file: "patches/1.0.6-0002-fix-cmake-build-with-ninja.patch"
patch_type: "conan"
patch_description: "Ninja needs 'aec' binary to be put in a separate folder to an imaginary 'aec' object output"
url: "https://gitlab.dkrz.de/k202009/libaec/-/archive/v1.0.6/libaec-v1.0.6.tar.bz2"
sha256: "31fb65b31e835e1a0f3b682d64920957b6e4407ee5bbf42ca49549438795a288"
92 changes: 48 additions & 44 deletions recipes/libaec/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.microsoft import is_msvc
from conan.tools.files import apply_conandata_patches, export_conandata_patches, get, copy, rm, rmdir, replace_in_file
from conan.tools.scm import Version
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.files import get, copy, rm, rmdir, replace_in_file
from conan.tools.microsoft import is_msvc, check_min_vs
from conan.tools.scm import Version
import os

required_conan_version = ">=1.52.0"
required_conan_version = ">=1.53.0"


class LibaecConan(ConanFile):
Expand All @@ -16,6 +16,8 @@ class LibaecConan(ConanFile):
homepage = "https://gitlab.dkrz.de/k202009/libaec"
description = "Adaptive Entropy Coding library"
topics = "dsp", "encoding", "decoding"

package_type = "library"
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
Expand All @@ -27,80 +29,82 @@ class LibaecConan(ConanFile):
}

def export_sources(self):
export_conandata_patches(self)
copy(self, "set_runtime_output_dir.cmake", self.recipe_folder, os.path.join(self.export_sources_folder, "src"))

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

def configure(self):
if self.options.shared:
try:
del self.options.fPIC
except Exception:
pass
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass
self.options.rm_safe("fPIC")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")

def layout(self):
cmake_layout(self, src_folder="src")

def validate(self):
if Version(self.version) >= "1.0.6" and is_msvc(self):
# libaec/1.0.6 uses "restrict" keyword which seems to be supported since Visual Studio 16.
if Version(self.settings.compiler.version) < "16":
raise ConanInvalidConfiguration("{} does not support Visual Studio {}".format(self.name, self.settings.compiler.version))
# In libaec/1.0.6, fail to build aec_client command with debug and shared settings in Visual Studio.
# Temporary, this recipe doesn't support these settings.
if self.options.shared and self.settings.build_type == "Debug":
raise ConanInvalidConfiguration("{} does not support debug and shared build in Visual Studio(currently)".format(self.name))
# libaec/1.0.6 uses "restrict" keyword which seems to be supported since Visual Studio 16.
check_min_vs(self, 192)
# libaec/1.0.6 fails to build aec_client command with debug and shared settings in Visual Studio.
# Temporary, this recipe doesn't support these settings.
if is_msvc(self) and self.options.shared and self.settings.build_type == "Debug":
raise ConanInvalidConfiguration(f"{self.name} does not support debug and shared build in Visual Studio (currently)")

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

def generate(self):
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.cache_variables["CMAKE_PROJECT_libaec_INCLUDE"] = "set_runtime_output_dir.cmake"
tc.cache_variables["CMAKE_POSITION_INDEPENDENT_CODE"] = self.options.get_safe("fPIC", True)
tc.cache_variables["BUILD_SHARED_LIBS"] = self.options.shared
tc.generate()

def _patch_sources(self):
cmakelists = os.path.join(self.source_folder, "CMakeLists.txt")
replace_in_file(self, cmakelists, "set(CMAKE_C_STANDARD 99)", "set(CMAKE_C_STANDARD 11)")
replace_in_file(self, cmakelists, "set(CMAKE_POSITION_INDEPENDENT_CODE ON)", "")
targets = "aec_shared sz_shared" if self.options.shared else "aec_static sz_static"
aec_client = " aec_client" if Version(self.version) < "1.1" else ""
replace_in_file(self, os.path.join(self.source_folder, "src", "CMakeLists.txt"),
f"install(TARGETS aec_static aec_shared sz_static sz_shared{aec_client})",
f"install(TARGETS {targets}{aec_client} ARCHIVE DESTINATION lib LIBRARY DESTINATION lib RUNTIME DESTINATION bin)")

def build(self):
apply_conandata_patches(self)
if Version(self.version) < "1.0.6":
replace_in_file(self, os.path.join(self.source_folder, "CMakeLists.txt"),
"add_subdirectory(tests)", "")
self._patch_sources()
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
if Version(self.version) < "1.0.6":
copy(self, pattern="Copyright.txt", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
else:
copy(self, pattern="LICENSE.txt", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
copy(self, "LICENSE.txt", self.source_folder, os.path.join(self.package_folder, "licenses"))
cmake = CMake(self)
cmake.install()
copy(self, "szlib.h", os.path.join(self.source_folder, "include"), os.path.join(self.package_folder, "include"))
copy(self, "libaec.h", os.path.join(self.build_folder, "include"), os.path.join(self.package_folder, "include"))
rmdir(self, os.path.join(self.package_folder, "share"))
rmdir(self, os.path.join(self.package_folder, "cmake"))
rm(self, "*.pdb", os.path.join(self.package_folder, "bin"))

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "libaec")

# CMake targets are based on
# https://gitlab.dkrz.de/k202009/libaec/-/blob/master/cmake/libaec-config.cmake.in
self.cpp_info.components["aec"].set_property("cmake_target_name", "libaec::aec")
aec_name = "aec"
if self.settings.os == "Windows" and Version(self.version) >= "1.0.6" and not self.options.shared:
aec_name = "aec_static"
if self.settings.os == "Windows" and not self.options.shared:
aec_name = "aec_static"
self.cpp_info.components["aec"].libs = [aec_name]

self.cpp_info.components["sz"].set_property("cmake_target_name", "libaec::sz")
szip_name = "sz"
if self.settings.os == "Windows":
if Version(self.version) >= "1.0.6":
szip_name = "szip" if self.options.shared else "szip_static"
elif self.options.shared:
szip_name = "szip"
self.cpp_info.libs = [szip_name, aec_name]
szip_name = "szip" if self.options.shared else "szip_static"
self.cpp_info.components["sz"].libs = [szip_name]

# TODO: Legacy, to be removed on Conan 2.0
bin_path = os.path.join(self.package_folder, "bin")
self.output.info("Appending PATH environment variable: {}".format(bin_path))
self.env_info.PATH.append(bin_path)
135 changes: 0 additions & 135 deletions recipes/libaec/all/patches/1.0.4-0001-Fix-static-library-builds.patch

This file was deleted.

10 changes: 0 additions & 10 deletions recipes/libaec/all/patches/1.0.4-0002-fix-install-ios.patch

This file was deleted.

Loading

0 comments on commit 6a76abc

Please sign in to comment.