diff --git a/recipes/libaec/all/CMakeLists.txt b/recipes/libaec/all/CMakeLists.txt deleted file mode 100644 index 28b6788808412..0000000000000 --- a/recipes/libaec/all/CMakeLists.txt +++ /dev/null @@ -1,9 +0,0 @@ -cmake_minimum_required(VERSION 2.8.11) - -project(cmake_wrapper) - -include(conanbuildinfo.cmake) -conan_basic_setup() - -add_subdirectory("source_subfolder") - diff --git a/recipes/libaec/all/conandata.yml b/recipes/libaec/all/conandata.yml index 81bd3833b2814..fedb680f0ebb4 100644 --- a/recipes/libaec/all/conandata.yml +++ b/recipes/libaec/all/conandata.yml @@ -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" diff --git a/recipes/libaec/all/conanfile.py b/recipes/libaec/all/conanfile.py index 5f628637c580f..943870cdf6a8a 100644 --- a/recipes/libaec/all/conanfile.py +++ b/recipes/libaec/all/conanfile.py @@ -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): @@ -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], @@ -21,25 +25,9 @@ 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": @@ -47,14 +35,26 @@ def config_options(self): 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. @@ -62,46 +62,41 @@ def validate(self): 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" diff --git a/recipes/libaec/all/test_package/CMakeLists.txt b/recipes/libaec/all/test_package/CMakeLists.txt index 39f956e39b59c..f87e0b5ca8eb9 100644 --- a/recipes/libaec/all/test_package/CMakeLists.txt +++ b/recipes/libaec/all/test_package/CMakeLists.txt @@ -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) diff --git a/recipes/libaec/all/test_package/conanfile.py b/recipes/libaec/all/test_package/conanfile.py index b07f7e5f677ac..75526b1d02b79 100644 --- a/recipes/libaec/all/test_package/conanfile.py +++ b/recipes/libaec/all/test_package/conanfile.py @@ -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") diff --git a/recipes/libaec/all/test_v1_package/CMakeLists.txt b/recipes/libaec/all/test_v1_package/CMakeLists.txt new file mode 100644 index 0000000000000..454ad5fbc6eba --- /dev/null +++ b/recipes/libaec/all/test_v1_package/CMakeLists.txt @@ -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) diff --git a/recipes/libaec/all/test_v1_package/conanfile.py b/recipes/libaec/all/test_v1_package/conanfile.py new file mode 100644 index 0000000000000..b07f7e5f677ac --- /dev/null +++ b/recipes/libaec/all/test_v1_package/conanfile.py @@ -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)