Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

libfdk_aac: conan v2 support #15350

Merged
merged 2 commits into from
Jan 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 0 additions & 7 deletions recipes/libfdk_aac/all/CMakeLists.txt

This file was deleted.

12 changes: 6 additions & 6 deletions recipes/libfdk_aac/all/conandata.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
sources:
"2.0.2":
url: "https://github.com/mstorsjo/fdk-aac/archive/refs/tags/v2.0.2.tar.gz"
sha256: "7812b4f0cf66acda0d0fe4302545339517e702af7674dd04e5fe22a5ade16a90"
url: "https://sourceforge.net/projects/opencore-amr/files/fdk-aac/fdk-aac-2.0.2.tar.gz"
sha256: "c9e8630cf9d433f3cead74906a1520d2223f89bcd3fa9254861017440b8eb22f"
"2.0.1":
url: "https://github.com/mstorsjo/fdk-aac/archive/v2.0.1.tar.gz"
sha256: "a4142815d8d52d0e798212a5adea54ecf42bcd4eec8092b37a8cb615ace91dc6"
url: "https://sourceforge.net/projects/opencore-amr/files/fdk-aac/fdk-aac-2.0.1.tar.gz"
sha256: "840133aa9412153894af03b27b03dde1188772442c316a4ce2a24ed70093f271"
"2.0.0":
url: "https://github.com/mstorsjo/fdk-aac/archive/v2.0.0.tar.gz"
sha256: "6e6c7921713788e31df655911e1d42620b057180b00bf16874f5d630e1d5b9a2"
url: "https://sourceforge.net/projects/opencore-amr/files/fdk-aac/fdk-aac-2.0.0.tar.gz"
sha256: "f7d6e60f978ff1db952f7d5c3e96751816f5aef238ecf1d876972697b85fd96c"
191 changes: 88 additions & 103 deletions recipes/libfdk_aac/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,15 @@
from conans import ConanFile, AutoToolsBuildEnvironment, CMake, VisualStudioBuildEnvironment, tools
import contextlib
import functools
from conan import ConanFile
from conan.tools.apple import fix_apple_shared_install_name
from conan.tools.cmake import CMake, CMakeToolchain, cmake_layout
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import chdir, copy, get, rename, replace_in_file, rm, rmdir
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import is_msvc, NMakeToolchain
from conan.tools.scm import Version
import os

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.55.0"


class LibFDKAACConan(ConanFile):
Expand All @@ -12,7 +18,7 @@ class LibFDKAACConan(ConanFile):
description = "A standalone library of the Fraunhofer FDK AAC code from Android"
license = "https://github.com/mstorsjo/fdk-aac/blob/master/NOTICE"
homepage = "https://sourceforge.net/projects/opencore-amr/"
topics = ("libfdk_aac", "multimedia", "audio", "fraunhofer", "aac", "decoder", "encoding", "decoding")
topics = ("multimedia", "audio", "fraunhofer", "aac", "decoder", "encoding", "decoding")

settings = "os", "arch", "compiler", "build_type"
options = {
Expand All @@ -24,133 +30,113 @@ class LibFDKAACConan(ConanFile):
"fPIC": True,
}

exports_sources = "CMakeLists.txt"
generators = "cmake"

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

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

@property
def _settings_build(self):
return getattr(self, "settings_build", self.settings)

@property
def _use_cmake(self):
return tools.Version(self.version) >= "2.0.2"
return Version(self.version) >= "2.0.2"

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

def configure(self):
if self.options.shared:
del self.options.fPIC
self.options.rm_safe("fPIC")

def layout(self):
if self._use_cmake:
cmake_layout(self, src_folder="src")
else:
basic_layout(self, src_folder="src")

def build_requirements(self):
if not self._use_cmake and not self._is_msvc:
self.build_requires("libtool/2.4.6")
if self._settings_build.os == "Windows" and not tools.get_env("CONAN_BASH_PATH"):
self.build_requires("msys2/cci.latest")
if not self._use_cmake and not is_msvc(self):
self.tool_requires("libtool/2.4.7")
if self._settings_build.os == "Windows":
self.win_bash = True
if not self.conf.get("tools.microsoft.bash:path", check_type=str):
self.tool_requires("msys2/cci.latest")

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

@functools.lru_cache(1)
def _configure_cmake(self):
cmake = CMake(self)
cmake.definitions["BUILD_PROGRAMS"] = False
cmake.definitions["FDK_AAC_INSTALL_CMAKE_CONFIG_MODULE"] = False
cmake.definitions["FDK_AAC_INSTALL_PKGCONFIG_MODULE"] = False
cmake.configure()
return cmake

@contextlib.contextmanager
def _msvc_build_environment(self):
with tools.chdir(self._source_subfolder):
with tools.vcvars(self):
with tools.environment_append(VisualStudioBuildEnvironment(self).vars):
yield

