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
8,903
Downloads
Loading...
Loading...
1
from conans import ConanFile, tools, CMake
2
import os
3
4
required_conan_version = ">=1.43.0"
5
6
7
class FlacConan(ConanFile):
8
    name = "flac"
9
    description = "Free Lossless Audio Codec"
10
    topics = ("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
15
    settings = "os", "arch", "compiler", "build_type"
16
    options = {
17
        "shared": [True, False],
18
        "fPIC": [True, False],
19
    }
20
    default_options = {
21
        "shared": False,
22
        "fPIC": True,
23
    }
24
25
    generators = "cmake", "cmake_find_package"
26
    _cmake = None
27
28
    @property
29
    def _source_subfolder(self):
30
        return "source_subfolder"
31
32
    def export_sources(self):
33
        self.copy("CMakeLists.txt")
34
        for patch in self.conan_data.get("patches", {}).get(self.version, []):
35
            self.copy(patch["patch_file"])
36
37
    def config_options(self):
38
        if self.settings.os == "Windows":
39
            del self.options.fPIC
40
41
    def configure(self):
42
        if self.options.shared:
43
            del self.options.fPIC
44
45
    def requirements(self):
46
        self.requires("ogg/1.3.5")
47
48
    def build_requirements(self):
49
        if self.settings.arch in ["x86", "x86_64"]:
50
            self.build_requires("nasm/2.15.05")
51
52
    def source(self):
53
        tools.get(**self.conan_data["sources"][self.version],
54
                  destination=self._source_subfolder, strip_root=True)
55
56
    def _configure_cmake(self):
57
        if self._cmake:
58
            return self._cmake
59
        self._cmake = CMake(self)
60
        self._cmake.definitions["BUILD_EXAMPLES"] = False
61
        self._cmake.definitions["BUILD_DOCS"] = False
62
        self._cmake.definitions["BUILD_TESTING"] = False
63
        self._cmake.configure()
64
        return self._cmake
65
66
    def build(self):
67
        for patch in self.conan_data.get("patches", {}).get(self.version, []):
68
            tools.patch(**patch)
69
        cmake = self._configure_cmake()
70
        cmake.build()
71
72
    def package(self):
73
        cmake = self._configure_cmake()
74
        cmake.install()
75
        self.copy(pattern="COPYING.*", dst="licenses", src=self._source_subfolder, keep_path=False)
76
        self.copy(pattern="*.h", dst=os.path.join("include", "share"), src=os.path.join(self._source_subfolder, "include", "share"), keep_path=False)
77
        self.copy(pattern="*.h", dst=os.path.join("include", "share", "grabbag"),
78
                  src=os.path.join(self._source_subfolder, "include", "share", "grabbag"), keep_path=False)
79
        tools.rmdir(os.path.join(self.package_folder, "share"))
80
81
    def package_info(self):
82
        self.cpp_info.set_property("cmake_file_name", "flac")
83
84
        self.cpp_info.components["libflac"].set_property("cmake_target_name", "FLAC::FLAC")
85
        self.cpp_info.components["libflac"].set_property("pkg_config_name", "flac")
86
        self.cpp_info.components["libflac"].libs = ["FLAC"]
87
        self.cpp_info.components["libflac"].requires = ["ogg::ogg"]
88
89
        self.cpp_info.components["libflac++"].set_property("cmake_target_name", "FLAC::FLAC++")
90
        self.cpp_info.components["libflac++"].set_property("pkg_config_name", "flac++")
91
        self.cpp_info.components["libflac++"].libs = ["FLAC++"]
92
        self.cpp_info.components["libflac++"].requires = ["libflac"]
93
        if not self.options.shared:
94
            self.cpp_info.components["libflac"].defines = ["FLAC__NO_DLL"]
95
            if self.settings.os in ["Linux", "FreeBSD"]:
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
        # TODO: to remove in conan v2 once cmake_find_package_* generators removed
103
        self.cpp_info.filenames["cmake_find_package"] = "flac"
104
        self.cpp_info.filenames["cmake_find_package_multi"] = "flac"
105
        self.cpp_info.names["cmake_find_package"] = "FLAC"
106
        self.cpp_info.names["cmake_find_package_multi"] = "FLAC"
107
        self.cpp_info.components["libflac"].names["cmake_find_package"] = "FLAC"
108
        self.cpp_info.components["libflac"].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
112