flac/1.3.3

Free Lossless Audio Codec
GPL-2.0-or-later
License
1.3.3
Version
8,903
Downloads
Loading...
Loading...
1
from conans import ConanFile, tools, CMake
2
import os
3
4
required_conan_version = ">=1.33.0"
5
6
7
class FlacConan(ConanFile):
8
    name = "flac"
9
    description = "Free Lossless Audio Codec"
10
    topics = ("conan", "flac", "codec", "audio", )
11
    url = "https://github.com/conan-io/conan-center-index"
12
    homepage = "https://github.com/xiph/flac"
13
    license = ("BSD-3-Clause", "GPL-2.0-or-later", "LPGL-2.1-or-later", "GFDL-1.2")
14
    exports_sources = ["CMakeLists.txt", "patches/*"]
15
16
    generators = "cmake", "cmake_find_package"
17
    settings = "os", "compiler", "build_type", "arch"
18
    options = {
19
        "shared": [True, False],
20
        "fPIC": [True, False],
21
    }
22
    default_options = {
23
        "shared": False,
24
        "fPIC": True,
25
    }
26
27
    _cmake = None
28
29
    @property
30
    def _source_subfolder(self):
31
        return "source_subfolder"
32
33
    def config_options(self):
34
        if self.settings.os == "Windows":
35
            del self.options.fPIC
36
37
    def configure(self):
38
        if self.options.shared:
39
            del self.options.fPIC
40
41
    def requirements(self):
42
        self.requires("ogg/1.3.4")
43
44
    def build_requirements(self):
45
        self.build_requires("nasm/2.14")
46
47
    def source(self):
48
        tools.get(**self.conan_data["sources"][self.version],
49
                  destination=self._source_subfolder, strip_root=True)
50
51
    def _configure_cmake(self):
52
        if self._cmake:
53
            return self._cmake
54
        self._cmake = CMake(self)
55
        self._cmake.definitions["BUILD_EXAMPLES"] = False
56
        self._cmake.definitions["BUILD_DOCS"] = False
57
        self._cmake.definitions["BUILD_TESTING"] = False
58
        self._cmake.configure()
59
        return self._cmake
60
61
    def build(self):
62
        for patch in self.conan_data.get("patches", {}).get(self.version, []):
63
            tools.patch(**patch)
64
        cmake = self._configure_cmake()
65
        cmake.build()
66
67
    def package(self):
68
        cmake = self._configure_cmake()
69
        cmake.install()
70
        self.copy(pattern="COPYING.*", dst="licenses", src=self._source_subfolder, keep_path=False)
71
        self.copy(pattern="*.h", dst=os.path.join("include", "share"), src=os.path.join(self._source_subfolder, "include", "share"), keep_path=False)
72
        self.copy(pattern="*.h", dst=os.path.join("include", "share", "grabbag"),
73
                  src=os.path.join(self._source_subfolder, "include", "share", "grabbag"), keep_path=False)
74
        tools.rmdir(os.path.join(self.package_folder, "share"))
75
76
    def package_info(self):
77
        self.cpp_info.filenames["cmake_find_package"] = "flac"
78
        self.cpp_info.filenames["cmake_find_package_multi"] = "flac"
79
        self.cpp_info.names["cmake_find_package"] = "FLAC"
80
        self.cpp_info.names["cmake_find_package_multi"] = "FLAC"
81
82
        self.cpp_info.components["libflac"].libs = ["FLAC"]
83
        self.cpp_info.components["libflac"].names["cmake_find_package"] = "FLAC"
84
        self.cpp_info.components["libflac"].names["cmake_find_package_multi"] = "FLAC"
85
        self.cpp_info.components["libflac"].names["pkg_config"] = "flac"
86
        self.cpp_info.components["libflac"].requires = ["ogg::ogg"]
87
88
        self.cpp_info.components["libflac++"].libs = ["FLAC++"]
89
        self.cpp_info.components["libflac++"].requires = ["libflac"]
90
        self.cpp_info.components["libflac++"].names["cmake_find_package"] = "FLAC++"
91
        self.cpp_info.components["libflac++"].names["cmake_find_package_multi"] = "FLAC++"
92
        self.cpp_info.components["libflac++"].names["pkg_config"] = "flac++"
93
        if not self.options.shared:
94
            self.cpp_info.components["libflac"].defines = ["FLAC__NO_DLL"]
95
            if self.settings.os == "Linux":
96
                self.cpp_info.components["libflac"].system_libs += ["m"]
97
98
        bin_path = os.path.join(self.package_folder, "bin")
99
        self.output.info("Appending PATH environment variable: {}".format(bin_path))
100
        self.env_info.PATH.append(bin_path)
101
102