meson: Streamline the way we detect when to build documentation
[platform/upstream/gstreamer.git] / subprojects / gst-plugins-bad / docs / meson.build
1 build_hotdoc = false
2
3 if meson.is_cross_build()
4     if get_option('doc').enabled()
5         error('Documentation enabled but building the doc while cross building is not supported yet.')
6     endif
7
8     message('Documentation not built as building it while cross building is not supported yet.')
9     subdir_done()
10 endif
11
12 if static_build
13     if get_option('doc').enabled()
14         error('Documentation enabled but not supported when building statically.')
15     endif
16
17     message('Building statically, can\'t build the documentation')
18     subdir_done()
19 endif
20
21 if not build_gir
22     if get_option('doc').enabled()
23         error('Documentation enabled but introspection not built.')
24     endif
25
26     message('Introspection not built, won\'t build documentation requiring it')
27 endif
28
29 required_hotdoc_extensions = ['gi-extension', 'c-extension', 'gst-extension']
30 if gst_dep.type_name() == 'internal'
31     gst_proj = subproject('gstreamer')
32     plugins_cache_generator = gst_proj.get_variable('plugins_cache_generator')
33 else
34     plugins_cache_generator = find_program(join_paths(gst_dep.get_pkgconfig_variable('libexecdir'), 'gstreamer-' + api_version, 'gst-plugins-doc-cache-generator'),
35         required: false)
36 endif
37
38 plugins_cache = join_paths(meson.current_source_dir(), 'plugins', 'gst_plugins_cache.json')
39
40 if plugins.length() == 0
41     message('All bad plugins have been disabled')
42 elif plugins_cache_generator.found()
43     plugins_doc_dep = custom_target('bad-plugins-doc-cache',
44         command: [plugins_cache_generator, plugins_cache, '@OUTPUT@', '@INPUT@'],
45         input: plugins,
46         output: 'gst_plugins_cache.json',
47         build_always_stale: true,
48     )
49 else
50     warning('GStreamer plugin inspector for documentation not found, can\'t update the cache')
51 endif
52
53 hotdoc_p = find_program('hotdoc', required: get_option('doc'))
54 if not hotdoc_p.found()
55     message('Hotdoc not found, not building the documentation')
56     subdir_done()
57 endif
58
59 hotdoc_req = '>= 0.11.0'
60 hotdoc_version = run_command(hotdoc_p, '--version').stdout()
61 if not hotdoc_version.version_compare(hotdoc_req)
62     if get_option('doc').enabled()
63         error('Hotdoc version @0@ not found, got @1@'.format(hotdoc_req, hotdoc_version))
64     else
65         message('Hotdoc version @0@ not found, got @1@'.format(hotdoc_req, hotdoc_version))
66         subdir_done()
67     endif
68 endif
69
70 hotdoc = import('hotdoc')
71 foreach extension: required_hotdoc_extensions
72     if not hotdoc.has_extensions(extension)
73         if get_option('doc').enabled()
74             error('Documentation enabled but @0@ missing'.format(extension))
75         endif
76
77         message('@0@ extensions not found, not building documentation requiring it'.format(extension))
78     endif
79 endforeach
80
81 build_hotdoc = true
82
83 docconf = configuration_data()
84 docconf.set('GST_API_VERSION', api_version)
85
86 configure_file(input : 'gst_api_version.in',
87                output : 'gst_api_version.md',
88                configuration : docconf)
89
90 root_rel = '..'
91 excludes = []
92 foreach f: [
93         'gst/frei0r/frei0r.h',
94         'gst/mxf/mxful.c',
95         'gst-libs/gst/*/*-private.h',
96         'gst-libs/gst/codecparsers/nalutils.h',
97         'ext/closedcaption/bcd.h',
98         'ext/closedcaption/bit_slicer.[ch]',
99         'ext/closedcaption/decoder.[ch]',
100         'ext/closedcaption/macros.h',
101         'ext/closedcaption/misc.h',
102         'ext/closedcaption/raw_decoder.[ch]',
103         'ext/closedcaption/sampling_par.[ch]',
104         'ext/closedcaption/sliced.[ch]',
105         'ext/*/*.h',
106         'sys/*/*.h',
107         'gst/*/*.h',
108         'gst-libs/gst/*/*-prelude.h',
109         'gst-libs/gst/vulkan/vulkan_fwd.h'
110     ]
111     excludes += [join_paths(meson.current_source_dir(), root_rel, f)]
112 endforeach
113
114 libs = []
115 if build_gir
116     libs = [
117         {'name': 'mpegts', 'gir': mpegts_gir, 'lib': gstmpegts_dep},
118         {'name': 'play', 'gir': play_gir, 'lib': gstplay_dep},
119         {'name': 'player', 'gir': player_gir, 'lib': gstplayer_dep},
120         {'name': 'insertbin', 'gir': insertbin_gir, 'lib': gstinsertbin_dep},
121         {'name': 'codecparsers', 'lib': gstcodecparsers_dep},
122         {'name': 'adaptivedemux', 'lib': gstadaptivedemux_dep},
123         {'name': 'basecamerabinsrc', 'gir': basecamerabin_gir, 'lib': gstbasecamerabin_dep},
124         {'name': 'webrtc', 'gir': webrtc_gir, 'lib': gstwebrtc_dep, 'suffix': 'lib'},
125         {'name': 'audio', 'gir': audio_gir, 'lib': gstbadaudio_dep, 'prefix': 'bad-'},
126         {'name': 'transcoder', 'gir': transcoder_gir, 'lib': gst_transcoder_dep},
127         {'name': 'codecs', 'gir': codecs_gir, 'lib': gstcodecs_dep},
128     ]
129
130     if gstopencv_dep.found()
131         libs += [
132             {'name': 'opencv', 'lib': gstopencv_dep, 'c_source_patterns': ['*.h', '*.cpp'], 'extra_c_flags': ['-x c++']},
133         ]
134     endif
135
136     if gstvulkan_dep.found()
137         libs += [
138              {'name': 'vulkan', 'gir': vulkan_gir, 'lib': gstvulkan_dep, 'suffix': 'lib'},
139         ]
140         if enabled_vulkan_winsys.contains('xcb')
141             libs += [
142                 {'name': 'vulkan-xcb', 'gir': vulkan_xcb_gir, 'lib': gstvulkanxcb_dep, 'extra_sources' : [
143                     join_paths(root_rel, 'gst-libs/gst/vulkan/xcb/gstvkdisplay_xcb.[ch]'),
144                 ]},
145             ]
146         endif
147         if enabled_vulkan_winsys.contains('wayland')
148             libs += [
149                 {'name': 'vulkan-wayland', 'gir': vulkan_wayland_gir, 'lib': gstvulkanwayland_dep, 'extra_sources' : [
150                     join_paths(root_rel, 'gst-libs/gst/vulkan/wayland/gstvkdisplay_wayland.[ch]'),
151                 ]},
152             ]
153         endif
154     endif
155 endif
156
157 has_gi_extension = hotdoc.has_extensions('gi-extension')
158 has_c_extension = hotdoc.has_extensions('c-extension')
159 libs_doc = []
160 foreach lib_def: libs
161   name = lib_def['name']
162   lib = lib_def['lib']
163   extra_sources = lib_def.get('extra_sources', [])
164
165   c_source_patterns = lib_def.get('c_source_patterns', ['*.[hc]'])
166   c_sources = []
167   foreach pattern: c_source_patterns
168     c_sources += join_paths(root_rel, 'gst-libs/gst', name, pattern)
169   endforeach
170   c_sources += extra_sources
171
172     if lib_def.has_key('gir')
173         if has_gi_extension
174             gir = lib_def['gir']
175             prefix = lib_def.get('prefix', '')
176             suffix = lib_def.get('suffix', '')
177             libs_doc += [hotdoc.generate_doc(prefix + name + suffix,
178                 project_version: api_version,
179                 gi_c_sources: c_sources,
180                 gi_sources: gir[0].full_path(),
181                 gi_c_source_filters: excludes,
182                 sitemap: join_paths('libs', name, 'sitemap.txt'),
183                 index: join_paths('libs/', name, 'index.md'),
184                 gi_index: join_paths('libs/', name, 'index.md'),
185                 gi_smart_index: true,
186                 gi_order_generated_subpages: true,
187                 dependencies: [lib, gir],
188                 c_flags: '-DGST_USE_UNSTABLE_API',
189                 install: false,
190             )]
191         endif
192     else
193         if has_c_extension
194             libs_doc += [hotdoc.generate_doc('gst-plugins-bad-' + name,
195                 sitemap: join_paths('libs', name, 'sitemap.txt'),
196                 index: join_paths('libs', name, 'index.md'),
197                 project_version: api_version,
198                 c_sources: c_sources,
199                 c_source_filters: excludes,
200                 c_index: join_paths('libs', name, 'index.md'),
201                 c_smart_index: true,
202                 c_order_generated_subpages: true,
203                 extra_c_flags: ['-DGST_USE_UNSTABLE_API'] + lib_def.get('extra_c_flags', []),
204                 dependencies: lib,
205                 install: false,
206             )]
207         endif
208     endif
209 endforeach
210
211 list_plugin_res = run_command(python3, '-c',
212 '''
213 import sys
214 import json
215
216 with open("@0@") as f:
217     print(':'.join(json.load(f).keys()), end='')
218 '''.format(plugins_cache))
219
220 assert(list_plugin_res.returncode() == 0,
221   'Could not list plugins from @0@'.format(plugins_cache))
222
223 plugins_doc = []
224 foreach plugin_name: list_plugin_res.stdout().split(':')
225     plugins_doc += [hotdoc.generate_doc(plugin_name,
226         project_version: api_version,
227         sitemap: 'plugins/sitemap.txt',
228         index: 'plugins/index.md',
229         c_flags: '-DGST_USE_UNSTABLE_API',
230         gst_index: 'plugins/index.md',
231         gst_smart_index: true,
232         gst_c_sources: [
233             join_paths(root_rel, 'sys/*/*.[ch]'),
234             join_paths(root_rel, 'sys/*/*.cpp'),
235             join_paths(root_rel, 'sys/*/*.cc'),
236             join_paths(root_rel, 'sys/*/*.hh'),
237             join_paths(root_rel, 'ext/*/*.[ch]'),
238             join_paths(root_rel, 'ext/*/*.cpp'),
239             join_paths(root_rel, 'ext/*/*.cc'),
240             join_paths(root_rel, 'ext/*/*.hh'),
241             join_paths(root_rel, 'gst/*/*.[ch]'),
242             join_paths(root_rel, 'gst/rtmp2/*/*.[ch]'),
243         ],
244         dependencies: [gst_dep, plugins],
245         install: false,
246         disable_incremental_build: true,
247         gst_cache_file: plugins_cache,
248         gst_c_source_filters: excludes,
249         gst_order_generated_subpages: true,
250         gst_plugin_name: plugin_name,
251         include_paths: join_paths(meson.current_source_dir(), '..'),
252     )]
253 endforeach