This repository has been archived by the owner on Nov 5, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
conanfile.py
145 lines (127 loc) · 6.61 KB
/
conanfile.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
from conans import ConanFile, tools, Meson, VisualStudioBuildEnvironment
import glob
import os
import shutil
class GStreamerConan(ConanFile):
name = "gstreamer"
version = "1.16.0"
description = "GStreamer is a development framework for creating applications like media players, video editors, streaming media broadcasters and so on"
topics = ("conan", "gstreamer", "multimedia", "video", "audio", "broadcasting", "framework", "media")
url = "https://github.com/bincrafters/conan-gstreamer"
homepage = "https://gstreamer.freedesktop.org/"
license = "GPL-2.0-only"
settings = "os", "arch", "compiler", "build_type"
options = {"shared": [True, False], "fPIC": [True, False]}
default_options = {"shared": True, "fPIC": True}
_source_subfolder = "source_subfolder"
_build_subfolder = "build_subfolder"
exports_sources = ["patches/*.diff"]
requires = ("glib/2.66.2",)
generators = "pkg_config"
@property
def _is_msvc(self):
return self.settings.compiler == "Visual Studio"
def configure(self):
del self.settings.compiler.libcxx
del self.settings.compiler.cppstd
def config_options(self):
if self.settings.os == 'Windows':
del self.options.fPIC
def build_requirements(self):
self.build_requires("meson/0.54.2")
if not tools.which("pkg-config") or self.settings.os == "Windows":
self.build_requires("pkgconf/1.7.3")
if self.settings.os == 'Windows':
self.build_requires("winflexbison/2.5.22")
else:
self.build_requires("bison/3.5.3")
self.build_requires("flex/2.6.4")
def source(self):
source_url = "https://gitlab.freedesktop.org/gstreamer/{n}/-/archive/{v}/{n}-{v}.tar.bz2".format(v=self.version, n=self.name)
sha256 = "57dbb3df5781840ca45da6b011deda824e025b22684b5218f167d3a9f721cf3e"
tools.get(source_url, sha256=sha256)
os.rename("%s-%s" % (self.name, self.version), self._source_subfolder)
def _apply_patches(self):
for filename in sorted(glob.glob("patches/*.diff")):
self.output.info('applying patch "%s"' % filename)
tools.patch(base_path=self._source_subfolder, patch_file=filename)
def _configure_meson(self):
meson = Meson(self)
defs = dict()
if self.settings.compiler == "Visual Studio":
if int(str(self.settings.compiler.version)) < 14:
defs["c_args"] = " -Dsnprintf=_snprintf"
defs["cpp_args"] = " -Dsnprintf=_snprintf"
if self.settings.get_safe("compiler.runtime"):
defs["b_vscrt"] = str(self.settings.compiler.runtime).lower()
defs["tools"] = "disabled"
defs["examples"] = "disabled"
defs["benchmarks"] = "disabled"
defs["tests"] = "disabled"
meson.configure(build_folder=self._build_subfolder,
source_folder=self._source_subfolder,
defs=defs, args=['--wrap-mode=nofallback'])
return meson
def _copy_pkg_config(self, name):
root = self.deps_cpp_info[name].rootpath
pc_dir = os.path.join(root, 'lib', 'pkgconfig')
pc_files = glob.glob('%s/*.pc' % pc_dir)
if not pc_files: # zlib store .pc in root
pc_files = glob.glob('%s/*.pc' % root)
for pc_name in pc_files:
new_pc = os.path.basename(pc_name)
self.output.warn('copy .pc file %s' % os.path.basename(pc_name))
shutil.copy(pc_name, new_pc)
prefix = tools.unix_path(root) if self.settings.os == 'Windows' else root
tools.replace_prefix_in_pc_file(new_pc, prefix)
def build(self):
self._apply_patches()
self._copy_pkg_config("glib")
with tools.environment_append(VisualStudioBuildEnvironment(self).vars) if self._is_msvc else tools.no_op():
meson = self._configure_meson()
meson.build()
def _fix_library_names(self, path):
# regression in 1.16
if self.settings.compiler == "Visual Studio":
with tools.chdir(path):
for filename_old in glob.glob("*.a"):
filename_new = filename_old[3:-2] + ".lib"
self.output.info("rename %s into %s" % (filename_old, filename_new))
shutil.move(filename_old, filename_new)
def package(self):
self.copy(pattern="LICENSE", dst="licenses", src=self._source_subfolder)
with tools.environment_append(VisualStudioBuildEnvironment(self).vars) if self._is_msvc else tools.no_op():
meson = self._configure_meson()
meson.install()
self._fix_library_names(os.path.join(self.package_folder, "lib"))
self._fix_library_names(os.path.join(self.package_folder, "lib", "gstreamer-1.0"))
def package_info(self):
self.cpp_info.includedirs = [os.path.join("include", "gstreamer-1.0")]
gst_plugin_path = os.path.join(self.package_folder, "lib", "gstreamer-1.0")
if self.options.shared:
self.output.info("Appending GST_PLUGIN_PATH env var : %s" % gst_plugin_path)
self.env_info.GST_PLUGIN_PATH.append(gst_plugin_path)
else:
self.cpp_info.libdirs.append(gst_plugin_path)
self.cpp_info.libs.extend(["gstcoreelements",
"gstcoretracers"])
self.cpp_info.libs.extend(["gstreamer-1.0", "gstbase-1.0", "gstcontroller-1.0", "gstnet-1.0"])
if self.settings.os == "Linux":
self.cpp_info.libs.append("dl")
elif self.settings.os == "Windows":
self.cpp_info.libs.append("ws2_32")
if not self.options.shared:
self.cpp_info.defines.append("GST_STATIC_COMPILATION")
gstreamer_root = self.package_folder
self.output.info("Creating GSTREAMER_ROOT env var : %s" % gstreamer_root)
self.env_info.GSTREAMER_ROOT = gstreamer_root
gst_plugin_scanner = "gst-plugin-scanner.exe" if self.settings.os == "Windows" else "gst-plugin-scanner"
gst_plugin_scanner = os.path.join(self.package_folder, "bin", "gstreamer-1.0", gst_plugin_scanner)
self.output.info("Creating GST_PLUGIN_SCANNER env var : %s" % gst_plugin_scanner)
self.env_info.GST_PLUGIN_SCANNER = gst_plugin_scanner
if self.settings.arch == "x86":
self.output.info("Creating GSTREAMER_ROOT_X86 env var : %s" % gstreamer_root)
self.env_info.GSTREAMER_ROOT_X86 = gstreamer_root
elif self.settings.arch == "x86_64":
self.output.info("Creating GSTREAMER_ROOT_X86_64 env var : %s" % gstreamer_root)
self.env_info.GSTREAMER_ROOT_X86_64 = gstreamer_root