Skip to content

Commit bd5fe95

Browse files
taliseinkjellahl
authored andcommitted
meson: Add libxml2 cmake wrap
1 parent ac10f92 commit bd5fe95

File tree

3 files changed

+63
-17
lines changed

3 files changed

+63
-17
lines changed

libxml++/meson.build

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,13 +92,19 @@ if is_msvc and get_option('default_library') != 'static'
9292
xmlxx_cpp_args += ['-D_WINDLL']
9393
endif
9494

95+
xmlxx_all_deps = [xmlxx_build_dep]
96+
9597
extra_xmlxx_objects = []
9698

9799
# Build the .rc file for Windows builds and link to it
98100
if host_machine.system() == 'windows'
99101
windows = import('windows')
100102
xmlxx_res = windows.compile_resources(xmlxx_rc)
101103
extra_xmlxx_objects += xmlxx_res
104+
105+
if xml2_is_subproject
106+
xmlxx_all_deps += [winsock_dep]
107+
endif
102108
endif
103109

104110
extra_include_dirs = ['..']
@@ -119,5 +125,5 @@ xmlxx_library = library(xmlxx_libname,
119125
xmlxx_own_dep = declare_dependency(
120126
link_with: xmlxx_library,
121127
include_directories: extra_include_dirs,
122-
dependencies: xmlxx_build_dep
128+
dependencies: xmlxx_all_deps
123129
)

meson.build

Lines changed: 52 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,7 @@ project('libxml++', 'cpp',
77
'warning_level=1',
88
'cpp_std=c++17',
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.60.0', # required for dependency('iconv')
1211
)
1312

1413
xmlxx_api_version = '5.0'
@@ -105,9 +104,12 @@ install_pkgconfigdir = install_libdir / 'pkgconfig'
105104
xml2_min_ver = '2.7.7'
106105
xml2_req = '>= @0@'.format(xml2_min_ver)
107106
xml2_dep = dependency('libxml-2.0', version: xml2_req, required: host_machine.system() != 'windows')
107+
xml2_is_subproject = false
108108

109+
libxml2_lib_set = false
109110
if not xml2_dep.found()
110111
libxml2_lib = 'libxml2'
112+
libxml2_lib_set = true
111113
xml2_dep = cpp_compiler.find_library(libxml2_lib,
112114
has_headers: [
113115
'libxml/globals.h',
@@ -122,19 +124,51 @@ if not xml2_dep.found()
122124
'libxml/xmlIO.h',
123125
'libxml/xmlreader.h',
124126
'libxml/xmlschemas.h',
125-
])
126-
127-
xml_min_ver_split = xml2_min_ver.split('.')
128-
xml_min_ver_int = xml_min_ver_split[0].to_int() * 10000 + \
129-
xml_min_ver_split[1].to_int() * 100 + \
130-
xml_min_ver_split[2].to_int()
131-
132-
if not cpp_compiler.compiles('''#include <libxml/tree.h>
133-
#if LIBXML_VERSION < @0@
134-
# error libxml2 versions must be @1@ or later
135-
#endif'''.format(xml_min_ver_int.to_string(), xml2_min_ver),
136-
name : 'libxml2 is @0@ or later'.format(xml2_min_ver))
137-
error('Your libxml2 installation must be @0@ or later'.format(xml2_min_ver))
127+
],
128+
required: false)
129+
if xml2_dep.found()
130+
xml_min_ver_split = xml2_min_ver.split('.')
131+
xml_min_ver_int = xml_min_ver_split[0].to_int() * 10000 + \
132+
xml_min_ver_split[1].to_int() * 100 + \
133+
xml_min_ver_split[2].to_int()
134+
135+
if not cpp_compiler.compiles('''#include <libxml/tree.h>
136+
#if LIBXML_VERSION < @0@
137+
# error libxml2 versions must be @1@ or later
138+
#endif'''.format(xml_min_ver_int.to_string(), xml2_min_ver),
139+
name : 'libxml2 is @0@ or later'.format(xml2_min_ver))
140+
error('Your libxml2 installation must be @0@ or later'.format(xml2_min_ver))
141+
endif
142+
else
143+
cmake = import('cmake')
144+
opt_var = cmake.subproject_options()
145+
build_shared = get_option('default_library') != 'static'
146+
iconv_dep = dependency('iconv', required: false)
147+
icu_i18n_dep = dependency('icu-i18n', required: false)
148+
icu_uc_dep = dependency('icu-uc', required: false)
149+
lzma_dep = dependency('liblzma', required: false)
150+
thread_dep = dependency('threads', required: false)
151+
zlib_dep = dependency('zlib', required: false)
152+
winsock_dep = cpp_compiler.find_library('ws2_32', required: false)
153+
opt_var.add_cmake_defines({'BUILD_SHARED_LIBS': build_shared,
154+
'LIBXML2_WITH_HTTP': host_machine.system() != 'windows' or winsock_dep.found(),
155+
'LIBXML2_WITH_ICONV': iconv_dep.found(),
156+
'LIBXML2_WITH_ICU': icu_i18n_dep.found() and icu_uc_dep.found(),
157+
'LIBXML2_WITH_LZMA': lzma_dep.found(),
158+
'LIBXML2_WITH_PYTHON': false,
159+
'LIBXML2_WITH_TESTS': build_tests,
160+
'LIBXML2_WITH_THREADS': thread_dep.found(),
161+
'LIBXML2_WITH_ZLIB': zlib_dep.found(),
162+
})
163+
164+
xml2_sp = cmake.subproject('libxml2_cmake', options: opt_var)
165+
xml2_dep = xml2_sp.dependency('LibXml2')
166+
xml2_is_subproject = true
167+
168+
if build_tests
169+
test('testchar', xml2_sp.target('testchar'))
170+
test('testdict', xml2_sp.target('testdict'))
171+
endif
138172
endif
139173
endif
140174

@@ -146,7 +180,9 @@ libxml2_lib_pkgconfig = ''
146180
if xml2_dep.type_name() == 'pkgconfig'
147181
xmlxx_requires += ['libxml-2.0', xml2_req]
148182
else
149-
libxml2_lib_pkgconfig = '-l@0@'.format(libxml2_lib)
183+
if libxml2_lib_set
184+
libxml2_lib_pkgconfig = '-l@0@'.format(libxml2_lib)
185+
endif
150186
endif
151187

152188
xmlxx_requires = ' '.join(xmlxx_requires)

subprojects/libxml2_cmake.wrap

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[wrap-git]
2+
url = https://gitlab.gnome.org/GNOME/libxml2.git
3+
revision = master
4+
depth = 1

0 commit comments

Comments
 (0)