Skip to content

Meson: Use built-in install path options

Meson provides built-in options for common install paths. By using get_option('datadir') and the like to control the install path values, instead of hardcoding them, they can be overridden at build time on the meson command line.

Additionally, the builtin options handle special-case prefixing for dirs like /etc automatically. (When the prefix is /usr, get_option('sysconfdir') will return /etc; elsewhere it will return etc. Which means that get_option('prefix') / get_option('sysconfdir') becomes /etc/ in a /usr-prefix install -- because meson drops all preceding path elements when an absolute path is joined on -- but it becomes <prefix>/etc/ for any other prefix.)

So, as an example, this command:

meson setup _build . --prefix /var/tmp/highlight --sysconfdir /run/etc --mandir man

sets up a build system that'll install binaries into /var/tmp/highlight/bin/, data files into /var/tmp/highlight/share/, man pages into /var/tmp/highlight/man/ (instead of the default /var/tmp/highlight/share/man/), and configuration files into /run/etc/highlight/.

Other changes

  • Using the / operator is more idiomatic than calling join_path(); since Meson 0.49 (very old) they're 100% equivalent. But if there's a strong preference for explicit join_paths() calls, I can restore those.

  • I dropped a couple of variables like bin_dir and lib_dir, they were never used anywhere because those artifacts are installed automatically with install: true.

    lib_dir was especially problematic, because it was being set to <prefix>/lib even on systems where get_option('libdir') would return lib64 or lib/x86_64-linux-gnu. (I could've updated it to lib_dir = get_option('prefix') / get_option('libdir'), which would correct that. But like I said, that path is only ever used implicitly. There's no need for a variable at all.)

Merge request reports

Loading