[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,25 @@
sources:
"1.31.2":
url:
- "https://nexus.avroid.tech/repository/all-raw-proxy-sourceforge_net/projects/mpg123/files/mpg123/1.31.2/mpg123-1.31.2.tar.bz2"
- "https://www.mpg123.de/download/mpg123-1.31.2.tar.bz2"
sha256: "b17f22905e31f43b6b401dfdf6a71ed11bb7d056f68db449d70b9f9ae839c7de"
"1.29.3":
url:
- "https://nexus.avroid.tech/repository/all-raw-proxy-sourceforge_net/projects/mpg123/files/mpg123/1.29.3/mpg123-1.29.3.tar.bz2"
- "https://www.mpg123.de/download/mpg123-1.29.3.tar.bz2"
sha256: "963885d8cc77262f28b77187c7d189e32195e64244de2530b798ddf32183e847"
"1.26.4":
url:
- "https://nexus.avroid.tech/repository/all-raw-proxy-sourceforge_net/projects/mpg123/files/mpg123/1.26.4/mpg123-1.26.4.tar.bz2"
- "https://www.mpg123.de/download/mpg123-1.26.4.tar.bz2"
sha256: "081991540df7a666b29049ad870f293cfa28863b36488ab4d58ceaa7b5846454"
patches:
"1.31.2":
- patch_file: "patches/0001-msvc-export-symbols.patch"
"1.26.4":
- patch_file: "patches/0001-msvc-export-symbols.patch"
"1.29.3":
- patch_file: "patches/0001-msvc-export-symbols.patch"
- patch_file: "patches/0002-cmake-read_api_version-fix.patch"

View File

@@ -0,0 +1,239 @@
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.apple import is_apple_os, fix_apple_shared_install_name
from conan.tools.cmake import cmake_layout, CMake, CMakeDeps, CMakeToolchain
from conan.tools.layout import basic_layout
from conan.tools.gnu import Autotools, AutotoolsDeps, AutotoolsToolchain
from conan.tools.files import get, copy, export_conandata_patches, apply_conandata_patches, rmdir, rm
from conan.tools.microsoft import is_msvc
from conan.tools.env import VirtualBuildEnv, VirtualRunEnv
from conan.tools.build import cross_building
import os
required_conan_version = ">=1.53.0"
class Mpg123Conan(ConanFile):
name = "mpg123"
description = "Fast console MPEG Audio Player and decoder library"
topics = ("mpeg", "audio", "player", "decoder")
url = "https://github.com/conan-io/conan-center-index"
homepage = "http://mpg123.org/"
license = "LGPL-2.1-or-later", "GPL-2.0-or-later"
settings = "os", "compiler", "build_type", "arch"
options = {
"shared": [True, False],
"fPIC": [True, False],
"flexible_resampling": [True, False],
"network": [True, False],
"icy": [True, False],
"id3v2": [True, False],
"ieeefloat": [True, False],
"layer1": [True, False],
"layer2": [True, False],
"layer3": [True, False],
"moreinfo": [True, False],
"seektable": [None, "ANY"],
"module": ["dummy", "libalsa", "tinyalsa", "win32"],
}
default_options = {
"shared": False,
"fPIC": True,
"flexible_resampling": True,
"network": True,
"icy": True,
"id3v2": True,
"ieeefloat": True,
"layer1": True,
"layer2": True,
"layer3": True,
"moreinfo": True,
"seektable": "1000",
"module": "dummy",
}
@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)
@property
def _audio_module(self):
return {
"libalsa": "alsa",
}.get(str(self.options.module), str(self.options.module))
def export_sources(self):
export_conandata_patches(self)
def config_options(self):
if self.settings.os == "Windows":
self.options.rm_safe("fPIC")
def configure(self):
self.settings.rm_safe("compiler.libcxx")
self.settings.rm_safe("compiler.cppstd")
if self.options.shared:
self.options.rm_safe("fPIC")
def layout(self):
if is_msvc(self):
cmake_layout(self, src_folder="src")
else:
basic_layout(self, src_folder="src")
def requirements(self):
if self.options.module == "libalsa":
self.requires("libalsa/1.2.10")
if self.options.module == "tinyalsa":
self.requires("tinyalsa/2.0.0")
def validate(self):
if not str(self.options.seektable).isdigit():
raise ConanInvalidConfiguration(f"The option -o {self.ref.name}:seektable must be an integer number.")
if self.settings.os != "Windows" and self.options.module == "win32":
raise ConanInvalidConfiguration(f"The option -o {self.ref.name}:module should not use 'win32' for non-Windows OS")
def build_requirements(self):
if not self.conf.get("tools.gnu:pkg_config", default=False, check_type=str):
self.tool_requires("pkgconf/[>=2.0.3]")
if self.settings.arch in ["x86", "x86_64"]:
#self.tool_requires("yasm/1.3.0")
self.tool_requires("nasm/[>=2.15.05]")
if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", default=False, check_type=str):
self.tool_requires("msys2/cci.latest")
def source(self):
get(self, **self.conan_data["sources"][self.version], strip_root=True)
def generate(self):
env = VirtualBuildEnv(self)
env.generate()
if not cross_building(self):
env = VirtualRunEnv(self)
env.generate(scope="build")
if is_msvc(self):
tc = CMakeToolchain(self)
tc.variables["NO_MOREINFO"] = not self.options.moreinfo
tc.variables["NETWORK"] = self.options.network
tc.variables["NO_NTOM"] = not self.options.flexible_resampling
tc.variables["NO_ICY"] = not self.options.icy
tc.variables["NO_ID3V2"] = not self.options.id3v2
tc.variables["IEEE_FLOAT"] = self.options.ieeefloat
tc.variables["NO_LAYER1"] = not self.options.layer1
tc.variables["NO_LAYER2"] = not self.options.layer2
tc.variables["NO_LAYER3"] = not self.options.layer3
tc.variables["USE_MODULES"] = False
tc.variables["CHECK_MODULES"] = self._audio_module
tc.variables["WITH_SEEKTABLE"] = self.options.seektable
tc.generate()
tc = CMakeDeps(self)
tc.generate()
else:
yes_no = lambda v: "yes" if v else "no"
tc = AutotoolsToolchain(self)
tc.configure_args.extend([
f"--enable-moreinfo={yes_no(self.options.moreinfo)}",
f"--enable-network={yes_no(self.options.network)}",
f"--enable-ntom={yes_no(self.options.flexible_resampling)}",
f"--enable-icy={yes_no(self.options.icy)}",
f"--enable-id3v2={yes_no(self.options.id3v2)}",
f"--enable-ieeefloat={yes_no(self.options.ieeefloat)}",
f"--enable-layer1={yes_no(self.options.layer1)}",
f"--enable-layer2={yes_no(self.options.layer2)}",
f"--enable-layer3={yes_no(self.options.layer3)}",
f"--with-audio={self._audio_module}",
f"--with-default-audio={self._audio_module}",
f"--with-seektable={self.options.seektable}",
f"--enable-modules=no",
f"--enable-shared={yes_no(self.options.shared)}",
f"--enable-static={yes_no(not self.options.shared)}",
])
if is_apple_os(self):
# Needed for fix_apple_shared_install_name invocation in package method
tc.extra_cflags += ["-headerpad_max_install_names"]
# The finite-math-only optimization has no effect and will cause linking errors
# when linked against glibc >= 2.31
tc.extra_cflags += ["-fno-finite-math-only"]
tc.generate()
tc = AutotoolsDeps(self)
tc.generate()
def build(self):
apply_conandata_patches(self)
if is_msvc(self):
cmake = CMake(self)
cmake.configure(build_script_folder=os.path.join(self.source_folder, "ports", "cmake"))
cmake.build()
else:
autotools = Autotools(self)
autotools.configure()
autotools.make()
def package(self):
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
if is_msvc(self):
cmake = CMake(self)
cmake.install()
rmdir(self, os.path.join(self.package_folder, "lib", "cmake"))
else:
autotools = Autotools(self)
autotools.install()
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rmdir(self, os.path.join(self.package_folder, "share"))
fix_apple_shared_install_name(self)
def package_info(self):
self.cpp_info.set_property("cmake_file_name", "mpg123")
self.cpp_info.components["libmpg123"].libs = ["mpg123"]
self.cpp_info.components["libmpg123"].set_property("pkg_config_name", "libmpg123")
self.cpp_info.components["libmpg123"].set_property("cmake_target_name", "MPG123::libmpg123")
self.cpp_info.components["libmpg123"].names["cmake_find_package"] = "libmpg123"
self.cpp_info.components["libmpg123"].names["cmake_find_package_multi"] = "libmpg123"
if self.settings.os == "Windows" and self.options.shared:
self.cpp_info.components["libmpg123"].defines.append("LINK_MPG123_DLL")
self.cpp_info.components["libout123"].libs = ["out123"]
self.cpp_info.components["libout123"].set_property("pkg_config_name", "libout123")
self.cpp_info.components["libout123"].set_property("cmake_target_name", "MPG123::libout123")
self.cpp_info.components["libout123"].names["cmake_find_package"] = "libout123"
self.cpp_info.components["libout123"].names["cmake_find_package_multi"] = "libout123"
self.cpp_info.components["libout123"].requires = ["libmpg123"]
self.cpp_info.components["libsyn123"].libs = ["syn123"]
self.cpp_info.components["libsyn123"].set_property("pkg_config_name", "libsyn123")
self.cpp_info.components["libsyn123"].set_property("cmake_target_name", "MPG123::libsyn123")
self.cpp_info.components["libsyn123"].names["cmake_find_package"] = "libsyn123"
self.cpp_info.components["libsyn123"].names["cmake_find_package_multi"] = "libsyn123"
self.cpp_info.components["libsyn123"].requires = ["libmpg123"]
if self.settings.os == "Linux":
self.cpp_info.components["libmpg123"].system_libs = ["m"]
if self.settings.arch in ["x86", "x86_64"]:
self.cpp_info.components["libsyn123"].system_libs = ["mvec"]
elif self.settings.os == "Windows":
self.cpp_info.components["libmpg123"].system_libs = ["shlwapi"]
if self.options.module == "libalsa":
self.cpp_info.components["libout123"].requires.append("libalsa::libalsa")
if self.options.module == "tinyalsa":
self.cpp_info.components["libout123"].requires.append("tinyalsa::tinyalsa")
if self.options.module == "win32":
self.cpp_info.components["libout123"].system_libs.append("winmm")
# TODO: Remove after Conan 2.x becomes the standard
self.cpp_info.filenames["cmake_find_package"] = "mpg123"
self.cpp_info.filenames["cmake_find_package_multi"] = "mpg123"
self.cpp_info.names["cmake_find_package"] = "MPG123"
self.cpp_info.names["cmake_find_package_multi"] = "MPG123"
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)

