Skip to content

Commit

Permalink
meson: replace the backends list with -Dbackend-foo features
Browse files Browse the repository at this point in the history
This removes the 'backends' option and replaces it with individual
options for each backend, e.g. -Dbackend-gtk3=enabled.
All backends become optional by default and are built if the
dependencies are available.

A summary is printed to list the actually enabled backends.

This makes life easier for new users since the majority of them will not
have GTK3, GTK4 and Qt5 headers installed by default and thus are almost
guaranteed to run into a meson error on first configure.

Fixes #94
  • Loading branch information
whot authored and GeorgesStavracas committed Dec 9, 2022
1 parent c179930 commit 333a299
Show file tree
Hide file tree
Showing 9 changed files with 30 additions and 18 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
- name: Check out libportal
uses: actions/checkout@v1
- name: Configure libportal
run: meson setup --prefix=/usr _build -Dbackends=gtk3 -Ddocs=false
run: meson setup --prefix=/usr _build -Dbackend-gtk3=enabled -Ddocs=false
- name: Build libportal
run: ninja -C_build

Expand All @@ -43,7 +43,7 @@ jobs:
- name: Check out libportal
uses: actions/checkout@v1
- name: Configure libportal
run: meson setup --prefix=/usr _build -Dbackends=gtk3,gtk4
run: meson setup --prefix=/usr _build -Dbackend-gtk3=enabled -Dbackend-gtk4=enabled
- name: Build libportal
run: ninja -C_build

Expand All @@ -62,7 +62,7 @@ jobs:
- name: Check out libportal
uses: actions/checkout@v1
- name: Configure libportal
run: meson setup --prefix=/usr _build -Dbackends=gtk3,gtk4
run: meson setup --prefix=/usr _build -Dbackend-gtk3=enabled -Dbackend-gtk4=enabled
- name: Build libportal
run: ninja -C_build
- name: Deploy Docs
Expand Down
2 changes: 1 addition & 1 deletion build-aux/org.gnome.PortalTest.Gtk3.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"buildsystem": "meson",
"builddir": true,
"config-opts": [
"-Dbackends=gtk3",
"-Dbackend-gtk3=enabled",
"-Dportal-tests=true",
"-Ddocs=false"
],
Expand Down
2 changes: 1 addition & 1 deletion build-aux/org.gnome.PortalTest.Gtk4.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
"buildsystem": "meson",
"builddir": true,
"config-opts": [
"-Dbackends=gtk4",
"-Dbackend-gtk4=enabled",
"-Dportal-tests=true",
"-Ddocs=false"
],
Expand Down
2 changes: 1 addition & 1 deletion build-aux/org.gnome.PortalTest.Qt5.json
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
"buildsystem": "meson",
"builddir": true,
"config-opts": [
"-Dbackends=qt5",
"-Dbackend-qt5=enabled",
"-Dportal-tests=true",
"-Dintrospection=false",
"-Dvapi=false",
Expand Down
23 changes: 16 additions & 7 deletions libportal/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -109,12 +109,14 @@ if introspection
endif
endif

enabled_backends = []

########
# GTK3 #
########

if 'gtk3' in backends
gtk3_dep = dependency('gtk+-3.0')
gtk3_dep = dependency('gtk+-3.0', required: get_option('backend-gtk3'))
if gtk3_dep.found()
gtk3_headers = ['portal-gtk3.h']
gtk3_sources = ['portal-gtk3.c']

Expand Down Expand Up @@ -164,14 +166,15 @@ if 'gtk3' in backends
)
endif
endif
enabled_backends += ['gtk3']
endif

########
# GTK4 #
########

if 'gtk4' in backends
gtk4_dep = dependency('gtk4')
gtk4_dep = dependency('gtk4', required: get_option('backend-gtk4'))
if gtk4_dep.found()
gtk4_headers = ['portal-gtk4.h']
gtk4_sources = ['portal-gtk4.c']

Expand Down Expand Up @@ -222,16 +225,17 @@ if 'gtk4' in backends
)
endif
endif
enabled_backends += ['gtk4']
endif

########
# Qt 5 #
########

if 'qt5' in backends
add_languages('cpp', required : true)
have_cpp = add_languages('cpp', required: get_option('backend-qt5'))
qt5_dep = dependency('qt5', modules: ['Core', 'Gui', 'X11Extras', 'Widgets'], required: get_option('backend-qt5'))

qt5_dep = dependency('qt5', modules: ['Core', 'Gui', 'X11Extras', 'Widgets'])
if have_cpp and qt5_dep.found()
qt5_headers = ['portal-qt5.h']
qt5_sources = ['portal-qt5.cpp']

Expand All @@ -257,4 +261,9 @@ if 'qt5' in backends
dependencies: [libportal_dep, qt5_dep],
link_with: libportal_qt5,
)
enabled_backends += ['qt5']
endif

if meson.version().version_compare('>= 0.54.0')
summary({'enabled backends': enabled_backends}, section: 'Backends', list_sep: ',')
endif
1 change: 0 additions & 1 deletion meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ endforeach

configure_file(output : 'config.h', configuration : conf)

backends = get_option('backends')
introspection = get_option('introspection')
vapi = get_option('vapi')

Expand Down
8 changes: 6 additions & 2 deletions meson_options.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
option('backends', type: 'array', choices: ['gtk3', 'gtk4', 'qt5'], value: ['gtk3', 'gtk4', 'qt5'],
description : 'A list of portal backends to build')
option('backend-gtk3', type: 'feature', value: 'auto',
description: 'Build the GTK3 portal backend')
option('backend-gtk4', type: 'feature', value: 'auto',
description: 'Build the GTK4 portal backend')
option('backend-qt5', type: 'feature', value: 'auto',
description: 'Build the Qt5 portal backend')
option('portal-tests', type: 'boolean', value: false,
description : 'Build portal tests of each backend')
option('introspection', type: 'boolean', value: true,
Expand Down
2 changes: 1 addition & 1 deletion portal-test/meson.build
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
foreach backend : backends
foreach backend : enabled_backends
subdir(backend)
endforeach
2 changes: 1 addition & 1 deletion tests/meson.build
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
if 'qt5' in backends
if 'qt5' in enabled_backends
subdir('qt5')
endif

Expand Down

0 comments on commit 333a299

Please sign in to comment.