README: Add a screenshot showing how to run meson on windows
[platform/upstream/gstreamer.git] / README.md
1 # gst-build
2
3 GStreamer [meson](http://mesonbuild.com/) based repositories aggregrator.
4
5 Check out this module and run meson on it, and it will git clone the other
6 GStreamer modules as [meson subprojects](http://mesonbuild.com/Subprojects.html)
7 and build everything in one go. Once that is done you can switch into an
8 development environment which allows you to easily develop and test the latest
9 version of GStreamer without the need to install anything or touch an existing
10 GStreamer system installation.
11
12 ## Getting started
13
14 ### Install git and python 3.5+
15
16 If you're on Linux, you probably already have these. On macOS, you can use the
17 [official Python installer](https://www.python.org/downloads/mac-osx/).
18
19 You can find [instructions for Windows below](#windows-prerequisites-setup).
20
21 ### Install meson and ninja
22
23 Meson 0.48 or newer is required.
24
25 On Linux and macOS you can get meson through your package manager or using:
26
27   $ pip3 install --user meson
28
29 This will install meson into `~/.local/bin` which may or may not be included
30 automatically in your PATH by default.
31
32 You should get `ninja` using your package manager or download the [official
33 release](https://github.com/ninja-build/ninja/releases) and put the `ninja`
34 binary in your PATH.
35
36 You can find [instructions for Windows below](#windows-prerequisites-setup).
37
38 ### Build GStreamer and its modules
39
40 You can get all GStreamer built running:
41
42 ```
43 meson builddir
44 ninja -C builddir
45 ```
46
47 This will automatically create the `build` directory and build everything
48 inside it.
49
50 NOTE: On Windows, you *must* run this from [inside the Visual Studio command
51 prompt](#running-meson-on-windows) of the appropriate architecture and version.
52
53 ### External dependencies
54
55 All mandatory dependencies of GStreamer are included as [meson subprojects](https://mesonbuild.com/Subprojects.html):
56 libintl, zlib, libffi, glib. Some optional dependencies are also included as
57 subprojects, such as ffmpeg, x264, json-glib, graphene, openh264, orc, etc.
58
59 Mandatory dependencies will be automatically built if meson cannot find them on
60 your system using pkg-config. The same is true for optional dependencies that
61 are included as subprojects. You can find a full list by looking at the
62 `subprojects` directory.
63
64 Plugins that need optional dependencies that aren't included can only be built
65 if they are provided by the system. Instructions on how to build some common
66 ones such as Qt5/QML are listed below. If you do not know how to provide an
67 optional dependency needed by a plugin, you should use [Cerbero](https://gitlab.freedesktop.org/gstreamer/cerbero/#description)
68 which handles this for you automatically.
69
70 Plugins will be automatically enabled if possible, but you can ensure that
71 a particular plugin (especially if it has external dependencies) is built by
72 enabling the gstreamer repository that ships it and the plugin inside it. For
73 example, to enable the Qt5 plugin in the gst-plugins-good repository, you need
74 to run meson as follows:
75
76 ```
77 meson -Dgood=enabled -Dgst-plugins-good:qt5=enabled builddir
78 ```
79
80 This will cause Meson to error out if the plugin could not be enabled. You can
81 also flip the default and disable all plugins except those explicitly enabled
82 like so:
83
84 ```
85 meson -Dauto_features=disabled -Dgstreamer:tools=enabled -Dbad=enabled -Dgst-plugins-bad:openh264=enabled
86 ```
87
88 This will disable all optional features and then enable the `openh264` plugin
89 and the tools that ship with the core gstreamer repository: `gst-inspect-1.0`,
90 `gst-launch-1.0`, etc. As usual, you can change these values on a builddir that
91 has already been setup with `meson configure -Doption=value`.
92
93 ### Building the Qt5 QML plugin
94
95 If `qmake` is not in `PATH` and pkgconfig files are not available, you can
96 point the `QMAKE` env var to the Qt5 installation of your choosing before
97 running `meson` as shown above.
98
99 The plugin will be automatically enabled if possible, but you can ensure that
100 it is built by passing `-Dgood=enabled -Dgst-plugins-good:qt5=enabled` to `meson`.
101
102 ### Building the Intel MSDK plugin
103
104 On Linux, you need to have development files for `libmfx` installed. On
105 Windows, if you have the [Intel Media SDK](https://software.intel.com/en-us/media-sdk),
106 it will set the `INTELMEDIASDKROOT` environment variable, which will be used by
107 the build files to find `libmfx`.
108
109 The plugin will be automatically enabled if possible, but you can ensure it by
110 passing `-Dbad=enabled -Dgst-plugins-bad:msdk=enabled` to `meson`.
111
112 # Development environment
113
114 ## Development environment target
115
116 gst-build also contains a special `devenv` target that lets you enter an
117 development environment where you will be able to work on GStreamer
118 easily. You can get into that environment running:
119
120 ```
121 ninja -C builddir devenv
122 ```
123
124 If your operating system handles symlinks, built modules source code will be
125 available at the root of `gst-build/` for example GStreamer core will be in
126 `gstreamer/`. Otherwise they will be present in `subprojects/`. You can simply
127 hack in there and to rebuild you just need to rerun `ninja -C builddir`.
128
129 NOTE: In the development environment, a fully usable prefix is also configured
130 in `gst-build/prefix` where you can install any extra dependency/project.
131
132 An external script can be run in development environment with:
133
134 ```
135 ./gst-env.py external_script.sh
136 ```
137
138 ## Update git subprojects
139
140 We added a special `update` target to update subprojects (it uses `git pull
141 --rebase` meaning you should always make sure the branches you work on are
142 following the right upstream branch, you can set it with `git branch
143 --set-upstream-to origin/master` if you are working on `gst-build` master
144 branch).
145
146 Update all GStreamer modules and rebuild:
147
148 ```
149 ninja -C builddir update
150 ```
151
152 Update all GStreamer modules without rebuilding:
153
154 ```
155 ninja -C builddir git-update
156 ```
157
158 ## Custom subprojects
159
160 We also added a meson option, `custom_subprojects`, that allows the user
161 to provide a comma-separated list of subprojects that should be built
162 alongside the default ones.
163
164 To use it:
165
166 ```
167 cd subprojects
168 git clone my_subproject
169 cd ../build
170 rm -rf * && meson .. -Dcustom_subprojects=my_subproject
171 ninja
172 ```
173
174 ## Run tests
175
176 You can easily run the test of all the components:
177
178 ```
179 meson test -C build
180 ```
181
182 To list all available tests:
183
184 ```
185 meson test -C builddir --list
186 ```
187
188 To run all the tests of a specific component:
189
190 ```
191 meson test -C builddir --suite gst-plugins-base
192 ```
193
194 Or to run a specific test file:
195
196 ```
197 meson test -C builddir --suite gstreamer gst_gstbuffer
198 ```
199
200 Run a specific test from a specific test file:
201
202 ```
203 GST_CHECKS=test_subbuffer meson test -C builddir --suite gstreamer gst_gstbuffer
204 ```
205
206 ## Optional Installation
207
208 `gst-build` has been created primarily for [development usage](#development-environment-target),
209 but you can also install everything that is built into a predetermined prefix like so:
210
211 ```
212 meson --prefix=/path/to/install/prefix builddir
213 ninja -C builddir
214 meson install -C builddir
215 ```
216
217 Note that the installed files have `RPATH` stripped, so you will need to set
218 `LD_LIBRARY_PATH`, `DYLD_LIBRARY_PATH`, or `PATH` as appropriate for your
219 platform for things to work.
220
221 ## Checkout another branch using worktrees
222
223 If you need to have several versions of GStreamer coexisting (eg. `master` and `1.16`),
224 you can use the `gst-worktree.py` script provided by `gst-build`. It allows you
225 to create a new `gst-build` environment with new checkout of all the GStreamer modules as
226 [git worktrees](https://git-scm.com/docs/git-worktree).
227
228 For example to get a fresh checkout of `gst-1.16` from a `gst-build` repository
229 that is checked out at master, you can run:
230
231 ```
232 ./gst-worktree.py add gst-build-1.16 origin/1.16
233 ```
234
235 This will create a new ``gst-build-1.16`` directory pointing to the given branch `1.16`
236 for all the subprojects (gstreamer, gst-plugins-base, etc.)
237
238
239 ## Add information about GStreamer development environment in your prompt line
240
241 ### Bash prompt
242
243 We automatically handle `bash` and set `$PS1` accordingly.
244
245 If the automatic `$PS1` override is not desired (maybe you have a fancy custom prompt), set the `$GST_BUILD_DISABLE_PS1_OVERRIDE` environment variable to `TRUE` and use `$GST_ENV` when setting the custom prompt, for example with a snippet like the following:
246
247 ```bash
248 ...
249 if [[ -n "${GST_ENV-}" ]];
250 then
251   PS1+="[ ${GST_ENV} ]"
252 fi
253 ...
254 ```
255
256 ### Using powerline
257
258 In your powerline theme configuration file (by default in
259 `{POWERLINE INSTALLATION DIR}/config_files/themes/shell/default.json`)
260 you should add a new environment segment as follow:
261
262 ```
263 {
264   "function": "powerline.segments.common.env.environment",
265   "args": { "variable": "GST_ENV" },
266   "priority": 50
267 },
268 ```
269
270 ## Windows Prerequisites Setup
271
272 On Windows, some of the components may require special care.
273
274 ### Git for Windows
275
276 Use the [Git for Windows](https://gitforwindows.org/) installer. It will
277 install a `bash` prompt with basic shell utils and up-to-date git binaries.
278
279 During installation, when prompted about `PATH`, you should select the
280 following option:
281
282 ![Select "Git from the command line and also from 3rd-party software"](/data/images/git-installer-PATH.png)
283
284 ### Python 3.5+ on Windows
285
286 Use the [official Python installer](https://www.python.org/downloads/windows/).
287 You must ensure that Python is installed into `PATH`:
288
289 ![Enable Add Python to PATH, then click Customize Installation](/data/images/py-installer-page1.png)
290
291 You may also want to customize the installation and install it into
292 a system-wide location such as `C:\PythonXY`, but this is not required.
293
294 ### Ninja on Windows
295
296 The easiest way to install Ninja on Windows is with `pip3`, which will download
297 the compiled binary and place it into the `Scripts` directory inside your
298 Python installation:
299
300 ```
301 pip3 install ninja
302 ```
303
304 You can also download the [official release](https://github.com/ninja-build/ninja/releases)
305 and place it into `PATH`.
306
307 ### Meson on Windows
308
309 **IMPORTANT**: Do not use the Meson MSI installer since it is experimental and known to not
310 work with `gst-build`.
311
312 You can use `pip3` to install Meson, same as Ninja above:
313
314 ```
315 pip3 install meson
316 ```
317
318 Note that Meson is written entirely in Python, so you can also run it as-is
319 from the [git repository](https://github.com/mesonbuild/meson/) if you want to
320 use the latest master branch for some reason.
321
322 ### Running Meson on Windows
323
324 At present, to build with Visual Studio, you need to run Meson from inside the
325 VS 2019 command prompt. Press `Start`, and search for `VS 2019`, and click on
326 `x64 Native Tools Command Prompt for VS 2019`, or a prompt named similar to
327 that:
328
329 ![x64 Native Tools Command Prompt for VS 2019](/data/images/vs-2019-dev-prompt.png)
330
331
332 ### Setup a mingw/wine based development environment on linux
333
334 #### Install wine and mingw
335
336 ##### On fedora x64
337
338 ``` sh
339 sudo dnf install mingw64-gcc mingw64-gcc-c++ mingw64-pkg-config mingw64-winpthreads wine
340 ```
341
342 FIXME: Figure out what needs to be installed on other distros
343
344 #### Get meson from git
345
346 This simplifies the process and allows us to use the cross files
347 defined in meson itself.
348
349 ``` sh
350 git clone https://github.com/mesonbuild/meson.git
351 ```
352
353 #### Build and install
354
355 ```
356 BUILDDIR=$PWD/winebuild/
357 export WINEPREFIX=$BUILDDIR/wine-prefix/ && mkdir -p $WINEPREFIX
358 # Setting the prefix is mandatory as it is used to setup symlinks during uninstalled development
359 meson/meson.py $BUILDDIR --cross-file meson/cross/linux-mingw-w64-64bit.txt -Dgst-plugins-bad:vulkan=disabled -Dorc:gtk_doc=disabled --prefix=$BUILDDIR/wininstall/ -Djson-glib:gtk_doc=disabled
360 meson/meson.py install -C $BUILDDIR/
361 ```
362
363 > __NOTE__: You should use `meson install -C $BUILDDIR`  each time you make a change
364 > instead of the usual `ninja -C build` as the environment is not uninstalled.
365
366 #### The development environment
367
368 You can get into the development environment the usual way:
369
370 ```
371 ninja -C $BUILDDIR/ devenv
372 ```
373
374 Alternatively, if you'd rather not start a shell in your workflow, you
375 can mutate the current environment into a suitable state like so:
376
377 ```
378 gst-env.py --only-environment
379 ```
380
381 This will print output suitable for an sh-compatible `eval` function,
382 just like `ssh-agent -s`.
383
384 After setting up [binfmt] to use wine for windows binaries,
385 you can run GStreamer tools under wine by running:
386
387 ```
388 gst-launch-1.0.exe videotestsrc ! glimagesink
389 ```
390
391 [binfmt]: http://man7.org/linux/man-pages/man5/binfmt.d.5.html