Skip to content

Commit 36c2b34

Browse files
fanc999-1kjellahl
authored andcommitted
Meson: Cleanup and fix libxml2 dep search
Use CMake to help us find libxml2, in addition to using pkg-config, as CMake actually looks up libxml2 for us using the headers in %INCLUDE% and the libraries in %LIB% in a more comprehensive way, so we don't need to reinvent the wheel. Since we use Meson 0.60.0 or later, we can use the CMake libxml2 dependency name together with libxml-2.0.pc to find libxml2 in one single call. Also update the libxml2 CMake subproject by using CMake to find ICU and liblzma in the same manner, and ensure that we have the correct libxml2 .lib in the resulting pkg-config file for libxml++.
1 parent b95854e commit 36c2b34

File tree

1 file changed

+58
-84
lines changed

1 file changed

+58
-84
lines changed

meson.build

Lines changed: 58 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -100,92 +100,65 @@ install_pkgconfigdir = install_libdir / 'pkgconfig'
100100
# xmlxx_dep (created in libxml++/meson.build):
101101
# Dependencies when using the libxml++ library.
102102

103-
# libxml2's Windows-specific Makefiles don't create pkg-config files for us, so
104-
# we may need to look for it manually on Windows
105103
xml2_min_ver = '2.7.7'
106104
xml2_req = '>= @0@'.format(xml2_min_ver)
107-
xml2_dep = dependency('libxml-2.0', version: xml2_req, required: host_machine.system() != 'windows')
108-
xml2_is_subproject = false
105+
xml2_dep = dependency(
106+
['libxml-2.0', 'LibXml2'],
107+
version: xml2_req,
108+
required: host_machine.system() != 'windows'
109+
)
109110

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

191164
xmlxx_requires = []
@@ -196,9 +169,10 @@ libxml2_lib_pkgconfig = ''
196169
if xml2_dep.type_name() == 'pkgconfig'
197170
xmlxx_requires += ['libxml-2.0', xml2_req]
198171
else
199-
if libxml2_lib_set
200-
libxml2_lib_pkgconfig = '-l@0@'.format(libxml2_lib)
201-
endif
172+
libxml2_lib_pkgconfig = xml2_dep.get_variable(
173+
cmake: 'LIBXML2_LIBRARIES',
174+
default_value: 'LibXml2.lib',
175+
)
202176
endif
203177

204178
xmlxx_requires = ' '.join(xmlxx_requires)

0 commit comments

Comments
 (0)