Skip to content

Commit 92a17d1

Browse files
committed
Meson build: Use Meson's pkgconfig module
instead of using the libxml++.pc.in template. Require meson >= 0.62. Remove the can_add_dist_script variable. It's unnecessary when the meson version >= 0.58.
1 parent 40ee12c commit 92a17d1

File tree

4 files changed

+73
-85
lines changed

4 files changed

+73
-85
lines changed

docs/manual/meson.build

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
# docs/manual
22

33
# input: install_datadir, xmlxx_pcname, tutorial_custom_cmd_py, python3,
4-
# build_documentation, book_name, can_add_dist_script, xsltproc
4+
# build_documentation, book_name, xsltproc
55
# output: can_parse_and_validate, build_pdf_by_default, can_build_pdf,
66
# install_tutorialdir, build_manual_opt, build_manual
77

@@ -106,13 +106,11 @@ if can_build_pdf
106106
)
107107
endif
108108

109-
if can_add_dist_script
110-
# Distribute built files.
111-
meson.add_dist_script(
112-
python3, tutorial_custom_cmd_py, 'dist_doc',
113-
doc_dist_dir,
114-
meson.current_build_dir(),
115-
meson.current_build_dir() / 'libxml++.xml',
116-
meson.current_build_dir() / 'libxml++.pdf',
117-
)
118-
endif
109+
# Distribute built files.
110+
meson.add_dist_script(
111+
python3, tutorial_custom_cmd_py, 'dist_doc',
112+
doc_dist_dir,
113+
meson.current_build_dir(),
114+
meson.current_build_dir() / 'libxml++.xml',
115+
meson.current_build_dir() / 'libxml++.pdf',
116+
)

docs/reference/meson.build

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
# Input: project_build_root, project_source_root, xmlxx_pcname,
44
# xmlxx_api_version, build_documentation, source_h_files,
5-
# install_datadir, python3, doc_reference_py, can_add_dist_script, dot
5+
# install_datadir, python3, doc_reference_py, dot
66
# Output: install_docdir, install_devhelpdir, book_name,
77
# if build_documentation: tag_file
88

@@ -130,14 +130,12 @@ meson.add_install_script(
130130
docinstall_flags
131131
)
132132

133-
if can_add_dist_script
134-
# Distribute built files and files copied by mm-common-get.
135-
meson.add_dist_script(
136-
python3, doc_reference_py, 'dist_doc',
137-
doctool_dir,
138-
doctool_dist_dir,
139-
meson.current_build_dir(),
140-
tag_file.full_path(),
141-
devhelp_file.full_path(),
142-
)
143-
endif
133+
# Distribute built files and files copied by mm-common-get.
134+
meson.add_dist_script(
135+
python3, doc_reference_py, 'dist_doc',
136+
doctool_dir,
137+
doctool_dist_dir,
138+
meson.current_build_dir(),
139+
tag_file.full_path(),
140+
devhelp_file.full_path(),
141+
)

libxml++/meson.build

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22

33
# Input: xmlxx_build_dep, xmlxx_pcname, xmlxx_libversion, xmlxx_api_version,
44
# install_includedir, xmlxx_rc, xmlxx_libname, macos_darwin_versions,
5-
# xml2_is_subproject, winsock_dep, bcrypt_dep
5+
# xml2_is_subproject, winsock_dep, bcrypt_dep,
6+
# xmlxx_pc_requires, libxml2_lib_pkgconfig
67
# Output: source_h_files, xmlxx_own_dep
78

89
# There are no built source files in libxml++-4.0.
@@ -120,6 +121,35 @@ xmlxx_library = library(xmlxx_libname,
120121
install: true,
121122
)
122123

