Skip to content

Commit b167ef1

Browse files
fanc999-1kjellahl
authored andcommitted
meson: Backport libxml2 CMake support
This is the backport of the CMake support for libxml2, where: * We use CMake to look for libxml2 as well, if it is not found by pkg-config, on Windows. It actually does what the existing method does for Visual Studio builds, i.e. look for the libxml2 headers and libraries in %INCLUDE% and %LIB% respectively, so no need to reinvent the wheels here. This accomodates usage on Meson 0.55.x. * Add support to build libxml2 as a subproject using CMake on Windows, like what we do for the master/libxml++-5-0 branches.
1 parent 1ce8ac4 commit b167ef1

File tree

2 files changed

+80
-33
lines changed

2 files changed

+80
-33
lines changed

libxml++/meson.build

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# libxml++
22

33
# Input: xmlxx_build_dep, xmlxx_pcname, xmlxx_libversion, xmlxx_api_version,
4-
# install_includedir, xmlxx_rc, xmlxx_libname, macos_darwin_versions
4+
# install_includedir, xmlxx_rc, xmlxx_libname, macos_darwin_versions,
5+
# xml2_is_subproject
56
# Output: source_h_files, xmlxx_own_dep
67

78
# There are no built source files in libxml++-2.6.
@@ -102,6 +103,10 @@ if host_machine.system() == 'windows'
102103
extra_xmlxx_objects += xmlxx_res
103104
endif
104105