def _build_vs(self):
with self._msvc_build_environment():
# Rely on flags injected by conan
tools.replace_in_file("Makefile.vc",
"CFLAGS = /nologo /W3 /Ox /MT",
"CFLAGS = /nologo")
tools.replace_in_file("Makefile.vc",
"MKDIR_FLAGS = -p",
"MKDIR_FLAGS =")
# Build either shared or static, and don't build utility (it always depends on static lib)
tools.replace_in_file("Makefile.vc", "copy $(PROGS) $(bindir)", "")
tools.replace_in_file("Makefile.vc", "copy $(LIB_DEF) $(libdir)", "")
if self.options.shared:
tools.replace_in_file("Makefile.vc",
"all: $(LIB_DEF) $(STATIC_LIB) $(SHARED_LIB) $(IMP_LIB) $(PROGS)",
"all: $(LIB_DEF) $(SHARED_LIB) $(IMP_LIB)")
tools.replace_in_file("Makefile.vc", "copy $(STATIC_LIB) $(libdir)", "")
else:
tools.replace_in_file("Makefile.vc",
"all: $(LIB_DEF) $(STATIC_LIB) $(SHARED_LIB) $(IMP_LIB) $(PROGS)",
"all: $(STATIC_LIB)")
tools.replace_in_file("Makefile.vc", "copy $(IMP_LIB) $(libdir)", "")
tools.replace_in_file("Makefile.vc", "copy $(SHARED_LIB) $(bindir)", "")
self.run("nmake -f Makefile.vc")

def _build_autotools(self):
with tools.chdir(self._source_subfolder):
self.run("{} -fiv".format(tools.get_env("AUTORECONF")), win_bash=tools.os_info.is_windows)
# relocatable shared lib on macOS
tools.replace_in_file("configure", "-install_name \\$rpath/", "-install_name @rpath/")
if self.settings.os == "Android" and tools.os_info.is_windows:
# remove escape for quotation marks, to make ndk on windows happy
tools.replace_in_file("configure",
"s/[ `~#$^&*(){}\\\\|;'\\\''\"<>?]/\\\\&/g", "s/[ `~#$^&*(){}\\\\|;<>?]/\\\\&/g")
autotools = self._configure_autotools()
autotools.make()

@functools.lru_cache(1)
def _configure_autotools(self):
autotools = AutoToolsBuildEnvironment(self, win_bash=tools.os_info.is_windows)
autotools.libs = []
yes_no = lambda v: "yes" if v else "no"
args = [
"--enable-shared={}".format(yes_no(self.options.shared)),
"--enable-static={}".format(yes_no(not self.options.shared)),
]
autotools.configure(args=args, configure_dir=self._source_subfolder)
return autotools
get(self, **self.conan_data["sources"][self.version], strip_root=True)

def generate(self):
if self._use_cmake:
tc = CMakeToolchain(self)
tc.variables["BUILD_PROGRAMS"] = False
tc.variables["FDK_AAC_INSTALL_CMAKE_CONFIG_MODULE"] = False
tc.variables["FDK_AAC_INSTALL_PKGCONFIG_MODULE"] = False
tc.generate()
elif is_msvc(self):
tc = NMakeToolchain(self)
tc.generate()
else:
env = VirtualBuildEnv(self)
env.generate()
tc = AutotoolsToolchain(self)
tc.generate()

def build(self):
if self._use_cmake:
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.configure()
cmake.build()
elif self._is_msvc:
self._build_vs()
elif is_msvc(self):
makefile_vc = os.path.join(self.source_folder, "Makefile.vc")
replace_in_file(self, makefile_vc, "CFLAGS = /nologo /W3 /Ox /MT", "CFLAGS = /nologo")
replace_in_file(self, makefile_vc, "MKDIR_FLAGS = -p", "MKDIR_FLAGS =")
# Build either shared or static, and don't build utility (it always depends on static lib)
replace_in_file(self, makefile_vc, "copy $(PROGS) $(bindir)", "")
replace_in_file(self, makefile_vc, "copy $(LIB_DEF) $(libdir)", "")
if self.options.shared:
replace_in_file(
self, makefile_vc,
"all: $(LIB_DEF) $(STATIC_LIB) $(SHARED_LIB) $(IMP_LIB) $(PROGS)",
"all: $(LIB_DEF) $(SHARED_LIB) $(IMP_LIB)",
)
replace_in_file(self, makefile_vc, "copy $(STATIC_LIB) $(libdir)", "")
else:
replace_in_file(
self, makefile_vc,
"all: $(LIB_DEF) $(STATIC_LIB) $(SHARED_LIB) $(IMP_LIB) $(PROGS)",
"all: $(STATIC_LIB)",
)
replace_in_file(self, makefile_vc, "copy $(IMP_LIB) $(libdir)", "")
replace_in_file(self, makefile_vc, "copy $(SHARED_LIB) $(bindir)", "")
with chdir(self, self.source_folder):
self.run("nmake -f Makefile.vc")
else:
self._build_autotools()
autotools = Autotools(self)
autotools.autoreconf()
if self.settings.os == "Android" and self._settings_build.os == "Windows":
# remove escape for quotation marks, to make ndk on windows happy
replace_in_file(
self, os.path.join(self.source_folder, "configure"),
"s/[ `~#$^&*(){}\\\\|;'\\\''\"<>?]/\\\\&/g", "s/[ `~#$^&*(){}\\\\|;<>?]/\\\\&/g",
)
autotools.configure()
autotools.make()