124+
# Generate .pc files, used by pkg-config.
125+
pkg_config = import('pkgconfig')
126+
pc_common_variables = [
127+
'doxytagfile=${docdir}/reference/' + xmlxx_pcname + '.tag',
128+
'htmlrefdir=${docdir}/reference/html',
129+
'htmlrefpub=https://libxmlplusplus.github.io/libxmlplusplus/reference/html',
130+
]
131+
pc_variables = [
132+
'exec_prefix=${prefix}',
133+
'datarootdir=${datadir}',
134+
'docdir=${datadir}/doc/' + xmlxx_pcname,
135+
] + pc_common_variables
136+
pc_uninstalled_variables = [
137+
'docdir=${prefix}/docs',
138+
] + pc_common_variables
139+
140+
pkg_config.generate(xmlxx_library,
141+
filebase: xmlxx_pcname,
142+
variables: pc_variables,
143+
uninstalled_variables: pc_uninstalled_variables,
144+
name: meson.project_name(),
145+
description: 'C++ wrapper for libxml2',
146+
url: 'https://libxmlplusplus.github.io/libxmlplusplus/',
147+
requires: xmlxx_pc_requires,
148+
libraries: libxml2_lib_pkgconfig,
149+
subdirs: [xmlxx_pcname],
150+
extra_cflags: ['-I${libdir}/' + xmlxx_pcname + '/include'],
151+
)
152+
123153
# This is used when building example programs and test programs.
124154
# It's also a part of xmlxx_dep, when libxml++ is a subproject.
125155
xmlxx_own_dep = declare_dependency(

meson.build

Lines changed: 23 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ project('libxml++', 'cpp',
77
'cpp_std=c++17',
88
'warning_level=1',
99
],
10-
meson_version: '>= 0.55.0', # required for meson.add_dist_script(python3, ...)
11-
# and meson.add_install_script(python3, ...)
10+
meson_version: '>= 0.62.0', # required for variables in pkgconfig.generate()
1211
)
1312

1413
xmlxx_api_version = '4.0'
@@ -38,10 +37,9 @@ macos_darwin_versions = [
3837
'@0@.@1@'.format(libtool_soversion[0] + 1, libtool_soversion[1])
3938
]
4039

41-
# Use these instead of meson.source_root() and meson.build_root() in subdirectories.
42-
# source_root() and build_root() are not useful, if this is a subproject.
43-
project_source_root = meson.current_source_dir()
44-
project_build_root = meson.current_build_dir()
40+
# Source and build root directories of the current (sub)project.
41+
project_source_root = meson.project_source_root()
42+
project_build_root = meson.project_build_root()
4543

4644
cpp_compiler = meson.get_compiler('cpp')
4745
is_msvc = cpp_compiler.get_id() == 'msvc'
@@ -114,22 +112,12 @@ glibmm_req_minor_ver = '68'
114112

115113
xml2_min_ver = '2.7.7'
116114
xml2_req = '>= @0@'.format(xml2_min_ver)
117-
118-
# Sadly, this is not Meson 0.60.x or later...
119115
xml2_dep = dependency(
120-
'libxml-2.0',
116+
['libxml-2.0', 'LibXml2'],
121117
version: xml2_req,
122118
required: host_machine.system() != 'windows'
123119
)
124120

125-
if not xml2_dep.found()
126-
xml2_dep = dependency(
127-
'LibXml2',
128-
version: xml2_req,
129-
required: host_machine.system() != 'windows'
130-
)
131-
endif
132-
133121
# Setup CMake subproject for use, if needed
134122
if not xml2_dep.found()
135123
cmake = import('cmake')
@@ -192,24 +180,22 @@ endif
192180

193181
glibmm_dep = dependency('glibmm-2.@0@'.format(glibmm_req_minor_ver), version: glibmm_req)
194182

195-
xmlxx_requires = []
196-
libxml2_lib_pkgconfig = ''
183+
xmlxx_pc_requires = []
184+
libxml2_lib_pkgconfig = []
197185

198186
# Put libxml-2.0 in the 'Requires:' section in the generated pkg-config file if
199187
# we found it by pkg-config
200188
if xml2_dep.type_name() == 'pkgconfig'
201-
xmlxx_requires += ['libxml-2.0', xml2_req]
189+
xmlxx_pc_requires += ['libxml-2.0' + xml2_req]
202190
else
203-
libxml2_lib_pkgconfig = xml2_dep.get_variable(
191+
libxml2_lib_pkgconfig += [xml2_dep.get_variable(
204192
cmake: 'LIBXML2_LIBRARIES',
205193
default_value: 'LibXml2.lib',
206-
)
194+
)]
207195
endif
208196