106+
if xml2_is_subproject
107+
xmlxx_build_dep += winsock_dep
108+
endif
109+
105110
extra_include_dirs = ['..']
106111
xmlxx_library = library(xmlxx_libname,
107112
source_cc_files,

meson.build

Lines changed: 74 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -107,42 +107,81 @@ install_pkgconfigdir = install_libdir / 'pkgconfig'
107107
# for its pkg-config files on Visual Studio as well
108108
glibmm_req = '>= 2.32.0'
109109

110-
# libxml2's Windows-specific Makefiles don't create pkg-config files for us, so
111-
# we may need to look for it manually on Windows
112110
xml2_min_ver = '2.7.7'
113111
xml2_req = '>= @0@'.format(xml2_min_ver)
114-
xml2_dep = dependency('libxml-2.0', version: xml2_req, required: host_machine.system() != 'windows')
115112

113+
# Sadly, this is not Meson 0.60.x or later...
114+
xml2_dep = dependency(
115+
'libxml-2.0',
116+
version: xml2_req,
117+
required: host_machine.system() != 'windows'
118+
)
119+
120+
if not xml2_dep.found()
121+
xml2_dep = dependency(
122+
'LibXml2',
123+
version: xml2_req,
124+
required: host_machine.system() != 'windows'
125+
)
126+
endif
127+
128+
# Setup CMake subproject for use, if needed
116129
if not xml2_dep.found()
117-
libxml2_lib = 'libxml2'
118-
xml2_dep = cpp_compiler.find_library(libxml2_lib,
119-
has_headers: [
120-
'libxml/globals.h',
121-
'libxml/parser.h',
122-
'libxml/parserInternals.h',
123-
'libxml/relaxng.h',
124-
'libxml/tree.h',
125-
'libxml/xinclude.h',
126-
'libxml/xpath.h',
127-
'libxml/xpathInternals.h',
128-
'libxml/xmlerror.h',
129-
'libxml/xmlIO.h',
130-
'libxml/xmlreader.h',
131-
'libxml/xmlschemas.h',
132-
])
133-
134-
xml_min_ver_split = xml2_min_ver.split('.')
135-
xml_min_ver_int = xml_min_ver_split[0].to_int() * 10000 + \
136-
xml_min_ver_split[1].to_int() * 100 + \
137-
xml_min_ver_split[2].to_int()
138-
139-
if not cpp_compiler.compiles('''#include <libxml/tree.h>
140-
#if LIBXML_VERSION < @0@
141-
# error libxml2 versions must be @1@ or later
142-
#endif'''.format(xml_min_ver_int.to_string(), xml2_min_ver),
143-
name : 'libxml2 is @0@ or later'.format(xml2_min_ver))
144-
error('Your libxml2 installation must be @0@ or later'.format(xml2_min_ver))
130+
cmake = import('cmake')
131+
opt_var = cmake.subproject_options()
132+
build_shared = get_option('default_library') != 'static'
133+
iconv_dep = dependency('iconv', required: false)
134+
icu_i18n_dep = dependency('icu-i18n', required: false)
135+
if not icu_i18n_dep.found()
136+
icu_i18n_dep = dependency('ICU',
137+
components: 'in',
138+
required: false)
145139
endif
140+
icu_uc_dep = dependency('icu-uc', required: false)
141+
if not icu_uc_dep.found()
142+
icu_uc_dep = dependency('ICU',
143+
components: 'uc',
144+
required: false)
145+
endif
146+
lzma_dep = dependency('liblzma', required: false)
147+
thread_dep = dependency('threads', required: false)
148+
zlib_dep = dependency('zlib', required: false)
149+
winsock_dep = cpp_compiler.find_library('ws2_32', required: false)
150+
cmake_build_type = get_option('buildtype')
151+
if get_option('buildtype') == 'debugoptimized'
152+
cmake_build_type = 'RelWithDebInfo'
153+
elif get_option('buildtype') == 'minsize'
154+
cmake_build_type = 'MinSizeRel'
155+
elif get_option('buildtype') == 'plain'
156+
cmake_build_type = ''
157+
endif
158+
opt_var.add_cmake_defines({
159+
'BUILD_SHARED_LIBS': build_shared,
160+
'CMAKE_BUILD_TYPE': cmake_build_type,
161+
'CMAKE_MSVC_RUNTIME_LIBRARY': '',
162+
'CMAKE_C_FLAGS_INIT': '',
163+
'CMAKE_C_FLAGS_DEBUG': '',
164+
'CMAKE_C_FLAGS_RELEASE': '',
165+
'CMAKE_C_FLAGS_RELWITHDEBINFO': '',
166+
'CMAKE_C_FLAGS_MINSIZEREL': '',
167+
'LIBXML2_WITH_HTTP': host_machine.system() != 'windows' or winsock_dep.found(),
168+
'LIBXML2_WITH_ICONV': iconv_dep.found(),
169+
'LIBXML2_WITH_ICU': icu_i18n_dep.found() and icu_uc_dep.found(),
170+
'LIBXML2_WITH_LZMA': lzma_dep.found(),
171+
'LIBXML2_WITH_PYTHON': false,
172+
'LIBXML2_WITH_TESTS': build_tests,
173+
'LIBXML2_WITH_THREADS': thread_dep.found(),
174+
'LIBXML2_WITH_ZLIB': zlib_dep.found(),
175+
})
176+
xml2_sp = cmake.subproject('libxml2_cmake', options: opt_var)
177+
xml2_dep = xml2_sp.dependency('LibXml2')
178+
endif
179+
180+
xml2_is_subproject = xml2_dep.type_name() == 'internal'
181+
182+
if xml2_is_subproject and build_tests
183+
test('testchar', xml2_sp.target('testchar'))
184+
test('testdict', xml2_sp.target('testdict'))
146185
endif
147186

148187
glibmm_req_minor_ver = '4'
@@ -156,7 +195,10 @@ libxml2_lib_pkgconfig = ''
156195
if xml2_dep.type_name() == 'pkgconfig'
157196
xmlxx_requires += ['libxml-2.0', xml2_req]
158197
else
159-
libxml2_lib_pkgconfig = '-l@0@'.format(libxml2_lib)
198+
libxml2_lib_pkgconfig = xml2_dep.get_variable(
199+
cmake: 'LIBXML2_LIBRARIES',
200+
default_value: 'LibXml2.lib',
201+
)
160202
endif
161203

162204
# ...Then put glibmm-2.x in the 'Requires:' section in the generated pkg-config file

0 commit comments

Comments
 (0)