@@ -7,8 +7,7 @@ project('libxml++', 'cpp',
7
7
' warning_level=1' ,
8
8
' cpp_std=c++17' ,
9
9
],
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')
12
11
)
13
12
14
13
xmlxx_api_version = ' 5.0'
@@ -105,9 +104,12 @@ install_pkgconfigdir = install_libdir / 'pkgconfig'
105
104
xml2_min_ver = ' 2.7.7'
106
105
xml2_req = ' >= @0@' .format(xml2_min_ver)
107
106
xml2_dep = dependency (' libxml-2.0' , version : xml2_req, required : host_machine .system() != ' windows' )
107
+ xml2_is_subproject = false
108
108
109
+ libxml2_lib_set = false
109
110
if not xml2_dep.found()
110
111
libxml2_lib = ' libxml2'
112
+ libxml2_lib_set = true
111
113
xml2_dep = cpp_compiler.find_library (libxml2_lib,
112
114
has_headers : [
113
115
' libxml/globals.h' ,
@@ -122,19 +124,51 @@ if not xml2_dep.found()
122
124
' libxml/xmlIO.h' ,
123
125
' libxml/xmlreader.h' ,
124
126
' 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
138
172
endif
139
173
endif
140
174
@@ -146,7 +180,9 @@ libxml2_lib_pkgconfig = ''
146
180
if xml2_dep.type_name() == ' pkgconfig'
147
181
xmlxx_requires += [' libxml-2.0' , xml2_req]
148
182
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
150
186
endif
151
187
152
188
xmlxx_requires = ' ' .join(xmlxx_requires)
0 commit comments