[igt-dev] [PATCH i-g-t 1/1] meson: Add options to control optional parts

Daniel Vetter daniel at ffwll.ch
Wed Jun 20 16:04:08 UTC 2018


On Wed, Jun 20, 2018 at 05:10:38PM +0300, Petri Latvala wrote:
> Distributions want explicit control over optional parts so they can
> state runtime dependencies before building. Let's restore the
> functionality autotools used to provide.
> 
> Where possible, the selection is done by choosing whether to build a
> particular item and the option name is build_$item. Example:
> build_overlay. Where not possible, the option name is
> with_$item. Example: with_valgrind.
> 
> Note, the old hack for not building docs when cross-compiling is
> gone, as doc building can be explicitly controlled now.
> 
> As a drive-by fix, building without glib actually works again.
> 
> Signed-off-by: Petri Latvala <petri.latvala at intel.com>
> Cc: Matt Turner <mattst88 at gmail.com>
> Cc: Daniel Vetter <daniel at ffwll.ch>
> Cc: Eric Anholt <eric at anholt.net>
> Cc: Arkadiusz Hiler <arkadiusz.hiler at intel.com>
> ---
> 
> Matt, does this match your expectations?
> 
> Eric, forewarning about the cross-compiling and documentation.

Just a quick comment on this: The cross-compiling was due to the
build_by_default hack, and the need to run the cross-compiled binaries in
qemu using emulation. Which is dead slow. With the build_by_default hack
gone, this shouldn't be an issue anymore.
-Daniel

