# HG changeset patch
# Node ID 77817ab2eaf2
# Parent  bdae2f4577c5
diff --git a/gplugin-gtk4-viewer/meson.build b/gplugin-gtk4-viewer/meson.build
--- a/gplugin-gtk4-viewer/meson.build
+++ b/gplugin-gtk4-viewer/meson.build
@@ -1,5 +1,3 @@
-if GTK4.found()
-
 if not get_option('install-gplugin-gtk4-viewer')
 summary('gplugin-gtk4-viewer',
         'You have disabled installation of gplugin-gtk4-viewer which is a ' +
@@ -32,5 +30,3 @@ if get_option('help2man')
 		install : get_option('install-gplugin-gtk4-viewer'),
 		install_dir : get_option('mandir') / 'man1')
 endif
-
-endif
diff --git a/gplugin-gtk4/meson.build b/gplugin-gtk4/meson.build
--- a/gplugin-gtk4/meson.build
+++ b/gplugin-gtk4/meson.build
@@ -1,6 +1,7 @@
 GTK4 = dependency('gtk4', version : '>=4.0.0', required : get_option('gtk4'))
-
-if GTK4.found()
+if not GTK4.found()
+  subdir_done()
+endif
 
 ###############################################################################
 # Build Info
@@ -147,5 +148,3 @@ install_headers(
 # subdirectories
 ###############################################################################
 subdir('reference')
-
-endif  # gtk4
diff --git a/gplugin-gtk4/reference/meson.build b/gplugin-gtk4/reference/meson.build
--- a/gplugin-gtk4/reference/meson.build
+++ b/gplugin-gtk4/reference/meson.build
@@ -1,31 +1,34 @@
-if get_option('doc')
-	gplugin_gtk4_toml = configure_file(
-		input : 'gplugin-gtk4.toml.in',
-		output : 'gplugin-gtk4.toml',
-		configuration : version_conf,
-		install : true,
-		install_dir : docs_dir / 'gplugin-gtk4',
-	)
-
-	gplugin_gtk4_doc = custom_target('gplugin-gtk4-doc',
-		input : [ gplugin_gtk4_toml, gplugin_gtk4_gir[0] ],
-		output : 'gplugin-gtk4',
-		command : [
-			gidocgen,
-			'generate',
-			'--quiet',
-			'--fatal-warnings',
-			'--add-include-path=@0@'.format(meson.project_build_root() / 'gplugin'),
-			'--config=@INPUT0@',
-			'--output-dir=@OUTPUT@',
-			'--no-namespace-dir',
-			'--content-dir=@0@'.format(meson.current_source_dir()),
-			'@INPUT1@'
-		],
-		depends : [ gplugin_gir[0] ],
-		build_by_default : true,
-		install : true,
-		install_dir : docs_dir,
-	)
+if not get_option('doc')
+  subdir_done()
 endif
 
+gplugin_gtk4_toml = configure_file(
+	input : 'gplugin-gtk4.toml.in',
+	output : 'gplugin-gtk4.toml',
+	configuration : version_conf,
+	install : true,
+	install_dir : docs_dir / 'gplugin-gtk4',
+)
+
+gplugin_gtk4_doc = custom_target('gplugin-gtk4-doc',
+	input : [ gplugin_gtk4_toml, gplugin_gtk4_gir[0] ],
+	output : 'gplugin-gtk4',
+	command : [
+		gidocgen,
+		'generate',
+		'--quiet',
+		'--fatal-warnings',
+		'--add-include-path=@0@'.format(meson.project_build_root() / 'gplugin'),
+		'--config=@INPUT0@',
+		'--output-dir=@OUTPUT@',
+		'--no-namespace-dir',
+		'--content-dir=@0@'.format(meson.current_source_dir()),
+		'@INPUT1@'
+	],
+	depends : [ gplugin_gir[0] ],
+	build_by_default : true,
+	install : true,
+	install_dir : docs_dir,
+)
+
+doc_targets += gplugin_gtk4_doc
diff --git a/gplugin/reference/meson.build b/gplugin/reference/meson.build
--- a/gplugin/reference/meson.build
+++ b/gplugin/reference/meson.build
@@ -1,3 +1,7 @@
+if not get_option('doc')
+  subdir_done()
+endif
+
 gplugin_doc_content_files = [
 	'embedding.md',
 	'genie.md',
@@ -7,33 +11,32 @@ gplugin_doc_content_files = [
 	'vala.md',
 ]
 
-if get_option('doc')
-	gplugin_toml = configure_file(
-		input : 'gplugin.toml.in',
-		output : 'gplugin.toml',
-		configuration : version_conf,
-		install : true,
-		install_dir : docs_dir / 'gplugin',
-	)
+gplugin_toml = configure_file(
+	input : 'gplugin.toml.in',
+	output : 'gplugin.toml',
+	configuration : version_conf,
+	install : true,
+	install_dir : docs_dir / 'gplugin',
+)
 
-	gplugin_doc = custom_target('gplugin-doc',
-		input : [ gplugin_toml, gplugin_gir[0] ],
-		output : 'gplugin',
-		command : [
-			gidocgen,
-			'generate',
-			'--quiet',
-			'--fatal-warnings',
-			'--config=@INPUT0@',
-			'--output-dir=@OUTPUT@',
-			'--no-namespace-dir',
-			'--content-dir=@0@'.format(meson.current_source_dir()),
-			'@INPUT1@'
-		],
-		depend_files : [ gplugin_doc_content_files ],
-		build_by_default : true,
-		install : true,
-		install_dir : docs_dir,
-	)
-endif
+gplugin_doc = custom_target('gplugin-doc',
+	input : [ gplugin_toml, gplugin_gir[0] ],
+	output : 'gplugin',
+	command : [
+		gidocgen,
+		'generate',
+		'--quiet',
+		'--fatal-warnings',
+		'--config=@INPUT0@',
+		'--output-dir=@OUTPUT@',
+		'--no-namespace-dir',
+		'--content-dir=@0@'.format(meson.current_source_dir()),
+		'@INPUT1@'
+	],
+	depend_files : [ gplugin_doc_content_files ],
+	build_by_default : true,
+	install : true,
+	install_dir : docs_dir,
+)
 
+doc_targets += gplugin_doc
diff --git a/gplugin/share/meson.build b/gplugin/share/meson.build
--- a/gplugin/share/meson.build
+++ b/gplugin/share/meson.build
@@ -1,2 +1,1 @@
 subdir('valgrind')
-
diff --git a/lua/meson.build b/lua/meson.build
--- a/lua/meson.build
+++ b/lua/meson.build
@@ -1,5 +1,4 @@
-summary('lua', get_option('lua'), section : 'Loader Support', bool_yn : true)
-
+LUA = dependency('', required: false)
 if get_option('lua')
 	if not get_option('introspection')
 		error('Lua plugin requires GObject Introspection.')
@@ -48,20 +47,26 @@ if get_option('lua')
 	if not LUA_FOUND
 		error('No usable Lua library was found')
 	endif
-
-	# now add the library
-	shared_library('gplugin-lua',
-		GPLUGIN_LUA_SOURCES,
-		GPLUGIN_LUA_HEADERS,
-		name_prefix : '',
-		c_args : ['-DG_LOG_USE_STRUCTURED', '-DG_LOG_DOMAIN="GPlugin-Lua"'],
-		dependencies : [LUA, gplugin_dep],
-		install : true,
-		install_dir : get_option('libdir') / 'gplugin'
-	)
-
-	# Add the loader's path to our environment variable
-	devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_build_dir())
 endif # lua
 
+summary('Lua', LUA, section : 'Loader Support', bool_yn : true)
+
+if not LUA.found()
+  subdir_done()
+endif
+
+# now add the library
+shared_library('gplugin-lua',
+	GPLUGIN_LUA_SOURCES,
+	GPLUGIN_LUA_HEADERS,
+	name_prefix : '',
+	c_args : ['-DG_LOG_USE_STRUCTURED', '-DG_LOG_DOMAIN="GPlugin-Lua"'],
+	dependencies : [LUA, gplugin_dep],
+	install : true,
+	install_dir : get_option('libdir') / 'gplugin'
+)
+
+# Add the loader's path to our environment variable
+devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_build_dir())
+
 subdir('tests')
