diff options
author | Dylan Baker <dylan@pnwbakers.com> | 2023-09-01 12:23:35 -0700 |
---|---|---|
committer | Simon Ser <contact@emersion.fr> | 2023-10-20 05:21:01 +0000 |
commit | 16e6a965051fae4d5142e9f16c47bb6bd3dd6f59 (patch) | |
tree | a256dde05cfb7a96285b4927f313b1836208b63f | |
parent | a6a2ccb4486306c3caa5ccd337d972b61b97f75a (diff) | |
download | libdrm-16e6a965051fae4d5142e9f16c47bb6bd3dd6f59.tar.gz libdrm-16e6a965051fae4d5142e9f16c47bb6bd3dd6f59.tar.bz2 libdrm-16e6a965051fae4d5142e9f16c47bb6bd3dd6f59.zip |
meson: Use feature.require() and feature.allowed()
To reduce the size and complexity of checks. require() allows combining
auto and enabled checks(), so that something like
```meson
x = get_option('feature')
y = false
if x.enabled()
if not condition
error(...)
endif
y = condition
endif
```
can be rewritten as:
```meson
y = get_option('feature').require(condition, error_message : ...).allowed()
```
require checks the condition, then if the feature is required it emits
an error with the given message otherwise it returns a disabled feature.
allowed then returns whether the feature is not disabled, and returns
that (ie, .allowed() == not .disabled()). This is especially helpful for
longer more complex conditions
Signed-off-by: Dylan Baker <dylan.c.baker@intel.com>
-rw-r--r-- | .gitlab-ci.yml | 4 | ||||
-rw-r--r-- | meson.build | 120 |
2 files changed, 36 insertions, 88 deletions
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index b59d68ea..6e8655fa 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -41,10 +41,10 @@ stages: BUILD_OS: debian FDO_DISTRIBUTION_VERSION: buster FDO_DISTRIBUTION_PACKAGES: 'build-essential docbook-xsl libatomic-ops-dev libcairo2-dev libcunit1-dev libpciaccess-dev meson ninja-build pkg-config python3 python3-pip python3-wheel python3-setuptools python3-docutils valgrind' - FDO_DISTRIBUTION_EXEC: 'pip3 install meson==0.53.0' + FDO_DISTRIBUTION_EXEC: 'pip3 install meson==0.59.0' # bump this tag every time you change something which requires rebuilding the # base image - FDO_DISTRIBUTION_TAG: "2022-08-22.0" + FDO_DISTRIBUTION_TAG: "2023-09-01.0" .debian-x86_64: extends: diff --git a/meson.build b/meson.build index ba62da6e..f883760e 100644 --- a/meson.build +++ b/meson.build @@ -23,7 +23,7 @@ project( ['c'], version : '2.4.116', license : 'MIT', - meson_version : '>= 0.53', + meson_version : '>= 0.59', default_options : ['buildtype=debugoptimized', 'c_std=c11'], ) @@ -84,113 +84,61 @@ config.set10('HAVE_LIB_ATOMIC_OPS', lib_atomics) dep_pciaccess = dependency('pciaccess', version : '>= 0.10', required : get_option('intel')) -with_intel = false -_intel = get_option('intel') -if not _intel.disabled() - if _intel.enabled() - if not with_atomics - error('libdrm_intel requires atomics.') - elif not dep_pciaccess.found() - error('libdrm_intel requires libpciaccess') - endif - else - with_intel = (_intel.enabled() or host_machine.cpu_family().startswith('x86')) and with_atomics and dep_pciaccess.found() - endif -endif +with_intel = get_option('intel') \ + .require(with_atomics, error_message : 'libdrm_intel requires atomics') \ + .require(dep_pciaccess.found(), error_message : 'libdrm_intel requires libpciaccess') \ + .disable_auto_if(not host_machine.system().startswith('x86')) \ + .allowed() summary('Intel', with_intel) -with_radeon = false -_radeon = get_option('radeon') -if not _radeon.disabled() - if _radeon.enabled() and not with_atomics - error('libdrm_radeon requires atomics.') - endif - with_radeon = with_atomics -endif +with_radeon = get_option('radeon') \ + .require(with_atomics, error_message : 'libdrm_radeon requires atomics') \ + .allowed() summary('Radeon', with_radeon) -with_amdgpu = false -_amdgpu = get_option('amdgpu') -if not _amdgpu.disabled() - if _amdgpu.enabled() and not with_atomics - error('libdrm_amdgpu requires atomics.') - endif - with_amdgpu = with_atomics -endif +with_amdgpu = get_option('amdgpu') \ + .require(with_atomics, error_message : 'libdrm_amdgpu requires atomics') \ + .allowed() summary('AMDGPU', with_amdgpu) -with_nouveau = false -_nouveau = get_option('nouveau') -if not _nouveau.disabled() - if _nouveau.enabled() and not with_atomics - error('libdrm_nouveau requires atomics.') - endif - with_nouveau = with_atomics -endif +with_nouveau = get_option('nouveau') \ + .require(with_atomics, error_message : 'libdrm_nouveau requires atomics') \ + .allowed() summary('Nouveau', with_nouveau) -with_vmwgfx = false -_vmwgfx = get_option('vmwgfx') -if not _vmwgfx.disabled() - with_vmwgfx = true -endif +with_vmwgfx = get_option('vmwgfx').allowed() summary('vmwgfx', with_vmwgfx) -with_omap = false -_omap = get_option('omap') -if _omap.enabled() - if not with_atomics - error('libdrm_omap requires atomics.') - endif - with_omap = true -endif +with_omap = get_option('omap') \ + .require(with_atomics, error_message : 'libdrm_omap requires atomics') \ + .enabled() summary('OMAP', with_omap) -with_freedreno = false -_freedreno = get_option('freedreno') -if not _freedreno.disabled() - if _freedreno.enabled() and not with_atomics - error('libdrm_freedreno requires atomics.') - else - with_freedreno = (_freedreno.enabled() or ['arm', 'aarch64'].contains(host_machine.cpu_family())) and with_atomics - endif -endif +with_freedreno = get_option('freedreno') \ + .require(with_atomics, error_message : 'libdrm_freedreno requires atomics') \ + .disable_auto_if(not ['arm', 'aarch64'].contains(host_machine.cpu_family())) \ + .allowed() summary('Freedreno', with_freedreno) summary('Freedreon-kgsl', with_freedreno_kgsl) -with_tegra = false -_tegra = get_option('tegra') -if _tegra.enabled() - if not with_atomics - error('libdrm_tegra requires atomics.') - endif - with_tegra = true -endif +with_tegra = get_option('tegra') \ + .require(with_atomics, error_message : 'libdrm_tegra requires atomics') \ + .disable_auto_if(not ['arm', 'aarch64'].contains(host_machine.cpu_family())) \ + .enabled() summary('Tegra', with_tegra) -with_etnaviv = false -_etnaviv = get_option('etnaviv') -if not _etnaviv.disabled() - if _etnaviv.enabled() and not with_atomics - error('libdrm_etnaviv requires atomics.') - endif - with_etnaviv = _etnaviv.enabled() or ( - with_atomics and [ - 'loongarch64', 'mips', 'mips64', - 'arm', 'aarch64', 'arc', - ].contains(host_machine.cpu_family()) - ) -endif +with_etnaviv = get_option('etnaviv') \ + .require(with_atomics, error_message : 'libdrm_etnaviv requires atomics') \ + .disable_auto_if(not ['arm', 'aarch64', 'arc', 'mips', 'mips64', 'loongarch64'].contains(host_machine.cpu_family())) \ + .allowed() summary('Etnaviv', with_etnaviv) with_exynos = get_option('exynos').enabled() summary('EXYNOS', with_exynos) -with_vc4 = false -_vc4 = get_option('vc4') -if not _vc4.disabled() - with_vc4 = _vc4.enabled() or ['arm', 'aarch64'].contains(host_machine.cpu_family()) -endif +with_vc4 = get_option('vc4') \ + .disable_auto_if(not ['arm', 'aarch64'].contains(host_machine.cpu_family())) \ + .allowed() summary('VC4', with_vc4) # Among others FreeBSD does not have a separate dl library. |