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

libalsa: conan v2 support #12824

Merged
merged 1 commit into from
Sep 6, 2022
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
1 change: 0 additions & 1 deletion recipes/libalsa/all/conandata.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,3 @@ sources:
patches:
"1.2.5.1":
- patch_file: "patches/1.2.5.1-0001-control-empty-fix-the-static-build.patch"
base_path: "source_subfolder"
87 changes: 45 additions & 42 deletions recipes/libalsa/all/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
from conans import AutoToolsBuildEnvironment, ConanFile, tools
from conans.errors import ConanInvalidConfiguration
from conan import ConanFile
from conan.errors import ConanInvalidConfiguration
from conan.tools.env import VirtualBuildEnv
from conan.tools.files import apply_conandata_patches, chdir, copy, get, rm, rmdir
from conan.tools.gnu import Autotools, AutotoolsToolchain
from conan.tools.layout import basic_layout
from conan.tools.microsoft import unix_path
import os

required_conan_version = ">=1.43.0"
required_conan_version = ">=1.50.0"


class LibalsaConan(ConanFile):
Expand All @@ -14,7 +19,7 @@ class LibalsaConan(ConanFile):
description = "Library of ALSA: The Advanced Linux Sound Architecture, that provides audio " \
"and MIDI functionality to the Linux operating system"

settings = "os", "compiler", "build_type", "arch"
settings = "os", "arch", "compiler", "build_type"
options = {
"shared": [True, False],
"fPIC": [True, False],
Expand All @@ -26,65 +31,63 @@ class LibalsaConan(ConanFile):
"disable_python": True,
}

_autotools = None

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

def export_sources(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
self.copy(patch["patch_file"])
for p in self.conan_data.get("patches", {}).get(self.version, []):
copy(self, p["patch_file"], self.recipe_folder, self.export_sources_folder)

def configure(self):
if self.options.shared:
del self.options.fPIC
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
try:
del self.settings.compiler.libcxx
except Exception:
pass
try:
del self.settings.compiler.cppstd
except Exception:
pass

def validate(self):
if self.settings.os != "Linux":
raise ConanInvalidConfiguration("Only Linux supported")

def build_requirements(self):
self.build_requires("libtool/2.4.6")
self.tool_requires("libtool/2.4.7")

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

def _configure_autotools(self):
if self._autotools:
return self._autotools
def source(self):
get(self, **self.conan_data["sources"][self.version],
destination=self.source_folder, strip_root=True)

self._autotools = AutoToolsBuildEnvironment(self)
def generate(self):
tc = AutotoolsToolchain(self)
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)),
"--enable-python={}".format(yes_no(not self.options.disable_python)),
"--datarootdir={}".format(tools.unix_path(os.path.join(self.package_folder, "res"))),
]
self._autotools.configure(args=args)
return self._autotools
tc.configure_args.extend([
f"--enable-python={yes_no(not self.options.disable_python)}",
"--datarootdir=${prefix}/res",
"--datadir=${prefix}/res",
])
tc.generate()
env = VirtualBuildEnv(self)
env.generate()

def build(self):
for patch in self.conan_data.get("patches", {}).get(self.version, []):
tools.patch(**patch)
with tools.chdir(self._source_subfolder):
self.run("{} -fiv".format(tools.get_env("AUTORECONF")), run_environment=True)

autotools = self._configure_autotools()
apply_conandata_patches(self)
with chdir(self, self.source_folder):
autotools = Autotools(self)
autotools.autoreconf()
autotools.configure()
autotools.make()

def package(self):
self.copy("COPYING", dst="licenses", src=self._source_subfolder)
with tools.chdir(self._source_subfolder):
autotools = self._configure_autotools()
copy(self, "COPYING", src=self.source_folder, dst=os.path.join(self.package_folder, "licenses"))
with chdir(self, self.source_folder):
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"))

def package_info(self):
self.cpp_info.set_property("cmake_find_mode", "both")
Expand Down
7 changes: 2 additions & 5 deletions recipes/libalsa/all/test_package/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
cmake_minimum_required(VERSION 3.1)
project(test_package C)

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

find_package(ALSA REQUIRED)

add_executable(${PROJECT_NAME} test_package.c)
target_link_libraries(${PROJECT_NAME} ALSA::ALSA)
target_link_libraries(${PROJECT_NAME} PRIVATE ALSA::ALSA)
18 changes: 13 additions & 5 deletions recipes/libalsa/all/test_package/conanfile.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,25 @@
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", "arch", "compiler", "build_type"
generators = "cmake", "cmake_find_package"
generators = "CMakeToolchain", "CMakeDeps", "VirtualRunEnv"

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 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/libalsa/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)
project(test_package LANGUAGES C)

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

find_package(ALSA REQUIRED)

add_executable(${PROJECT_NAME} ../test_package/test_package.c)
target_link_libraries(${PROJECT_NAME} PRIVATE ALSA::ALSA)
17 changes: 17 additions & 0 deletions recipes/libalsa/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"

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)