diff --git a/lua/tests/meson.build b/lua/tests/meson.build
--- a/lua/tests/meson.build
+++ b/lua/tests/meson.build
@@ -1,5 +1,3 @@
-if get_option('lua')
-
 e = executable('test-lua-loader', 'test-lua-loader.c',
 	c_args : [
 		'-DLUA_LOADER_DIR="@0@/.."'.format(meson.current_build_dir()),
@@ -12,5 +10,3 @@ test('Lua Loader', e)
 
 # Add the test plugins path to our environment variable
 devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_source_dir() / 'plugins')
-
-endif # lua
diff --git a/meson.build b/meson.build
--- a/meson.build
+++ b/meson.build
@@ -114,13 +114,14 @@ gidocgen_dep = dependency(
 
 gidocgen = find_program('gi-docgen', required : get_option('doc'))
 docs_dir = get_option('prefix') / get_option('datadir') / 'doc'
+doc_targets = []
 
 ###############################################################################
 # Subdirectories
 ###############################################################################
 subdir('gplugin')
 subdir('gplugin-gtk4')
-subdir('gplugin-gtk4-viewer')
+subdir('gplugin-gtk4-viewer', if_found: GTK4)
 subdir('gplugin-query')
 subdir('po')
 
@@ -131,11 +132,6 @@ subdir('tcc')
 subdir('vala')
 
 if get_option('doc')
-	doc_targets = [gplugin_doc]
-	if GTK4.found()
-		doc_targets += gplugin_gtk4_doc
-	endif
-
 	alias_target('doc', doc_targets)
 endif
 
@@ -148,7 +144,7 @@ install_data('ChangeLog', 'INSTALL.md', 
 
 summary({
 	'api reference' : get_option('doc'),
-	'GTK4 widgets' : GTK4.found(),
+	'GTK4 widgets' : GTK4,
 	'man pages' : get_option('help2man'),
 }, bool_yn : true, section : 'Miscellaneous')
 
diff --git a/python3/meson.build b/python3/meson.build
--- a/python3/meson.build
+++ b/python3/meson.build
@@ -1,5 +1,4 @@
-summary('python3', get_option('python3'), section : 'Loader Support', bool_yn : true)
-
+PYTHON3 = dependency('', required: false)
 if get_option('python3')
 	if not get_option('introspection')
 		error('Python3 plugin requires GObject Introspection.')
@@ -29,13 +28,10 @@ if get_option('python3')
 		['python-3.7', '>=3.7'],
 		['python-3.7m', '>=3.7'],
 	]
-	PYTHON_FOUND = false
 	PYGOBJECT_WORKS = false
 	foreach _PYTHON : _PYTHONS
 		PYTHON3 = dependency(_PYTHON[0], version : _PYTHON[1], required : false)
 		if PYTHON3.found()
-			PYTHON_FOUND = true
-
 			python3_gi_test = compiler.run(files('gplugin-python3-test-pygobject.c'),
 				dependencies : [GLIB, PYTHON3, PYGOBJECT],
 				name : 'Python3 GI')
@@ -49,42 +45,48 @@ if get_option('python3')
 		endif
 	endforeach
 
-	if not PYTHON_FOUND
+	if not PYTHON3.found()
 		error('failed to find a usable python')
 	endif
 
 	if not PYGOBJECT_WORKS
 		error('found a usable python but pygobject does not work with it')
 	endif
-
-	# Now add our libraries
-	gplugin_python3_inc = include_directories('.')
-	gplugin_python3 = shared_library('gplugin-python3',
-		GPLUGIN_PYTHON3_SOURCES,
-		GPLUGIN_PYTHON3_HEADERS,
-		name_prefix : '',
-		c_args : ['-DG_LOG_USE_STRUCTURED', '-DG_LOG_DOMAIN="GPlugin-Python3"'],
-		dependencies : [PYTHON3, PYGOBJECT, gplugin_dep],
-		install : true,
-		install_dir : get_option('libdir') / 'gplugin'
-	)
-	gplugin_python3_dep = declare_dependency(
-		include_directories : gplugin_python3_inc,
-		link_with : gplugin_python3,
-	)
-
-	gplugin_python3_static = static_library('gplugin-python3-static',
-		GPLUGIN_PYTHON3_SOURCES,
-		GPLUGIN_PYTHON3_HEADERS,
-		dependencies : [PYTHON3, PYGOBJECT, gplugin_dep],
-	)
-	gplugin_python3_static_dep = declare_dependency(
-		include_directories : gplugin_python3_inc,
-		link_with : gplugin_python3_static,
-	)
-
-	# Add the loader's path to our environment variable
-	devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_build_dir())
 endif # python3
 
+summary('Python3', PYTHON3, section : 'Loader Support', bool_yn : true)
+
+if not PYTHON3.found()
+  subdir_done()
+endif
+
+# Now add our libraries
+gplugin_python3_inc = include_directories('.')
+gplugin_python3 = shared_library('gplugin-python3',
+	GPLUGIN_PYTHON3_SOURCES,
+	GPLUGIN_PYTHON3_HEADERS,
+	name_prefix : '',
+	c_args : ['-DG_LOG_USE_STRUCTURED', '-DG_LOG_DOMAIN="GPlugin-Python3"'],
+	dependencies : [PYTHON3, PYGOBJECT, gplugin_dep],
+	install : true,
+	install_dir : get_option('libdir') / 'gplugin'
+)
+gplugin_python3_dep = declare_dependency(
+	include_directories : gplugin_python3_inc,
+	link_with : gplugin_python3,
+)
+
+gplugin_python3_static = static_library('gplugin-python3-static',
+	GPLUGIN_PYTHON3_SOURCES,
+	GPLUGIN_PYTHON3_HEADERS,
+	dependencies : [PYTHON3, PYGOBJECT, gplugin_dep],
+)
+gplugin_python3_static_dep = declare_dependency(
+	include_directories : gplugin_python3_inc,
+	link_with : gplugin_python3_static,
+)
+
+# Add the loader's path to our environment variable
+devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_build_dir())
+
 subdir('tests')
