flac/1.3.3

Free Lossless Audio Codec
BSD-3-Clause, GFDL-1.2, GPL-2.0-or-later, LPGL-2.1-or-later
License
1.3.3
Version
27,470
Downloads
Loading...
Loading...
1
from conan import ConanFile
2
from conan.tools.cmake import CMake, CMakeDeps, CMakeToolchain, cmake_layout
3
from conan.tools.env import VirtualBuildEnv
4
from conan.tools.files import apply_conandata_patches, copy, get, rmdir
5
import os
6
7
required_conan_version = ">=1.47.0"
8
9
10
class FlacConan(ConanFile):
11
    name = "flac"
12
    description = "Free Lossless Audio Codec"
13
    topics = ("flac", "codec", "audio", )
14
    url = "https://github.com/conan-io/conan-center-index"
15
    homepage = "https://github.com/xiph/flac"
16
    license = ("BSD-3-Clause", "GPL-2.0-or-later", "LPGL-2.1-or-later", "GFDL-1.2")
17
18
    settings = "os", "arch", "compiler", "build_type"
19
    options = {
20
        "shared": [True, False],
21
        "fPIC": [True, False],
22
    }
23
    default_options = {
24
        "shared": False,
25
        "fPIC": True,
26
    }
27
28
    def export_sources(self):
29
        for p in self.conan_data.get("patches", {}).get(self.version, []):
30
            copy(self, p["patch_file"], self.recipe_folder, self.export_sources_folder)
31
32
    def config_options(self):
33
        if self.settings.os == "Windows":
34
            del self.options.fPIC
35
36
    def configure(self):
37
        if self.options.shared:
38
            del self.options.fPIC
39
40
    def requirements(self):
41
        self.requires("ogg/1.3.5")
42
43
    def build_requirements(self):
44
        if self.settings.arch in ["x86", "x86_64"]:
45
            self.tool_requires("nasm/2.15.05")
46
47
    def layout(self):
48
        cmake_layout(self, src_folder="src")
49
50
    def source(self):
51
        get(self, **self.conan_data["sources"][self.version],
52
            destination=self.source_folder, strip_root=True)
53
54
    def generate(self):
55
        tc = CMakeToolchain(self)
56
        tc.variables["BUILD_EXAMPLES"] = False
57
        tc.variables["BUILD_DOCS"] = False
58
        tc.variables["BUILD_TESTING"] = False
59
        tc.generate()
60
        cd = CMakeDeps(self)
61
        cd.generate()
62
        if self.settings.arch in ["x86", "x86_64"]:
63
            envbuild = VirtualBuildEnv(self)
64
            envbuild.generate(scope="build")
65
66
    def build(self):
67
        apply_conandata_patches(self)
68
        cmake = CMake(self)
69
        cmake.configure()
70
        cmake.build()
71
72
    def package(self):
73
        cmake = CMake(self)
74
        cmake.install()
75
        copy(self, "COPYING.*", src=self.source_folder,
76
                                dst=os.path.join(self.package_folder, "licenses"), keep_path=False)
77
        copy(self, "*.h", src=os.path.join(self.source_folder, "include", "share"),
78
                          dst=os.path.join(self.package_folder, "include", "share"), keep_path=False)
79
        copy(self, "*.h", src=os.path.join(self.source_folder, "include", "share", "grabbag"),
80
                          dst=os.path.join(self.package_folder, "include", "share", "grabbag"), keep_path=False)
81
        rmdir(self, os.path.join(self.package_folder, "share"))
82
83
    def package_info(self):
84
        self.cpp_info.set_property("cmake_file_name", "flac")
85
86
        self.cpp_info.components["libflac"].set_property("cmake_target_name", "FLAC::FLAC")
87
        self.cpp_info.components["libflac"].set_property("pkg_config_name", "flac")
88
        self.cpp_info.components["libflac"].libs = ["FLAC"]
89
        self.cpp_info.components["libflac"].requires = ["ogg::ogg"]
90
91
        self.cpp_info.components["libflac++"].set_property("cmake_target_name", "FLAC::FLAC++")
92
        self.cpp_info.components["libflac++"].set_property("pkg_config_name", "flac++")
93
        self.cpp_info.components["libflac++"].libs = ["FLAC++"]
94
        self.cpp_info.components["libflac++"].requires = ["libflac"]
95
        if not self.options.shared:
96
            self.cpp_info.components["libflac"].defines = ["FLAC__NO_DLL"]
97
            if self.settings.os in ["Linux", "FreeBSD"]:
98
                self.cpp_info.components["libflac"].system_libs += ["m"]
99
100
        bin_path = os.path.join(self.package_folder, "bin")
101
        self.output.info("Appending PATH environment variable: {}".format(bin_path))
102
        self.env_info.PATH.append(bin_path)
103
104
        # TODO: to remove in conan v2 once cmake_find_package_* generators removed
105
        self.cpp_info.filenames["cmake_find_package"] = "flac"
106
        self.cpp_info.filenames["cmake_find_package_multi"] = "flac"
107
        self.cpp_info.names["cmake_find_package"] = "FLAC"
108
        self.cpp_info.names["cmake_find_package_multi"] = "FLAC"
109
        self.cpp_info.components["libflac"].names["cmake_find_package"] = "FLAC"
110
        self.cpp_info.components["libflac"].names["cmake_find_package_multi"] = "FLAC"
111
        self.cpp_info.components["libflac++"].names["cmake_find_package"] = "FLAC++"
112
        self.cpp_info.components["libflac++"].names["cmake_find_package_multi"] = "FLAC++"
113
114