View File

@@ -0,0 +1,22 @@
--- a/ports/cmake/src/libout123/CMakeLists.txt
+++ b/ports/cmake/src/libout123/CMakeLists.txt
@@ -18,7 +18,7 @@ add_library(${TARGET}
$<TARGET_OBJECTS:compat>
$<$<BOOL:${USE_MODULES}>:$<TARGET_OBJECTS:compat_dl>>)
-set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME out123)
+set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME out123 WINDOWS_EXPORT_ALL_SYMBOLS ON)
target_link_libraries(${TARGET} PRIVATE
$<TARGET_NAME_IF_EXISTS:defaultmodule>
--- a/ports/cmake/src/libsyn123/CMakeLists.txt
+++ b/ports/cmake/src/libsyn123/CMakeLists.txt
@@ -15,7 +15,7 @@ add_library(${TARGET}
"${CMAKE_CURRENT_SOURCE_DIR}/../../../../src/libsyn123/sampleconv.c"
$<TARGET_OBJECTS:compat_str>)
-set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME syn123)
+set_target_properties(${TARGET} PROPERTIES OUTPUT_NAME syn123 WINDOWS_EXPORT_ALL_SYMBOLS ON)
target_include_directories(${TARGET} INTERFACE
"$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>"

View File

@@ -0,0 +1,10 @@
--- a/ports/cmake/cmake/read_api_version.cmake
+++ b/ports/cmake/cmake/read_api_version.cmake
@@ -1,6 +1,6 @@
function(read_api_version project_version api_version outapi_version synapi_version )
- file( READ "${CMAKE_SOURCE_DIR}/../../configure.ac" configure_ac )
+ file( READ "${CMAKE_CURRENT_SOURCE_DIR}/../../configure.ac" configure_ac )
string( REGEX MATCH "AC_INIT\\(\\[mpg123\\], \\[([0-9\\.]+)" result ${configure_ac} )
set( ${project_version} ${CMAKE_MATCH_1} PARENT_SCOPE )

View File

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

View File

@@ -0,0 +1,26 @@
from conan import ConanFile
from conan.tools.build import can_run
from conan.tools.cmake import cmake_layout, CMake
import os
class TestPackageConan(ConanFile):
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeDeps", "CMakeToolchain", "VirtualRunEnv"
test_type = "explicit"
def requirements(self):
self.requires(self.tested_reference_str)
def layout(self):
cmake_layout(self)
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,12 @@
#include "mpg123.h"
#include <stdio.h>
int main() {
int error;
mpg123_pars *pars;
pars = mpg123_new_pars(&error);
mpg123_fmt_all(pars);
mpg123_delete_pars(pars);
return 0;
}

View File

@@ -0,0 +1,7 @@
versions:
"1.31.2":
folder: "all"
"1.29.3":
folder: "all"
"1.26.4":
folder: "all"