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!

This has required adjusting the Meson CI to not attempt to find
every feature as at least `xkbcommon` is not in the image!
  • Loading branch information
Kangie committed Sep 14, 2024
1 parent 3a935f0 commit 72274f8
Show file tree
Hide file tree
Showing 3 changed files with 99 additions and 53 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ccpp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ jobs:
- name: set git safe directory
run: git config --global --add safe.directory ${GITHUB_WORKSPACE}
- name: configure meson build
run: CC=clang CC_LD=lld meson setup builddir -Dhtmldoc=true -Dmandoc=true -Dauto_features=enabled
run: CC=clang CC_LD=lld meson setup builddir -Dhtmldoc=true -Dmandoc=true
- name: run build
run: ninja -C builddir

Expand Down
94 changes: 46 additions & 48 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,27 @@ endif
sed = find_program('sed', required: true)

# Optional dependencies
# First we check for things specified by the user (i.e. no automagic)
# Then we check for automagic dependencies.
# Tip: 'Feature' types will always report 'not found' if disabled
# Tip: 'Feature' types always report 'not found' if disabled

freetype = dependency('freetype2', required: get_option('freetype'))
if freetype.found()
all_found_deps += freetype
summary_depvals += {'freetype': freetype}
conf.set10('HAVE_XFT', true)
freetype_dep_opts = ['xft', 'fontconfig']
freetype_deps = []
foreach d : freetype_dep_opts
freetype_dep = dependency(d, required: true)
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

fribidi = dependency(
'fribidi',
Expand Down Expand Up @@ -266,16 +284,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 @@ -284,6 +304,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 @@ -298,63 +319,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 @@ -534,11 +527,16 @@ summary(

featurevals = {
'bidi': fribidi.found() ? fribidi : false,
'freetype': freetype.found() ? freetype : false,
'Go Modules': golang.found(),
'iconv': iconv.found(),
'NLS': libintl.found(),
'Session Management': sm.found() ? sm : false,
'Shaped Windows': xext.found() ? xext : false,
'Xcursor': xcursor.found() ? xcursor : false,
'xkbcommon': xkbcommon.found() ? xkbcommon : false,
'XRender': xrender.found() ? xrender : false,
'XPM support': xpm.found() ? xpm : false,
'PNG support': libpng.found() ? libpng : false,
'SVG support': librsvg.found() ? librsvg : false,
}
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 72274f8

Please sign in to comment.