Skip to content

Commit

Permalink
meson: Remove automagic dependencies
Browse files Browse the repository at this point in the history
Prior to this commit there were a number of dependencies that could be
optionally found, but were not essential _and_ could not be explicitly
disabled if they were on the system.

Since meson supports the 'feature' option type (which has an 'auto'
setting), we can enable the existing logic if these options are
not set, but if explicitly enabled or disabled they will either
cause a build failure or be skipped entirely respectively.

This should make packaging more robust for distributions - there's
no way to accidentally build against a library you didn't intend
to if they're turned off!

Signed-off-by: Matt Jolly <[email protected]>
  • Loading branch information
Kangie committed Sep 16, 2024
1 parent c262fc2 commit b4130d5
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 51 deletions.
74 changes: 27 additions & 47 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -271,16 +271,18 @@ endif
librsvg = dependency(
'librsvg-2.0',
version: '>=2.13.92',
required: get_option('rsvg'),
required: get_option('svg'),
)
if librsvg.found()
all_found_deps += librsvg
conf.set10('HAVE_RSVG', true)
# We need at least one of these dependencies
svg_opt_deps = ['cairo', 'cairo-svg', 'libsvg-cairo']
svg_backends = ['cairo', 'cairo-svg', 'libsvg-cairo']
svg_deps = []
foreach d : svg_opt_deps
svg_dep = dependency(d, required: false)
foreach d : svg_backends
# By treating these as features we can let automagic find one or more backends
# or we can explicitly set one or more backends as required, or disable ones we don't want to use.
svg_dep = dependency(d, required: get_option(d))
if svg_dep.found()
svg_deps += svg_dep
summary_depvals += {d: svg_dep}
Expand All @@ -289,6 +291,7 @@ if librsvg.found()
endif
endforeach
if svg_deps.length() == 0
# If everything is set to auto we need to explicitly fail here.
error(
'librsvg found but also require one of: ' + svg_opt_deps.join(' '),
)
Expand All @@ -303,63 +306,35 @@ if sm.found()
conf.set10('SESSION', true)
endif

xcursor = dependency('xcursor', required: get_option('xcursor'))
if xcursor.found()
all_found_deps += xcursor
conf.set10('HAVE_XCURSOR', true)
endif

xext = dependency('xext', required: get_option('xext'))
if xext.found()
all_found_deps += xext
conf.set10('HAVE_SHAPE', true)
endif

# Automagic optional dependencies
# TODO: Automagic dependencies are a nightmare for
# downstream packagers who need to know what is
# and is not enabled for a package at build-time
# not what was randomly also found on their system.

# We should either make these required or hide them behind
# a feature flag.

freetype = dependency('freetype2', required: false)
if freetype.found()
all_found_deps += freetype
summary_depvals += {'freetype': freetype}
conf.set10('HAVE_XFT', true)
freetype_opt_deps = ['xft', 'fontconfig']
freetype_deps = []
foreach d : freetype_opt_deps
# These deps were previously listed as 'optional', but with 'required: true'
freetype_dep = dependency(d, required: false)
if freetype_dep.found()
freetype_deps += freetype_dep
summary_depvals += {d: freetype_dep}
conf.set10('HAVE_' + d.to_upper().underscorify(), true)
endif
endforeach
if freetype_deps.length() > 0
all_found_deps += freetype_deps
endif
endif

xkbcommon = dependency('xkbcommon', required: false)
xkbcommon = dependency('xkbcommon', required: get_option('xkbcommon'))
if xkbcommon.found()
all_found_deps += xkbcommon
conf.set10('HAVE_X11_XKBLIB_H', true)
summary_depvals += {'xkbcommon': xkbcommon}
endif

xpm = dependency('xpm', required: false)
xpm = dependency('xpm', required: get_option('xpm'))
if xpm.found()
all_found_deps += xpm
conf.set10('HAVE_XPM', true)
summary_depvals += {'xpm': xpm}
endif

automagic_opt_deps = ['xcursor', 'xrender']
foreach ad : automagic_opt_deps
this_dep = dependency(ad, required: true)
summary_depvals += {ad: this_dep}
conf.set10('HAVE_' + ad.to_upper().underscorify(), true)
all_found_deps += this_dep
endforeach
xrender = dependency('xrender', required: get_option('xrender'))
if xrender.found()
all_found_deps += xrender
conf.set10('HAVE_XRENDER', true)
endif

# Hard-coded
non_configurable_ops = [
Expand Down Expand Up @@ -538,14 +513,19 @@ summary(
)

featurevals = {
'bidi': fribidi.found() ? fribidi : false,
'BiDi': fribidi.found() ? fribidi : false,
'FreeType': freetype.found() ? freetype : false,
'Go Modules': golang.found(),
'iconv': iconv.found(),
'NLS': libintl.found(),
'PNG support': libpng.found() ? libpng : false,
'Session Management': sm.found() ? sm : false,
'Shaped Windows': xext.found() ? xext : false,
'PNG support': libpng.found() ? libpng : false,
'SVG support': librsvg.found() ? librsvg : false,
'Xcursor': xcursor.found() ? xcursor : false,
'xkbcommon': xkbcommon.found() ? xkbcommon : false,
'XPM support': xpm.found() ? xpm : false,
'XRender': xrender.found() ? xrender : false,
}

if not golang.found()
Expand Down
56 changes: 52 additions & 4 deletions meson.options
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,24 @@ option(
value: 'auto',
description: 'Enable fribidi support',
)
option(
'cairo',
type: 'feature',
value: 'auto',
description: 'Use Cairo as a librsvg backend',
)
option(
'cairo-svg',
type: 'feature',
value: 'auto',
description: 'Use CairoSVG as a librsvg backend',
)
option(
'freetype',
type: 'feature',
value: 'auto',
description: 'Enable freetype support',
)
option(
'golang',
type: 'feature',
Expand All @@ -22,6 +40,12 @@ option(
value: 'auto',
description: 'Enable iconv support',
)
option(
'libsvg-cairo',
type: 'feature',
value: 'auto',
description: 'Use librsvg as a librsvg backend',
)
option(
'mandoc',
type: 'boolean',
Expand All @@ -42,20 +66,44 @@ option(
description: 'Enable readline support for FvwmConsole (disabled if using Go)',
)
option(
'rsvg',
'sm',
type: 'feature',
value: 'auto',
description: 'Enable session management support',
)
option(
'svg',
type: 'feature',
value: 'auto',
description: 'Enable svg support',
)
option(
'sm',
'xcursor',
type: 'feature',
value: 'auto',
description: 'Enable session management support',
description: 'Enable Xcursor support',
)
option(
'xext',
type: 'feature',
value: 'auto',
description: 'Enable shaped window support',
description: 'Enable shaped window support via Xext',
)
option(
'xkbcommon',
type: 'feature',
value: 'auto',
description: 'Enable xkbcommon support',
)
option(
'xrender',
type: 'feature',
value: 'auto',
description: 'Enable XRender support',
)
option(
'xpm',
type: 'feature',
value: 'auto',
description: 'Enable X PixMap (xpm) support',
)

0 comments on commit b4130d5

Please sign in to comment.