diff --git a/python3/tests/meson.build b/python3/tests/meson.build
--- a/python3/tests/meson.build
+++ b/python3/tests/meson.build
@@ -1,5 +1,3 @@
-if get_option('python3')
-
 e = executable('test-python3-loader', 'test-python3-loader.c',
 	include_directories : include_directories('.'),
 	c_args : [
@@ -21,5 +19,3 @@ test('Python3 utils', e)
 
 # Add the test plugins path to our environment variable
 devenv.append('GPLUGIN_PLUGIN_PATH', meson.current_source_dir() / 'plugins')
-
-endif # python3
diff --git a/rust/meson.build b/rust/meson.build
--- a/rust/meson.build
+++ b/rust/meson.build
@@ -1,6 +1,7 @@
-if get_option('rs')
-	add_languages('rust')
+if not get_option('rs')
+  subdir_done()
+endif
 
-	subdir('tests')
-endif # rs
+add_languages('rust')
 
+subdir('tests')
diff --git a/rust/tests/meson.build b/rust/tests/meson.build
--- a/rust/tests/meson.build
+++ b/rust/tests/meson.build
@@ -1,5 +1,3 @@
-if get_option('rs')
-
 e = executable('test-rust-loading', 'test-rust-loading.c',
 	include_directories : include_directories('.'),
 	c_args: [
@@ -10,6 +8,3 @@ e = executable('test-rust-loading', 'tes
 test('Rust loading', e)
 
 subdir('plugins')
-
-endif # rs
-
diff --git a/vala/meson.build b/vala/meson.build
--- a/vala/meson.build
+++ b/vala/meson.build
@@ -1,23 +1,25 @@
-if get_option('vapi')
-	if not get_option('introspection')
-		error('Vala generation requires GObject Introspection.')
-	endif
+if not get_option('vapi')
+  subdir_done()
+endif
 
-	add_languages('vala', native: false)
+if not get_option('introspection')
+	error('Vala generation requires GObject Introspection.')
+endif
 
-	gplugin_vapi = gnome.generate_vapi('gplugin',
-		sources : gplugin_gir[0],
-		install : true,
-	)
+add_languages('vala', native: false)
 
-	if get_option('gtk4').allowed()
-		gplugin_gtk4_vapi = gnome.generate_vapi('gplugin-gtk4',
-			sources : gplugin_gtk4_gir[0],
-			packages : [ 'gtk4' ],
-			install : true,
-			gir_dirs : meson.current_build_dir() / '..' / 'gplugin',
-		)
-	endif
+gplugin_vapi = gnome.generate_vapi('gplugin',
+	sources : gplugin_gir[0],
+	install : true,
+)
 
-	subdir('tests')
-endif # vala
+if get_option('gtk4').allowed()
+	gplugin_gtk4_vapi = gnome.generate_vapi('gplugin-gtk4',
+		sources : gplugin_gtk4_gir[0],
+		packages : [ 'gtk4' ],
+		install : true,
+		gir_dirs : meson.current_build_dir() / '..' / 'gplugin',
+	)
+endif
+
+subdir('tests')
diff --git a/vala/tests/meson.build b/vala/tests/meson.build
--- a/vala/tests/meson.build
+++ b/vala/tests/meson.build
@@ -1,5 +1,3 @@
-if get_option('vapi')
-
 e = executable('test-vala-loading', 'test-vala-loading.c',
 	include_directories : include_directories('.'),
 	c_args : [
@@ -20,5 +18,3 @@ test('Genie loading', e)
 
 subdir('genie-plugins')
 subdir('plugins')
-
-endif # vapi