> 
> 
> benchmarks/meson.build |   4 +-
>  lib/meson.build        |   5 +-
>  man/meson.build        |  10 +++-
>  meson.build            | 156 +++++++++++++++++++++++++++++++++++++++++--------
>  meson_options.txt      |  60 +++++++++++++++++++
>  overlay/meson.build    |  46 +++++++++++----
>  tests/meson.build      |  18 +++---
>  tools/meson.build      |   2 +-
>  8 files changed, 254 insertions(+), 47 deletions(-)
> 
> diff --git a/benchmarks/meson.build b/benchmarks/meson.build
> index 27836c1d..baf1243d 100644
> --- a/benchmarks/meson.build
> +++ b/benchmarks/meson.build
> @@ -35,10 +35,10 @@ foreach prog : benchmark_progs
>  	executable(prog + '_bench', prog + '.c',
>  		   install : true,
>  		   install_dir : benchmarksdir,
> -		   dependencies : test_deps)
> +		   dependencies : igt_deps)
>  endforeach
>  
>  executable('gem_wsim_bench', 'gem_wsim.c',
>  	   install : true,
>  	   install_dir : benchmarksdir,
> -	   dependencies : test_deps + [ lib_igt_perf ])
> +	   dependencies : igt_deps + [ lib_igt_perf ])
> diff --git a/lib/meson.build b/lib/meson.build
> index 1a355414..5ef9b1a8 100644
> --- a/lib/meson.build
> +++ b/lib/meson.build
> @@ -52,7 +52,6 @@ lib_sources = [
>  
>  lib_deps = [
>  	cairo,
> -	glib,
>  	libdrm,
>  	libkmod,
>  	libprocps,
> @@ -64,6 +63,10 @@ lib_deps = [
>  	realtime,
>  ]
>  
> +if glib.found()
> +	lib_deps += glib
> +endif
> +
>  if libdrm_intel.found()
>  	lib_deps += libdrm_intel
>  else
> diff --git a/man/meson.build b/man/meson.build
> index 49b0686a..fa01f9dd 100644
> --- a/man/meson.build
> +++ b/man/meson.build
> @@ -22,10 +22,10 @@ defs_rst = configure_file(input : 'defs.rst.in',
>  		output : 'defs.rst',
>  		configuration : config)
>  
> -rst2man = find_program('rst2man', required : false)
> +rst2man = find_program('rst2man', required : _man_required)
>  rst2man_script = find_program('rst2man.sh')
>  
> -if rst2man.found()
> +if _build_man and rst2man.found()
>  	foreach manpage : manpages
>  		custom_target(manpage + '.1',
>  				build_by_default : true,
> @@ -36,4 +36,10 @@ if rst2man.found()
>  				install : true,
>  				install_dir : join_paths(mandir, 'man1'))
>  	endforeach
> +	build_info += 'Build man pages: Yes'
> +else
> +	if _man_required
> +		error('Cannot build man pages due to missing dependencies')
> +	endif
> +	build_info += 'Build man pages: No'
>  endif
> diff --git a/meson.build b/meson.build
> index cd736d8e..c2c29b85 100644
> --- a/meson.build
> +++ b/meson.build
> @@ -26,39 +26,129 @@ foreach cc_arg : cc_args
>    endif
>  endforeach
>  
> +_build_overlay = false
> +_overlay_required = false
> +_build_man = false
> +_man_required = false
> +_build_audio = false
> +_audio_required = false
> +_build_chamelium = false
> +_chamelium_required = false
> +_build_docs = false
> +_docs_required = false
> +_build_tests = false
> +_tests_required = false
> +
> +build_overlay = get_option('build_overlay')
> +overlay_backends = get_option('overlay_backends')
> +build_man = get_option('build_man')
> +with_valgrind = get_option('with_valgrind')
> +with_glib = get_option('with_glib')
> +build_audio = get_option('build_audio')
> +build_chamelium = get_option('build_chamelium')
> +build_docs = get_option('build_docs')
> +build_tests = get_option('build_tests')
> +with_libdrm = get_option('with_libdrm')
> +
> +_build_overlay = build_overlay != 'false'
> +_overlay_required = build_overlay == 'true'
> +_build_man = build_man != 'false'
> +_man_required = build_man == 'true'
> +_build_audio = build_audio != 'false'
> +_audio_required = build_audio == 'true'
> +_build_chamelium = build_chamelium != 'false'
> +_chamelium_required = build_chamelium == 'true'
> +_build_docs = build_docs != 'false'
> +_docs_required = build_docs == 'true'
> +_build_tests = build_tests != 'false'
> +_tests_required = build_tests == 'true'
> +
> +build_info = []
> +
>  inc = include_directories('include/drm-uapi', 'lib', '.')
>  
>  inc_for_gtkdoc = include_directories('lib')
>  
>  config = configuration_data()
>  
> +null_dep = dependency('', required : false)
> +
> +libdrm_info = []
> +libdrm_intel = null_dep
> +libdrm_nouveau = null_dep
> +libdrm_amdgpu = null_dep
> +
>  libdrm_version = '>=2.4.82'
>  libdrm = dependency('libdrm', version : libdrm_version)
> -libdrm_intel = dependency('libdrm_intel', version : libdrm_version, required : false)
> -libdrm_nouveau = dependency('libdrm_nouveau', version : libdrm_version, required : false)
> -libdrm_amdgpu = dependency('libdrm_amdgpu', version : libdrm_version, required : false)
> +if with_libdrm.contains('auto') or with_libdrm.contains('intel')
> +	libdrm_intel = dependency('libdrm_intel', version : libdrm_version, required : with_libdrm.contains('intel'))
> +	libdrm_info += 'intel'
> +endif
> +if with_libdrm.contains('auto') or with_libdrm.contains('nouveau')
> +	libdrm_nouveau = dependency('libdrm_nouveau', version : libdrm_version, required : with_libdrm.contains('nouveau'))
> +	libdrm_info += 'nouveau'
> +endif
> +if with_libdrm.contains('auto') or with_libdrm.contains('amdgpu')
> +	libdrm_amdgpu = dependency('libdrm_amdgpu', version : libdrm_version, required : with_libdrm.contains('amdgpu'))
> +	libdrm_info += 'amdgpu'
> +endif
> +
> +build_info += 'With libdrm: ' + ','.join(libdrm_info)
>  
>  pciaccess = dependency('pciaccess', version : '>=0.10')
>  libkmod = dependency('libkmod')
>  libprocps = dependency('libprocps', required : true)
>  libunwind = dependency('libunwind', required : true)
>  
> -valgrind = dependency('valgrind', required : false)
> -if valgrind.found()
> -	config.set('HAVE_VALGRIND', 1)
> +valgrind = null_dep
> +valgrindinfo = 'No'
> +if with_valgrind != 'false'
> +	valgrind = dependency('valgrind', required : with_valgrind == 'true')
> +	if valgrind.found()
> +		config.set('HAVE_VALGRIND', 1)
> +		valgrindinfo = 'Yes'
> +	endif
>  endif
> +build_info += 'Valgrind annotations: ' + valgrindinfo
>  
>  cairo = dependency('cairo', version : '>1.12.0', required : true)
>  libudev = dependency('libudev', required : true)
> -glib = dependency('glib-2.0', required : false)
> -if glib.found()
> -	config.set('HAVE_GLIB', 1)
> +
> +glib = null_dep
> +glibinfo = 'No'
> +if with_glib != 'false'
> +	glib = dependency('glib-2.0', required : with_glib == 'true')
> +	if glib.found()
> +		config.set('HAVE_GLIB', 1)
> +		glibinfo = 'Yes'
> +	endif
> +endif
> +build_info += 'Use GLib: ' + glibinfo
> +
> +gsl = null_dep
> +alsa = null_dep
> +pixman = null_dep
> +if _build_audio or _build_chamelium
> +	gsl = dependency('gsl', required : _audio_required or _chamelium_required)
> +endif
> +if _build_audio
> +	alsa = dependency('alsa', required : _audio_required)
> +endif
> +if _build_chamelium
> +	pixman = dependency('pixman-1', required : _chamelium_required)
>  endif
>  
> -gsl = dependency('gsl', required : false)
> -alsa = dependency('alsa', required : false)
> +audioinfo = 'No'
> +if _build_audio and alsa.found() and gsl.found()
> +	audioinfo = 'Yes'
> +else
> +	if _audio_required
> +		error('Cannot build audio test due to missing dependencies')
> +	endif
> +	_build_audio = false
> +endif
> +build_info += 'Build audio test: ' + audioinfo
>  
> -pixman = dependency('pixman-1', required : false)
>  xmlrpc = dependency('xmlrpc', required : false)
>  xmlrpc_util = dependency('xmlrpc_util', required : false)
>  xmlrpc_client = dependency('xmlrpc_client', required : false)
> @@ -76,13 +166,17 @@ if not xmlrpc.found() and xmlrpc_cmd.found()
>  	endif
>  endif
>  
> -if pixman.found() and gsl.found() and xmlrpc.found() and xmlrpc_util.found() and xmlrpc_client.found()
> +chamelium = null_dep
> +chameliuminfo = 'No'
> +if _build_chamelium and pixman.found() and gsl.found() and xmlrpc.found() and xmlrpc_util.found() and xmlrpc_client.found() and glib.found()
>  	chamelium = declare_dependency(dependencies : [ pixman, xmlrpc,
> -	  xmlrpc_util, xmlrpc_client])
> +							xmlrpc_util, xmlrpc_client])
>  	config.set('HAVE_CHAMELIUM', 1)
> -else
> -	chamelium = dependency('', required: false)
> +	chameliuminfo = 'Yes'
> +elif _chamelium_required
> +	error('Cannot build chamelium test due to missing dependencies')
>  endif
> +build_info += 'Build Chamelium test: ' + chameliuminfo
>  
>  pthreads = dependency('threads')
>  math = cc.find_library('m')
> @@ -133,17 +227,33 @@ mandir = get_option('mandir')
>  pkgconfigdir = join_paths(libdir, 'pkgconfig')
>  
>  subdir('lib')
> -subdir('tests')
> +if _build_tests
> +	subdir('tests')
> +	build_info += 'Build tests: Yes'
> +else
> +	build_info += 'Build tests: No'
> +endif
>  subdir('benchmarks')
>  subdir('tools')
>  if libdrm_intel.found()
>  	subdir('assembler')
> -	if ['x86', 'x86_64'].contains(host_machine.cpu_family())
> -		subdir('overlay')
> -	endif
>  endif
> +subdir('overlay')
>  subdir('man')
> -# has_exe_wrapper() is undefined if building natively
> -if not meson.is_cross_build() or not meson.has_exe_wrapper()
> -	subdir('docs')
> +
> +docs_info = 'No'
> +if _build_docs
> +	if _build_tests
> +		subdir('docs')
> +		docs_info = 'Yes'
> +	elif _docs_required
> +		error('Documentation requires building tests')
> +	endif
>  endif
> +build_info += 'Build documentation: ' + docs_info
> +
> +message('Build options')
> +message('=============')
> +foreach str : build_info
> +	message(str)
> +endforeach
> diff --git a/meson_options.txt b/meson_options.txt
> index 41be35e0..9ff2fd96 100644
> --- a/meson_options.txt
> +++ b/meson_options.txt
> @@ -1,3 +1,63 @@
> +option('build_overlay',
> +       type : 'combo',
> +       value : 'auto',
> +       choices : ['auto', 'true', 'false'],
> +       description : 'Build overlay')
> +
> +option('overlay_backends',
> +       type : 'array',
> +       value : ['auto'],
> +       choices : [ 'auto', 'x', 'xv' ],
> +       description : 'Overlay backends to enable')
> +
> +option('build_audio',
> +       type : 'combo',
> +       value : 'auto',
> +       choices : ['auto', 'true', 'false'],
> +       description : 'Build audio test')
> +
> +option('build_chamelium',
> +       type : 'combo',
> +       value : 'auto',
> +       choices : ['auto', 'true', 'false'],
> +       description : 'Build chamelium test')
> +
> +option('with_valgrind',
> +       type : 'combo',
> +       value : 'auto',
> +       choices : ['auto', 'true', 'false'],
> +       description : 'Build with support for valgrind annotations')
> +
> +option('with_glib',
> +       type : 'combo',
> +       value : 'auto',
> +       choices : ['auto', 'true', 'false'],
> +       description : 'Link with GLib')
> +
> +option('build_man',
> +       type : 'combo',
> +       value : 'auto',
> +       choices : ['auto', 'true', 'false'],
> +       description : 'Build man pages')
> +
> +option('build_docs',
> +       type : 'combo',
> +       value : 'auto',
> +       choices : ['auto', 'true', 'false'],
> +       description : 'Build documentation')
> +
> +option('build_tests',
> +       type : 'combo',
> +       value : 'auto',
> +       choices : ['auto', 'true', 'false'],
> +       description : 'Build tests')
> +
> +option('with_libdrm',
> +       type : 'array',
> +       value : ['auto'],
> +       choices : ['', 'auto', 'intel', 'nouveau', 'amdgpu'],
> +       description : 'libdrm libraries to be used')
> +
>  option('use_rpath',
>         type : 'boolean',
>         value : false,
> diff --git a/overlay/meson.build b/overlay/meson.build
> index 546c8377..46d2d494 100644
> --- a/overlay/meson.build
> +++ b/overlay/meson.build
> @@ -14,20 +14,35 @@ gpu_overlay_src = [
>  	'rc6.c',
>  ]
>  
> -xv = dependency('xv', required : false)
> -x11 = dependency('x11', required : false)
> -xext = dependency('xext', required : false)
> -dri2proto = dependency('dri2proto', version : '>= 2.6', required : false)
> -cairo_xlib = dependency('cairo-xlib', required : false)
> -xrandr = dependency('xrandr', version : '>=1.3', required : false)
> +xv_backend_required = false
> +xlib_backend_required = false
> +build_xv_backend = overlay_backends.contains('xv') or overlay_backends.contains('auto')
> +build_xlib_backend = overlay_backends.contains('x') or overlay_backends.contains('auto')
> +if _overlay_required
> +	xv_backend_required = overlay_backends.contains('xv')
> +	xlib_backend_required = overlay_backends.contains('x')
> +endif
> +
> +xv = dependency('xv', required : xv_backend_required)
> +x11 = dependency('x11', required : xv_backend_required)
> +xext = dependency('xext', required : xv_backend_required)
> +dri2proto = dependency('dri2proto',
> +		       version : '>= 2.6',
> +		       required : xv_backend_required or xlib_backend_required)
> +cairo_xlib = dependency('cairo-xlib', required : xlib_backend_required)
> +xrandr = dependency('xrandr', version : '>=1.3', required : _overlay_required)
>  
>  gpu_overlay_deps = [ realtime, math, cairo, pciaccess, libdrm,
>  	libdrm_intel, lib_igt_perf ]
>  
>  both_x11_src = ''
>  
> +with_xv_backend = false
> +with_xlib_backend = false
> +backends_strings = []
> +
>  gpu_overlay_cflags = []
> -if xv.found() and x11.found() and xext.found() and dri2proto.found()
> +if build_xv_backend and xv.found() and x11.found() and xext.found() and dri2proto.found()
>  	both_x11_src = 'x11/position.c'
>  	gpu_overlay_src += [
>  		'x11/dri2.c',
> @@ -38,20 +53,24 @@ if xv.found() and x11.found() and xext.found() and dri2proto.found()
>  	]
>  	gpu_overlay_deps += [ xv, x11, xext, dri2proto ]
>  	gpu_overlay_cflags += [ '-DHAVE_OVERLAY_XVLIB' ]
> +	with_xv_backend = true
> +	backends_strings += 'Xv'
>  endif
>  
> -if cairo_xlib.found() and xrandr.found() and dri2proto.found()
> +if build_xlib_backend and cairo_xlib.found() and dri2proto.found()
>  	both_x11_src = 'x11/position.c'
>  	gpu_overlay_src += 'x11/x11-window.c'
>  	gpu_overlay_deps += [ cairo_xlib, dri2proto ]
>  	gpu_overlay_cflags += [ '-DHAVE_OVERLAY_XLIB' ]
> +	with_xlib_backend = true
> +	backends_strings += 'X'
>  endif
>  
>  gpu_overlay_src += both_x11_src
>  
>  gpu_overlay_src += 'kms/kms-overlay.c'
>  
> -leg = find_program('leg', required : false)
> +leg = find_program('leg', required : _overlay_required)
>  if leg.found()
>  	leg_file = custom_target('tracepoint_format',
>  		output: 'tracepoint_format.h',
> @@ -62,10 +81,17 @@ else
>  	message('WARNING: leg command not found, disabling overlay; try : apt-get install peg')
>  endif
>  
> -if leg.found() and xrandr.found() and cairo.found()
> +if _build_overlay and ['x86', 'x86_64'].contains(host_machine.cpu_family()) and libdrm_intel.found() and leg.found() and xrandr.found() and cairo.found() and (with_xlib_backend or with_xv_backend)
>  	executable('intel-gpu-overlay', gpu_overlay_src,
>  			include_directories : inc,
>  			c_args : gpu_overlay_cflags,
>  			dependencies : gpu_overlay_deps,
>  			install : true)
> +	build_info += 'Build overlay: Yes'
> +	build_info += 'Overlay backends: ' + ','.join(backends_strings)
> +else
> +	if _overlay_required
> +		error('Cannot build overlay due to missing dependencies')
> +	endif
> +	build_info += 'Build overlay: No'
>  endif
> diff --git a/tests/meson.build b/tests/meson.build
> index cedb4ff1..ec36bafa 100644
> --- a/tests/meson.build
> +++ b/tests/meson.build
> @@ -232,14 +232,14 @@ if libdrm_nouveau.found()
>  	test_deps += libdrm_nouveau
>  endif
>  
> -if chamelium.found()
> +if _build_chamelium and chamelium.found()
>  	test_progs += [
>  		'kms_chamelium',
>  	]
>  	test_deps += chamelium
>  endif
>  
> -if alsa.found() and gsl.found()
> +if _build_audio and alsa.found() and gsl.found()
>  	test_progs += [
>  		'audio',
>  	]
> @@ -292,12 +292,14 @@ test_executables += executable('perf_pmu', 'perf_pmu.c',
>  	   install : true)
>  test_progs += 'perf_pmu'
>  
> -executable('testdisplay', ['testdisplay.c', 'testdisplay_hotplug.c'],
> -	   dependencies : test_deps,
> -	   install_dir : libexecdir,
> -	   install_rpath : rpathdir,
> -	   install : true)
> -test_progs += 'testdisplay'
> +if glib.found()
> +	executable('testdisplay', ['testdisplay.c', 'testdisplay_hotplug.c'],
> +		   dependencies : test_deps,
> +		   install_dir : libexecdir,
> +		   install_rpath : rpathdir,
> +		   install : true)
> +	test_progs += 'testdisplay'
> +endif
>  
>  subdir('amdgpu')
>  
> diff --git a/tools/meson.build b/tools/meson.build
> index 8ed1ccf4..1c8f44fd 100644
> --- a/tools/meson.build
> +++ b/tools/meson.build
> @@ -78,7 +78,7 @@ foreach prog : tools_progs
>  		   install : true)
>  endforeach
>  
> -if libudev.found()
> +if libudev.found() and glib.found()
>  	intel_dp_compliance_src = [
>  		'intel_dp_compliance.c',
>  		'intel_dp_compliance_hotplug.c'
> -- 
> 2.14.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch


More information about the igt-dev mailing list