def package(self):
self.copy(pattern="NOTICE", src=self._source_subfolder, dst="licenses")
copy(self, "NOTICE", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
if self._use_cmake:
cmake = self._configure_cmake()
cmake = CMake(self)
cmake.install()
elif self._is_msvc:
with self._msvc_build_environment():
self.run("nmake -f Makefile.vc prefix=\"{}\" install".format(self.package_folder))
elif is_msvc(self):
with chdir(self, self.source_folder):
self.run(f"nmake -f Makefile.vc prefix=\"{self.package_folder}\" install")
if self.options.shared:
tools.rename(os.path.join(self.package_folder, "lib", "fdk-aac.dll.lib"),
rename(self, os.path.join(self.package_folder, "lib", "fdk-aac.dll.lib"),
os.path.join(self.package_folder, "lib", "fdk-aac.lib"))
else:
autotools = self._configure_autotools()
autotools = Autotools(self)
autotools.install()
tools.rmdir(os.path.join(self.package_folder, "lib", "pkgconfig"))
tools.remove_files_by_mask(os.path.join(self.package_folder, "lib"), "*.la")
rmdir(self, os.path.join(self.package_folder, "lib", "pkgconfig"))
rm(self, "*.la", os.path.join(self.package_folder, "lib"))
fix_apple_shared_install_name(self)

def package_info(self):
self.cpp_info.set_property("cmake_file_name", "fdk-aac")
Expand All @@ -167,7 +153,6 @@ def package_info(self):
self.cpp_info.filenames["cmake_find_package_multi"] = "fdk-aac"
self.cpp_info.names["cmake_find_package"] = "FDK-AAC"
self.cpp_info.names["cmake_find_package_multi"] = "FDK-AAC"
self.cpp_info.names["pkg_config"] = "fdk-aac"
self.cpp_info.components["fdk-aac"].names["cmake_find_package"] = "fdk-aac"
self.cpp_info.components["fdk-aac"].names["cmake_find_package_multi"] = "fdk-aac"
self.cpp_info.components["fdk-aac"].set_property("cmake_target_name", "FDK-AAC::fdk-aac")
11 changes: 4 additions & 7 deletions recipes/libfdk_aac/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

include(${CMAKE_BINARY_DIR}/conanbuildinfo.cmake)
conan_basic_setup(TARGETS)
cmake_minimum_required(VERSION 3.8)
project(test_package LANGUAGES C)

find_package(fdk-aac REQUIRED CONFIG)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} FDK-AAC::fdk-aac)
set_property(TARGET ${PROJECT_NAME} PROPERTY C_STANDARD 99)
target_link_libraries(${PROJECT_NAME} PRIVATE FDK-AAC::fdk-aac)
target_compile_features(${PROJECT_NAME} PRIVATE c_std_99)
28 changes: 14 additions & 14 deletions recipes/libfdk_aac/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
from conans import ConanFile, CMake, tools
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", "compiler", "build_type", "arch"
generators = "cmake", "cmake_find_package_multi"
settings = "os", "arch", "compiler", "build_type"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"
test_type = "explicit"

def build_requirements(self):
if self.settings.os == "Macos" and self.settings.arch == "armv8":
# Workaround for CMake bug with error message:
# Attempting to use @rpath without CMAKE_SHARED_LIBRARY_RUNTIME_C_FLAG being
# set. This could be because you are using a Mac OS X version less than 10.5
# or because CMake's platform configuration is corrupt.
# FIXME: Remove once CMake on macOS/M1 CI runners is upgraded.
self.build_requires("cmake/3.22.0")
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 not tools.cross_building(self, skip_x64_x86=True):
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")
8 changes: 8 additions & 0 deletions recipes/libfdk_aac/all/test_v1_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
cmake_minimum_required(VERSION 3.1)
project(test_package)

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

add_subdirectory(${CMAKE_CURRENT_SOURCE_DIR}/../test_package
${CMAKE_CURRENT_BINARY_DIR}/test_package)
17 changes: 17 additions & 0 deletions recipes/libfdk_aac/all/test_v1_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
from conans import ConanFile, CMake, tools
import os


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

def build(self):
cmake = CMake(self)
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)