Skip to content

Commit

Permalink
(#13622) libaec: upgrade for conan v2
Browse files Browse the repository at this point in the history
* libaec - upgrade for conan v2

* Fix licence copy

* Fix test_v1_package - use common file

* Fix static/shared a better way

* Update recipes/libaec/all/conanfile.py

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

* Update recipes/libaec/all/conanfile.py

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

Co-authored-by: Uilian Ries <uilianries@gmail.com>
  • Loading branch information
paulharris and uilianries authored Oct 21, 2022
1 parent 4b20708 commit 5d069ec
Show file tree
Hide file tree
Showing 7 changed files with 97 additions and 74 deletions.
9 changes: 0 additions & 9 deletions recipes/libaec/all/CMakeLists.txt

This file was deleted.

3 changes: 0 additions & 3 deletions recipes/libaec/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,6 @@ sources:
patches:
"1.0.4":
- patch_file: "patches/1.0.4-0001-Fix-static-library-builds.patch"
base_path: "source_subfolder"
- patch_file: "patches/1.0.4-0002-fix-install-ios.patch"
base_path: "source_subfolder"
"1.0.6":
- patch_file: "patches/1.0.6-0001-fix-library-builds.patch"
base_path: "source_subfolder"
99 changes: 47 additions & 52 deletions recipes/libaec/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from conans import ConanFile, CMake, tools
from conans.errors import ConanInvalidConfiguration
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
import os

required_conan_version = ">=1.33.0"
required_conan_version = ">=1.52.0"


class LibaecConan(ConanFile):
Expand All @@ -11,7 +15,7 @@ class LibaecConan(ConanFile):
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://gitlab.dkrz.de/k202009/libaec"
description = "Adaptive Entropy Coding library"
topics = ("dsp", "libaec", "encoding", "decoding",)
topics = "dsp", "encoding", "decoding"
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
Expand All @@ -21,87 +25,78 @@ class LibaecConan(ConanFile):
"shared": False,
"fPIC": True,
}
generators = "cmake"
_cmake = None

@property
def _source_subfolder(self):
return "source_subfolder"

@property
def _build_subfolder(self):
return "build_subfolder"

@property
def _is_msvc(self):
return str(self.settings.compiler) in ["Visual Studio", "msvc"]

def export_sources(self):
self.copy("CMakeLists.txt")
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
export_conandata_patches(self)

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

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
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

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

def validate(self):
if tools.Version(self.version) >= "1.0.6" and self._is_msvc:
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 tools.Version(self.settings.compiler.version) < "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))

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

def _patch_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
if tools.Version(self.version) < "1.0.6":
tools.replace_in_file(os.path.join(self._source_subfolder, "CMakeLists.txt"),
"add_subdirectory(tests)", "")

def _configure_cmake(self):
if self._cmake:
return self._cmake
self._cmake = CMake(self)
self._cmake.configure()
return self._cmake
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.generate()

def build(self):
self._patch_sources()
cmake = self._configure_cmake()
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)", "")
cmake = CMake(self)
cmake.configure()
cmake.build()

def package(self):
if tools.Version(self.version) < "1.0.6":
self.copy(pattern="Copyright.txt", dst="licenses", src=self._source_subfolder)
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:
self.copy(pattern="LICENSE.txt", dst="licenses", src=self._source_subfolder)
cmake = self._configure_cmake()
copy(self, pattern="LICENSE.txt", dst=os.path.join(self.package_folder, "licenses"), src=self.source_folder)
cmake = CMake(self)
cmake.install()
tools.rmdir(os.path.join(self.package_folder, "share"))
tools.rmdir(os.path.join(self.package_folder, "cmake"))
tools.remove_files_by_mask(os.path.join(self.package_folder, "bin"), "*.pdb")
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):
aec_name = "aec"
if self.settings.os == "Windows" and tools.Version(self.version) >= "1.0.6" and not self.options.shared:
if self.settings.os == "Windows" and Version(self.version) >= "1.0.6" and not self.options.shared:
aec_name = "aec_static"
szip_name = "sz"
if self.settings.os == "Windows":
if tools.Version(self.version) >= "1.0.6":
if Version(self.version) >= "1.0.6":
szip_name = "szip" if self.options.shared else "szip_static"
elif self.options.shared:
szip_name = "szip"
Expand Down
3 changes: 0 additions & 3 deletions recipes/libaec/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
cmake_minimum_required(VERSION 3.1.3)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(libaec CONFIG REQUIRED)

add_executable(${PROJECT_NAME} test_package.c)
Expand Down
28 changes: 21 additions & 7 deletions recipes/libaec/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,19 +1,33 @@
from conans import ConanFile, CMake, tools
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
from conan.tools.scm import Version
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"

def requirements(self):
self.requires(self.tested_reference_str)

def layout(self):
cmake_layout(self)

def generate(self):
tc = CMakeToolchain(self)
if Version(self.dependencies["libaec"].ref.version) >= "1.0.6":
tc.variables["CMAKE_C_STANDARD"] = "11"
tc.generate()

def build(self):
cmake = CMake(self)
if tools.Version(self.deps_cpp_info["libaec"].version) >= "1.0.6":
cmake.definitions["CMAKE_C_STANDARD"] = "11"
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")
10 changes: 10 additions & 0 deletions recipes/libaec/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
cmake_minimum_required(VERSION 3.1.3)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)

find_package(libaec CONFIG REQUIRED)

add_executable(${PROJECT_NAME} ../test_package/test_package.c)
target_link_libraries(${PROJECT_NAME} libaec::libaec)
19 changes: 19 additions & 0 deletions recipes/libaec/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
from conans import ConanFile, CMake, tools
import os


class TestPackageConan(ConanFile):
settings = "os", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"

def build(self):
cmake = CMake(self)
if tools.Version(self.deps_cpp_info["libaec"].version) >= "1.0.6":
cmake.definitions["CMAKE_C_STANDARD"] = "11"
cmake.configure()
cmake.build()

def test(self):
if not tools.cross_building(self):
bin_path = os.path.join("bin", "test_package")
self.run(bin_path, run_environment=True)

0 comments on commit 5d069ec

Please sign in to comment.