[DO-971] ffmpeg recipe with requirements (!9)

Co-authored-by: aleksandr.vodyanov <aleksandr.vodyanov@avroid.tech>
Reviewed-on: https://git.avroid.tech/Conan/conan_build/pulls/9
This commit is contained in:
Aleksandr Vodyanov
2024-12-25 17:47:28 +03:00
parent e58f90de0e
commit 39afe6a1dd
212 changed files with 9263 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
sources:
"1.5.2":
url: "https://github.com/xiph/opus/releases/download/v1.5.2/opus-1.5.2.tar.gz"
sha256: "5cf92b5b577d8ed203424f1e0f618f30bc6b6e42a26eae88bdb649ea63961cc9"
"1.4":
url: "https://github.com/xiph/opus/releases/download/v1.4/opus-1.4.tar.gz"
sha256: "c9b32b4253be5ae63d1ff16eea06b94b5f0f2951b7a02aceef58e3a3ce49c51f"
"1.3.1":
url: "https://github.com/xiph/opus/releases/download/v1.3.1/opus-1.3.1.tar.gz"
sha256: "65b58e1e25b2a114157014736a3d9dfeaad8d41be1c8179866f144a2fb44ff9d"
patches:
"1.3.1":
- patch_file: "patches/1.3.1-add-opus_buildtype-cmake.patch"
patch_description: "Set a default build type if none was specified"
patch_type: "portability"

View File

@@ -0,0 +1,107 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
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 check_min_vs, is_msvc, is_msvc_static_runtime
from conan.tools.env import VirtualBuildEnv
from conan.tools.scm import Version
import os
required_conan_version = ">=1.53.0"
class OpusConan(ConanFile):
name = "opus"
description = "Opus is a totally open, royalty-free, highly versatile audio codec."
topics = ("opus", "audio", "decoder", "decoding", "multimedia", "sound")
url = "https://github.com/conan-io/conan-center-index"
homepage = "https://opus-codec.org"
license = "BSD-3-Clause"
package_type = "library"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
"fixed_point": [True, False],
"stack_protector": [True, False],
}
default_options = {
"shared": False,
"fPIC": True,
"fixed_point": False,
"stack_protector": True,
}
# def build_requirements(self):
# if Version(self.version) >= "1.5.2":
# self.tool_requires("cmake/[>=3.16 <4]")
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")
self.settings.rm_safe("compiler.cppstd")
self.settings.rm_safe("compiler.libcxx")
def layout(self):
cmake_layout(self, src_folder="src")
def validate(self):
check_min_vs(self, 190)
if Version(self.version) >= "1.5.2" and self.settings.compiler == "gcc" and Version(self.settings.compiler.version) < "8":
raise ConanInvalidConfiguration(f"{self.ref} GCC-{self.settings.compiler.version} not supported due to lack of AVX2 support. Use GCC >=8.")
def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)
def generate(self):
if Version(self.version) >= "1.5.2":
env = VirtualBuildEnv(self)
env.generate()
tc = CMakeToolchain(self)
tc.cache_variables["OPUS_BUILD_SHARED_LIBRARY"] = self.options.shared
tc.cache_variables["OPUS_FIXED_POINT"] = self.options.fixed_point
tc.cache_variables["OPUS_STACK_PROTECTOR"] = self.options.stack_protector
if Version(self.version) >= "1.5.2" and is_msvc(self):
tc.cache_variables["OPUS_STATIC_RUNTIME"] = is_msvc_static_runtime(self)
tc.generate()
def build(self):
apply_conandata_patches(self)
cmake = CMake(self)
cmake.configure()
cmake.build()
def package(self):
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
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"))
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "Opus")
self.cpp_info.set_property("cmake_target_name", "Opus::opus")
self.cpp_info.set_property("pkg_config_name", "opus")
# TODO: back to global scope in conan v2 once cmake_find_package_* generators removed
self.cpp_info.components["libopus"].libs = ["opus"]
self.cpp_info.components["libopus"].includedirs.append(os.path.join("include", "opus"))
if self.settings.os in ["Linux", "FreeBSD", "Android"]:
self.cpp_info.components["libopus"].system_libs.append("m")
if self.settings.os == "Windows" and self.settings.compiler == "gcc":
self.cpp_info.components["libopus"].system_libs.append("ssp")
# TODO: to remove in conan v2 once cmake_find_package_* generators removed
self.cpp_info.names["cmake_find_package"] = "Opus"
self.cpp_info.names["cmake_find_package_multi"] = "Opus"
self.cpp_info.components["libopus"].names["cmake_find_package"] = "opus"
self.cpp_info.components["libopus"].names["cmake_find_package_multi"] = "opus"
self.cpp_info.components["libopus"].set_property("cmake_target_name", "Opus::opus")
self.cpp_info.components["libopus"].set_property("pkg_config_name", "opus")

View File

@@ -0,0 +1,30 @@
# They forgot to package that file into the tarball for 1.3.1
# See https://github.com/xiph/opus/issues/129
new file mode 100755
--- /dev/null
+++ opus_buildtype.cmake
@@ -0,0 +1,23 @@
+# Set a default build type if none was specified
+
+if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
+ if(CMAKE_C_FLAGS)
+ message(STATUS "CMAKE_C_FLAGS: " ${CMAKE_C_FLAGS})
+ else()
+ set(default_build_type "Release")
+ message(
+ STATUS
+ "Setting build type to '${default_build_type}' as none was specified and no CFLAGS was exported."
+ )
+ set(CMAKE_BUILD_TYPE "${default_build_type}"
+ CACHE STRING "Choose the type of build."
+ FORCE)
+ # Set the possible values of build type for cmake-gui
+ set_property(CACHE CMAKE_BUILD_TYPE
+ PROPERTY STRINGS
+ "Debug"
+ "Release"
+ "MinSizeRel"
+ "RelWithDebInfo")
+ endif()
+endif()

View File

@@ -0,0 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package LANGUAGES C)
find_package(Opus REQUIRED CONFIG)
add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE Opus::opus)

View File

@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import CMake, cmake_layout
import os
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"
def layout(self):
cmake_layout(self)
def requirements(self):
self.requires(self.tested_reference_str)
def build(self):
cmake = CMake(self)
cmake.configure()
cmake.build()
def test(self):
if can_run(self):
bin_path = os.path.join(self.cpp.build.bindirs[0], "test_package")
self.run(bin_path, env="conanrun")

View File

@@ -0,0 +1,13 @@
#include <stdio.h>
#include <opus/opus.h>
int main() {
int err;
int rate = 48000;
int channels = 2;
int application = OPUS_APPLICATION_AUDIO;
OpusEncoder *encoder;
encoder = opus_encoder_create(rate, channels, application, &err);
opus_encoder_destroy(encoder);
}