209197
# ...Then put glibmm-2.x in the 'Requires:' section in the generated pkg-config file
210-
xmlxx_requires += ['glibmm-2.@0@'.format(glibmm_req_minor_ver), glibmm_req]
211-
212-
xmlxx_requires = ' '.join(xmlxx_requires)
198+
xmlxx_pc_requires += ['glibmm-2.@0@'.format(glibmm_req_minor_ver) + glibmm_req]
213199

214200
# Make sure we link to libxml-2.0 and glibmm
215201
xmlxx_build_dep = [xml2_dep, glibmm_dep]
@@ -348,20 +334,8 @@ endif
348334

349335
# Configure files
350336
pkg_conf_data = configuration_data()
351-
pkg_conf_data.set('prefix', install_prefix)
352-
pkg_conf_data.set('exec_prefix', '${prefix}')
353-
pkg_conf_data.set('libdir', '${exec_prefix}' / install_libdir)
354-
pkg_conf_data.set('datarootdir', '${prefix}' / install_datadir)
355-
pkg_conf_data.set('datadir', '${datarootdir}')
356-
pkg_conf_data.set('includedir', '${prefix}' / install_includedir)
357337
pkg_conf_data.set('PACKAGE_NAME', meson.project_name()) # MSVC_NMake/libxml++/libxml++.rc
358-
pkg_conf_data.set('PACKAGE_TARNAME', meson.project_name())
359338
pkg_conf_data.set('PACKAGE_VERSION', meson.project_version())
360-
pkg_conf_data.set('LIBXMLXX_MODULE_NAME', xmlxx_pcname)
361-
pkg_conf_data.set('LIBXMLXX_API_VERSION', xmlxx_api_version)
362-
pkg_conf_data.set('LIBXMLXX_MODULES', xmlxx_requires)
363-
pkg_conf_data.set('LIBXML2_LIB_NO_PKGCONFIG', libxml2_lib_pkgconfig)
364-
pkg_conf_data.set('MSVC_TOOLSET_VER', msvc14x_toolset_ver)
365339

366340
if not build_deprecated_api
367341
pkg_conf_data.set('LIBXMLXX_DISABLE_DEPRECATED', 1)
@@ -384,13 +358,6 @@ if cpp_compiler.get_argument_syntax() == 'msvc'
384358
endif
385359
endif
386360

387-
configure_file(
388-
input: 'libxml++.pc.in',
389-
output: xmlxx_pcname + '.pc',
390-
configuration: pkg_conf_data,
391-
install_dir: install_pkgconfigdir,
392-
)
393-
394361
xmlxxconfig_h_meson = files('libxml++config.h.meson')
395362
install_includeconfigdir = install_libdir / xmlxx_pcname / 'include'
396363
configure_file(
@@ -400,30 +367,25 @@ configure_file(
400367
install_dir: install_includeconfigdir,
401368
)
402369

403-
# add_dist_script() is not allowed in a subproject if meson.version() < 0.58.0.
404-
can_add_dist_script = not meson.is_subproject() or meson.version().version_compare('>= 0.58.0')
405-
406370
subdir('MSVC_NMake/libxml++')
407371
subdir('libxml++')
408372
subdir('examples')
409373
subdir('tests')
410374
subdir('docs/reference')
411375
subdir('docs/manual')
412376

413-
if can_add_dist_script
414-
# Add a ChangeLog file to the distribution directory.
415-
meson.add_dist_script(
416-
python3, dist_changelog_py,
417-
project_source_root,
418-
)
419-
# Add build scripts to the distribution directory, and delete .gitignore
420-
# files and an empty $MESON_PROJECT_DIST_ROOT/build/ directory.
421-
meson.add_dist_script(
422-
python3, dist_build_scripts_py,
423-
project_source_root,
424-
'untracked' / 'build_scripts',
425-
)
426-
endif
377+
# Add a ChangeLog file to the distribution directory.
378+
meson.add_dist_script(
379+
python3, dist_changelog_py,
380+
project_source_root,
381+
)
382+
# Add build scripts to the distribution directory, and delete .gitignore
383+
# files and an empty $MESON_PROJECT_DIST_ROOT/build/ directory.
384+
meson.add_dist_script(
385+
python3, dist_build_scripts_py,
386+
project_source_root,
387+
'untracked' / 'build_scripts',
388+
)
427389

428390
if meson.is_subproject()
429391
pkgconfig_vars = {

0 commit comments

Comments
 (0)