1prg_install = find_program('install')
2
3doxygen = find_program('doxygen', required : false)
4if not doxygen.found()
5	error('Program "doxygen" not found or not executable. Try building with -Ddocumentation=false')
6endif
7dot = find_program('dot', required : false)
8if not dot.found()
9	error('Program "dot" not found or not executable. Try building with -Ddocumentation=false')
10endif
11
12doxygen_version_cmd = run_command(doxygen.path(), '--version')
13if doxygen_version_cmd.returncode() != 0
14	error('Command "doxygen --version" failed.')
15endif
16doxygen_version = doxygen_version_cmd.stdout()
17if doxygen_version.version_compare('< 1.8.3')
18	error('doxygen needs to be at least version 1.8.3 (have @0@)'.format(doxygen_version))
19endif
20grep = find_program('grep')
21dot_version_cmd = run_command(dot.path(), '-V')
22if dot_version_cmd.returncode() != 0
23	error('Command "dot -V" failed.')
24endif
25# dot -V output is (to stderr):
26# 	dot - graphviz version 2.38.0 (20140413.2041)
27dot_version = dot_version_cmd.stderr().split(' ')[4]
28if dot_version.version_compare('< 2.26')
29	error('Graphviz dot needs to be at least version 2.26 (have @0@)'.format(dot_version))
30endif
31
32mainpage = vcs_tag(command : ['git', 'log', '-1', '--format=%h'],
33		 fallback : 'unknown',
34		 input : 'mainpage.dox',
35		 output : 'mainpage.dox',
36		 replace_string: '__GIT_VERSION__')
37
38src_doxygen = files(
39	# source files
40	join_paths(meson.source_root(), 'src', 'libinput.h'),
41	# style files
42	'style/header.html',
43	'style/footer.html',
44	'style/customdoxygen.css',
45	'style/bootstrap.css',
46	'style/libinputdoxygen.css',
47)
48
49config_noop = configuration_data()
50# Set a dummy replacement to silence meson warnings:
51# meson.build:487: WARNING: Got an empty configuration_data() object and
52# 		   found no substitutions in the input file 'foo'. If you
53# 		   want to copy a file to the build dir, use the 'copy:'
54# 		   keyword argument added in 0.47.0
55config_noop.set('dummy', 'dummy')
56
57doxyfiles = []
58foreach f : src_doxygen
59	df = configure_file(input: f,
60			    output: '@PLAINNAME@',
61			    configuration : config_noop,
62			    install : false)
63	doxyfiles += [ df ]
64endforeach
65
66doc_config = configuration_data()
67doc_config.set('PACKAGE_NAME', meson.project_name())
68doc_config.set('PACKAGE_VERSION', meson.project_version())
69doc_config.set('builddir', meson.current_build_dir())
70
71doxyfile = configure_file(input : 'libinput.doxygen.in',
72			  output : 'libinput.doxygen',
73			  configuration : doc_config,
74			  install : false)
75
76custom_target('doxygen',
77	      input : [ doxyfiles, doxyfile, mainpage ] + src_doxygen,
78	      output : [ '.' ],
79	      command : [ doxygen, doxyfile ],
80	      install : false,
81	      depends: [ mainpage ],
82	      build_by_default : true)
83