meson: Add build_rpath for qt5 plugin on macOS
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-good / ext / qt / meson.build
1 sources = [
2   'gstplugin.cc',
3   'gstqtelement.cc',
4   'gstqsgtexture.cc',
5   'gstqtglutility.cc',
6   'gstqtoverlay.cc',
7   'gstqtsink.cc',
8   'gstqtsrc.cc',
9   'qtglrenderer.cc',
10   'qtitem.cc',
11   'qtwindow.cc',
12 ]
13
14 moc_headers = [
15   'qtitem.h',
16   'qtwindow.h',
17   'gstqsgtexture.h',
18   'qtglrenderer.h',
19 ]
20
21 # Define a not-found dependency so this variable is always defined when we're
22 # deciding whether to build the qt5 examples
23 qt5qml_dep = dependency('', required: false)
24 qt5_option = get_option('qt5')
25 qt5_method = get_option('qt-method')
26
27 if qt5_option.disabled()
28   subdir_done()
29 endif
30
31 if not have_gstgl
32   if qt5_option.enabled()
33     error('qt5 qmlglsink plugin is enabled, but gstreamer-gl-1.0 was not found')
34   endif
35   subdir_done()
36 endif
37
38 if not add_languages('cpp', native: false, required: qt5_option)
39   subdir_done()
40 endif
41
42 qt5_mod = import('qt5')
43 qt5qml_dep = dependency('qt5', modules : ['Core', 'Gui', 'Qml', 'Quick'],
44                         method: qt5_method, required: qt5_option, static: host_system == 'ios')
45
46 # On Linux, distros often have the Qt5 pkg-config files and moc in separate
47 # packages, so the user may not have both installed. Check for moc and ensure
48 # that it's installed.
49 # We don't do this check on other OSes because they need to be able to simply
50 # point the `QMAKE` env var to `qmake` to build against a particular Qt5.
51 if host_system == 'linux' and not meson.is_cross_build()
52   moc = find_program('moc-qt5', 'moc', required : qt5_option)
53 else
54   # We only check if `moc` was found, and then discard it, so we can fake it.
55   # This is also a good unit test of the fact that we *don't* use it.
56   moc = declare_dependency()
57 endif
58
59 if not qt5qml_dep.found() or not moc.found()
60   subdir_done()
61 endif
62
63 optional_deps = []
64 qt_defines = []
65 have_qpa_include = false
66 have_qt_windowing = false
67
68 # Look for the QPA platform native interface header
69 qpa_header_path = join_paths(qt5qml_dep.version(), 'QtGui')
70 qpa_header = join_paths(qpa_header_path, 'qpa/qplatformnativeinterface.h')
71 if cxx.has_header(qpa_header, dependencies : qt5qml_dep)
72   qt_defines += '-DHAVE_QT_QPA_HEADER'
73   qt_defines += '-DQT_QPA_HEADER=' + '<@0@>'.format(qpa_header)
74   have_qpa_include = true
75   message('Found QtGui QPA header in ' + qpa_header_path)
76 endif
77
78 # Try to come up with all the platform/winsys combinations that will work
79
80 if gst_gl_have_window_x11 and gst_gl_have_platform_glx
81   # FIXME: automagic
82   qt5x11extras = dependency('qt5', modules : ['X11Extras'], method: qt5_method, required : false)
83   if qt5x11extras.found()
84     optional_deps += [qt5x11extras, gstglx11_dep]
85     qt_defines += ['-DHAVE_QT_X11']
86     have_qt_windowing = true
87   endif
88 endif
89
90 if gst_gl_have_platform_egl
91   # Embedded linux (e.g. i.MX6) with or without windowing support
92   qt_defines += ['-DHAVE_QT_EGLFS']
93   optional_deps += gstglegl_dep
94   have_qt_windowing = true
95   if have_qpa_include
96     # Wayland windowing
97     if gst_gl_have_window_wayland
98       # FIXME: automagic
99       qt5waylandextras = dependency('qt5', modules : ['WaylandClient'], method: qt5_method, required : false)
100       if qt5waylandextras.found()
101         optional_deps += [qt5waylandextras, gstglwayland_dep]
102         qt_defines += ['-DHAVE_QT_WAYLAND']
103         have_qt_windowing = true
104       endif
105     endif
106     # Android windowing
107     if gst_gl_have_window_android
108       # FIXME: automagic
109       qt5androidextras = dependency('qt5', modules : ['AndroidExtras'], method: qt5_method, required : false)
110       # for gl functions in QtGui/qopenglfunctions.h
111       # FIXME: automagic
112       glesv2_dep = cc.find_library('GLESv2', required : false)
113       if glesv2_dep.found() and qt5androidextras.found()
114         optional_deps += [qt5androidextras, glesv2_dep]
115         qt_defines += ['-DHAVE_QT_ANDROID']
116         have_qt_windowing = true
117         # Needed for C++11 support in Cerbero. People building with Android
118         # in some other way need to add the necessary bits themselves.
119         optional_deps += dependency('gnustl', required : false)
120       endif
121     endif
122   endif
123 endif
124
125 if gst_gl_have_platform_wgl and gst_gl_have_window_win32
126   # for wglMakeCurrent()
127   # FIXME: automagic
128   opengl32_dep = cc.find_library('opengl32', required : false)
129   if opengl32_dep.found()
130     qt_defines += ['-DHAVE_QT_WIN32']
131     optional_deps += opengl32_dep
132     have_qt_windowing = true
133   endif
134 endif
135
136 if gst_gl_have_window_cocoa and gst_gl_have_platform_cgl
137   # FIXME: automagic
138   qt5macextras = dependency('qt5', modules : ['MacExtras'], method: qt5_method, required : false)
139   if qt5macextras.found()
140     qt_defines += ['-DHAVE_QT_MAC']
141     optional_deps += qt5macextras
142     have_qt_windowing = true
143   endif
144 endif
145
146 if gst_gl_have_window_eagl and gst_gl_have_platform_eagl
147   if host_machine.system() == 'ios'
148     qt_defines += ['-DHAVE_QT_IOS']
149     have_qt_windowing = true
150   endif
151 endif
152
153 if have_qt_windowing
154   # rpath is needed to be able to load the plugin on macOS inside the devenv
155   qmlgl_kwargs = {}
156   if host_system == 'darwin'
157     fs = import('fs')
158     qt_bindir = fs.parent(find_program('qmake').full_path())
159     qt_libdir = fs.parent(qt_bindir) / 'lib'
160     qmlgl_kwargs += {'build_rpath': qt_libdir}
161   endif
162
163   # Build it!
164   moc_files = qt5_mod.preprocess(moc_headers : moc_headers)
165   gstqmlgl = library('gstqmlgl', sources, moc_files,
166     cpp_args : gst_plugins_good_args + qt_defines,
167     link_args : noseh_link_args,
168     include_directories: [configinc, libsinc],
169     dependencies : [gst_dep, gstvideo_dep, gstgl_dep, gstglproto_dep, qt5qml_dep, optional_deps],
170     override_options : ['cpp_std=c++11'],
171     kwargs: qmlgl_kwargs,
172     install: true,
173     install_dir : plugins_install_dir)
174   plugins += [gstqmlgl]
175 endif