• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1cmake_minimum_required(VERSION 3.15)
2
3project(libxml2 VERSION 2.9.10 LANGUAGES C)
4
5include(CheckCSourceCompiles)
6include(CheckFunctionExists)
7include(CheckIncludeFiles)
8include(CheckLibraryExists)
9include(CheckStructHasMember)
10include(CheckSymbolExists)
11include(CMakePackageConfigHelpers)
12include(GNUInstallDirs)
13
14option(BUILD_SHARED_LIBS "Build shared libraries" ON)
15set(LIBXML2_WITH_AUTOMATA ON)
16option(LIBXML2_WITH_C14N "Add the Canonicalization support" ON)
17option(LIBXML2_WITH_CATALOG "Add the Catalog support" ON)
18option(LIBXML2_WITH_DEBUG "Add the debugging module" ON)
19option(LIBXML2_WITH_DOCB "Add Docbook SGML support" ON)
20set(LIBXML2_WITH_EXPR ON)
21option(LIBXML2_WITH_FTP "Add the FTP support" ON)
22option(LIBXML2_WITH_HTML "Add the HTML support" ON)
23option(LIBXML2_WITH_HTTP "Add the HTTP support" ON)
24option(LIBXML2_WITH_ICONV "Add ICONV support" ON)
25option(LIBXML2_WITH_ICU "Add ICU support" OFF)
26option(LIBXML2_WITH_ISO8859X "Add ISO8859X support if no iconv" ON)
27option(LIBXML2_WITH_LEGACY "Add deprecated APIs for compatibility" ON)
28option(LIBXML2_WITH_LZMA "Use liblzma" ON)
29option(LIBXML2_WITH_MEM_DEBUG "Add the memory debugging module" OFF)
30option(LIBXML2_WITH_MODULES "Add the dynamic modules support" ON)
31option(LIBXML2_WITH_OUTPUT "Add the serialization support" ON)
32option(LIBXML2_WITH_PATTERN "Add the xmlPattern selection interface" ON)
33option(LIBXML2_WITH_PROGRAMS "Build programs" ON)
34option(LIBXML2_WITH_PUSH "Add the PUSH parser interfaces" ON)
35option(LIBXML2_WITH_PYTHON "Build Python bindings" ON)
36option(LIBXML2_WITH_READER "Add the xmlReader parsing interface" ON)
37option(LIBXML2_WITH_REGEXPS "Add Regular Expressions support" ON)
38option(LIBXML2_WITH_RUN_DEBUG "Add the runtime debugging module" OFF)
39option(LIBXML2_WITH_SAX1 "Add the older SAX1 interface" ON)
40option(LIBXML2_WITH_SCHEMAS "Add Relax-NG and Schemas support" ON)
41option(LIBXML2_WITH_SCHEMATRON "Add Schematron support" ON)
42option(LIBXML2_WITH_TESTS "Build tests" ON)
43option(LIBXML2_WITH_THREADS "Add multithread support" ON)
44option(LIBXML2_WITH_THREAD_ALLOC "Add per-thread memory" OFF)
45option(LIBXML2_WITH_TREE "Add the DOM like tree manipulation APIs" ON)
46set(LIBXML2_WITH_TRIO OFF)
47set(LIBXML2_WITH_UNICODE ON)
48option(LIBXML2_WITH_VALID "Add the DTD validation support" ON)
49option(LIBXML2_WITH_WRITER "Add the xmlWriter saving interface" ON)
50option(LIBXML2_WITH_XINCLUDE "Add the XInclude support" ON)
51option(LIBXML2_WITH_XPATH "Add the XPATH support" ON)
52option(LIBXML2_WITH_XPTR "Add the XPointer support" ON)
53option(LIBXML2_WITH_ZLIB "Use libz" ON)
54set(LIBXML2_XMLCONF_WORKING_DIR ${CMAKE_CURRENT_BINARY_DIR} CACHE PATH "Working directory for XML Conformance Test Suite")
55
56if(LIBXML2_WITH_ICONV)
57	find_package(Iconv REQUIRED)
58endif()
59
60if(LIBXML2_WITH_ICU)
61	find_package(ICU REQUIRED COMPONENTS data i18n uc)
62endif()
63
64if(LIBXML2_WITH_LZMA)
65	find_package(LibLZMA REQUIRED)
66endif()
67
68if(LIBXML2_WITH_PYTHON)
69	check_include_files(unistd.h HAVE_UNISTD_H)
70	check_symbol_exists(F_GETFL fcntl.h HAVE_F_GETFL)
71	if(HAVE_UNISTD_H AND HAVE_F_GETFL)
72		find_package(Python COMPONENTS Interpreter Development REQUIRED)
73	else()
74		find_package(Python2 COMPONENTS Interpreter Development REQUIRED)
75		add_library(Python::Python ALIAS Python2::Python)
76		set(Python_EXECUTABLE ${Python2_EXECUTABLE})
77		set(Python_SITEARCH ${Python2_SITEARCH})
78	endif()
79	set(LIBXML2_PYTHON_INSTALL_DIR ${Python_SITEARCH} CACHE PATH "Python bindings install directory")
80endif()
81
82if(LIBXML2_WITH_THREADS)
83	find_package(Threads REQUIRED)
84endif()
85
86if(LIBXML2_WITH_ZLIB)
87	find_package(ZLIB REQUIRED)
88endif()
89
90foreach(VARIABLE IN ITEMS WITH_AUTOMATA WITH_C14N WITH_CATALOG WITH_DEBUG WITH_DOCB WITH_EXPR WITH_FTP WITH_HTML WITH_HTTP WITH_ICONV WITH_ICU WITH_ISO8859X WITH_LEGACY WITH_LZMA WITH_MEM_DEBUG WITH_MODULES WITH_OUTPUT WITH_PATTERN WITH_PUSH WITH_READER WITH_REGEXPS WITH_RUN_DEBUG WITH_SAX1 WITH_SCHEMAS WITH_SCHEMATRON WITH_THREADS WITH_THREAD_ALLOC WITH_TREE WITH_TRIO WITH_UNICODE WITH_VALID WITH_WRITER WITH_XINCLUDE WITH_XPATH WITH_XPTR WITH_ZLIB)
91	if(LIBXML2_${VARIABLE})
92		set(${VARIABLE} 1)
93	else()
94		set(${VARIABLE} 0)
95	endif()
96endforeach()
97
98set(LIBXML_MAJOR_VERSION ${PROJECT_VERSION_MAJOR})
99set(LIBXML_MINOR_VERSION ${PROJECT_VERSION_MINOR})
100set(LIBXML_MICRO_VERSION ${PROJECT_VERSION_PATCH})
101
102set(VERSION "${LIBXML_MAJOR_VERSION}.${LIBXML_MINOR_VERSION}.${LIBXML_MICRO_VERSION}")
103set(LIBXML_VERSION ${LIBXML_MAJOR_VERSION}0${LIBXML_MINOR_VERSION}0${LIBXML_MICRO_VERSION})
104set(LIBXML_VERSION_STRING "${LIBXML_VERSION}")
105set(LIBXML_VERSION_EXTRA "")
106set(LIBXML_VERSION_NUMBER ${LIBXML_VERSION})
107
108set(MODULE_EXTENSION "${CMAKE_SHARED_LIBRARY_SUFFIX}")
109
110set(PACKAGE "libxml2")
111set(PACKAGE_BUGREPORT "xml@gnome.org")
112set(PACKAGE_NAME "libxml2")
113set(PACKAGE_STRING "libxml2 ${VERSION}")
114set(PACKAGE_TARNAME "libxml2")
115set(PACKAGE_URL "http://www.xmlsoft.org/")
116set(PACKAGE_VERSION ${VERSION})
117
118if(LIBLZMA_FOUND)
119	list(APPEND CMAKE_REQUIRED_LIBRARIES LibLZMA::LibLZMA)
120endif()
121
122if(Threads_FOUND)
123	list(APPEND CMAKE_REQUIRED_LIBRARIES Threads::Threads)
124endif()
125
126if(ZLIB_FOUND)
127	list(APPEND CMAKE_REQUIRED_LIBRARIES ZLIB::ZLIB)
128endif()
129
130if(MSVC)
131	configure_file(include/win32config.h config.h COPYONLY)
132else()
133	check_c_source_compiles("
134		void __attribute__((destructor))
135		f(void) {}
136		int main(void) { return 0; }
137	" ATTRIBUTE_DESTRUCTOR)
138	check_c_source_compiles("
139		#include <netdb.h>
140		int main() { (void) gethostbyname((const char*) \"\"); return 0; }
141	" GETHOSTBYNAME_ARG_CAST_CONST)
142	if(NOT GETHOSTBYNAME_ARG_CAST_CONST)
143		set(GETHOSTBYNAME_ARG_CAST "(char *)")
144	else()
145		set(GETHOSTBYNAME_ARG_CAST "/**/")
146	endif()
147	check_include_files(arpa/inet.h HAVE_ARPA_INET_H)
148	check_include_files(arpa/nameser.h HAVE_ARPA_NAMESER_H)
149	check_struct_has_member("struct sockaddr_storage" ss_family "sys/socket.h;sys/types.h" HAVE_SS_FAMILY)
150	check_struct_has_member("struct sockaddr_storage" __ss_family "sys/socket.h;sys/types.h" HAVE_BROKEN_SS_FAMILY)
151	if(HAVE_BROKEN_SS_FAMILY)
152		set(ss_family __ss_family)
153	endif()
154	check_function_exists(class HAVE_CLASS)
155	check_include_files(ctype.h HAVE_CTYPE_H)
156	check_include_files(dirent.h HAVE_DIRENT_H)
157	check_include_files(dlfcn.h HAVE_DLFCN_H)
158	check_library_exists(dl dlopen "" HAVE_DLOPEN)
159	check_include_files(dl.h HAVE_DL_H)
160	check_include_files(errno.h HAVE_ERRNO_H)
161	check_include_files(fcntl.h HAVE_FCNTL_H)
162	check_function_exists(finite HAVE_FINITE)
163	check_include_files(float.h HAVE_FLOAT_H)
164	check_function_exists(fpclass HAVE_FPCLASS)
165	check_function_exists(fprintf HAVE_FPRINTF)
166	check_function_exists(fp_class HAVE_FP_CLASS)
167	check_function_exists(ftime HAVE_FTIME)
168	check_function_exists(getaddrinfo HAVE_GETADDRINFO)
169	check_function_exists(gettimeofday HAVE_GETTIMEOFDAY)
170	check_include_files(inttypes.h HAVE_INTTYPES_H)
171	check_function_exists(isascii HAVE_ISASCII)
172	check_function_exists(isinf HAVE_ISINF)
173	check_function_exists(isnan HAVE_ISNAN)
174	check_function_exists(isnand HAVE_ISNAND)
175	check_library_exists(history append_history "" HAVE_LIBHISTORY)
176	check_library_exists(lzma lzma_code "" HAVE_LIBLZMA)
177	check_library_exists(pthread pthread_join "" HAVE_LIBPTHREAD)
178	check_library_exists(readline readline "" HAVE_LIBREADLINE)
179	check_library_exists(z gzread "" HAVE_LIBZ)
180	check_include_files(limits.h HAVE_LIMITS_H)
181	check_function_exists(localtime HAVE_LOCALTIME)
182	check_include_files(lzma.h HAVE_LZMA_H)
183	check_include_files(malloc.h HAVE_MALLOC_H)
184	check_include_files(math.h HAVE_MATH_H)
185	check_include_files(memory.h HAVE_MEMORY_H)
186	check_function_exists(mmap HAVE_MMAP)
187	check_function_exists(munmap HAVE_MUNMAP)
188	check_symbol_exists(DIR ndir.h HAVE_NDIR_H)
189	check_include_files(netdb.h HAVE_NETDB_H)
190	check_include_files(netinet/in.h HAVE_NETINET_IN_H)
191	check_include_files(poll.h HAVE_POLL_H)
192	check_function_exists(printf HAVE_PRINTF)
193	check_include_files(pthread.h HAVE_PTHREAD_H)
194	check_function_exists(putenv HAVE_PUTENV)
195	check_function_exists(rand HAVE_RAND)
196	check_function_exists(rand_r HAVE_RAND_R)
197	check_include_files(resolv.h HAVE_RESOLV_H)
198	check_library_exists(dld shl_load "" HAVE_SHLLOAD)
199	check_function_exists(signal HAVE_SIGNAL)
200	check_include_files(signal.h HAVE_SIGNAL_H)
201	check_function_exists(snprintf HAVE_SNPRINTF)
202	check_function_exists(sprintf HAVE_SPRINTF)
203	check_function_exists(srand HAVE_SRAND)
204	check_function_exists(sscanf HAVE_SSCANF)
205	check_function_exists(stat HAVE_STAT)
206	check_include_files(stdarg.h HAVE_STDARG_H)
207	check_include_files(stdint.h HAVE_STDINT_H)
208	check_include_files(stdlib.h HAVE_STDLIB_H)
209	check_function_exists(strftime HAVE_STRFTIME)
210	check_include_files(strings.h HAVE_STRINGS_H)
211	check_include_files(string.h HAVE_STRING_H)
212	check_symbol_exists(DIR sys/dir.h HAVE_SYS_DIR_H)
213	check_include_files(sys/mman.h HAVE_SYS_MMAN_H)
214	check_symbol_exists(DIR sys/ndir.h HAVE_SYS_NDIR_H)
215	check_include_files(sys/select.h HAVE_SYS_SELECT_H)
216	check_include_files(sys/socket.h HAVE_SYS_SOCKET_H)
217	check_include_files(sys/stat.h HAVE_SYS_STAT_H)
218	check_include_files(sys/timeb.h HAVE_SYS_TIMEB_H)
219	check_include_files(sys/time.h HAVE_SYS_TIME_H)
220	check_include_files(sys/types.h HAVE_SYS_TYPES_H)
221	check_function_exists(time HAVE_TIME)
222	check_include_files(time.h HAVE_TIME_H)
223	check_include_files(unistd.h HAVE_UNISTD_H)
224	check_function_exists(va_copy HAVE_VA_COPY)
225	check_function_exists(vfprintf HAVE_VFPRINTF)
226	check_function_exists(vsnprintf HAVE_VSNPRINTF)
227	check_function_exists(vsprintf HAVE_VSPRINTF)
228	check_function_exists(__va_copy HAVE___VA_COPY)
229	check_c_source_compiles("
230		#include <stdlib.h>
231		#include <iconv.h>
232		extern
233		#ifdef __cplusplus
234		\"C\"
235		#endif
236		#if defined(__STDC__) || defined(__cplusplus)
237		size_t iconv(iconv_t cd, char** inbuf, size_t* inbytesleft, char** outbuf, size_t* outbytesleft);
238		#else
239		size_t iconv();
240		#endif
241		int main() { return 0; }
242	" ICONV_CONST_TEST)
243	if(NOT ICONV_CONST_TEST)
244		set(ICONV_CONST "const")
245	endif()
246	set(LT_OBJDIR ".libs/")
247	check_c_source_compiles("
248		#include <sys/socket.h>
249		#include <sys/types.h>
250		int main() { (void) send(1, (const char*) \"\", 1, 1); return 0; }
251	" SEND_ARG2_CAST_CONST)
252	if(NOT SEND_ARG2_CAST_CONST)
253		set(SEND_ARG2_CAST "(char *)")
254	else()
255		set(SEND_ARG2_CAST "/**/")
256	endif()
257	check_include_files("float.h;stdarg.h;stdlib.h;string.h" STDC_HEADERS)
258	check_c_source_compiles("
259		#include <stdarg.h>
260		void a(va_list* ap) {};
261		int main() { va_list ap1, ap2; a(&ap1); ap2 = (va_list) ap1; return 0; }
262	" VA_LIST_IS_ARRAY_TEST)
263	if(VA_LIST_IS_ARRAY_TEST)
264		set(VA_LIST_IS_ARRAY FALSE)
265	else()
266		set(VA_LIST_IS_ARRAY TRUE)
267	endif()
268	check_c_source_compiles("
269		#include <stddef.h>
270		#include <sys/socket.h>
271		#include <sys/types.h>
272		int main() { (void) getsockopt(1, 1, 1, NULL, (socklen_t*) NULL); return 0; }
273	" XML_SOCKLEN_T_SOCKLEN_T)
274	if(XML_SOCKLEN_T_SOCKLEN_T)
275		set(XML_SOCKLEN_T socklen_t)
276	else()
277		check_c_source_compiles("
278			#include <stddef.h>
279			#include <sys/socket.h>
280			#include <sys/types.h>
281			int main() { (void) getsockopt(1, 1, 1, NULL, (size_t*) NULL); return 0; }
282		" XML_SOCKLEN_T_SIZE_T)
283		if(XML_SOCKLEN_T_SIZE_T)
284			set(XML_SOCKLEN_T size_t)
285		else()
286			check_c_source_compiles("
287				#include <stddef.h>
288				#include <sys/socket.h>
289				#include <sys/types.h>
290				int main() { (void) getsockopt (1, 1, 1, NULL, (int*) NULL); return 0; }
291			" XML_SOCKLEN_T_INT)
292			set(XML_SOCKLEN_T int)
293		endif()
294	endif()
295	configure_file(config.h.cmake.in config.h)
296endif()
297
298set(
299	LIBXML2_HDRS
300	include/libxml/c14n.h
301	include/libxml/catalog.h
302	include/libxml/chvalid.h
303	include/libxml/debugXML.h
304	include/libxml/dict.h
305	include/libxml/DOCBparser.h
306	include/libxml/encoding.h
307	include/libxml/entities.h
308	include/libxml/globals.h
309	include/libxml/hash.h
310	include/libxml/HTMLparser.h
311	include/libxml/HTMLtree.h
312	include/libxml/list.h
313	include/libxml/nanoftp.h
314	include/libxml/nanohttp.h
315	include/libxml/parser.h
316	include/libxml/parserInternals.h
317	include/libxml/pattern.h
318	include/libxml/relaxng.h
319	include/libxml/SAX.h
320	include/libxml/SAX2.h
321	include/libxml/schemasInternals.h
322	include/libxml/schematron.h
323	include/libxml/threads.h
324	include/libxml/tree.h
325	include/libxml/uri.h
326	include/libxml/valid.h
327	include/libxml/xinclude.h
328	include/libxml/xlink.h
329	include/libxml/xmlIO.h
330	include/libxml/xmlautomata.h
331	include/libxml/xmlerror.h
332	include/libxml/xmlexports.h
333	include/libxml/xmlmemory.h
334	include/libxml/xmlmodule.h
335	include/libxml/xmlreader.h
336	include/libxml/xmlregexp.h
337	include/libxml/xmlsave.h
338	include/libxml/xmlschemas.h
339	include/libxml/xmlschemastypes.h
340	include/libxml/xmlstring.h
341	include/libxml/xmlunicode.h
342	include/libxml/xmlwriter.h
343	include/libxml/xpath.h
344	include/libxml/xpathInternals.h
345	include/libxml/xpointer.h
346)
347
348set(
349	LIBXML2_SRCS
350	buf.c
351	c14n.c
352	catalog.c
353	chvalid.c
354	debugXML.c
355	dict.c
356	encoding.c
357	entities.c
358	error.c
359	globals.c
360	hash.c
361	HTMLparser.c
362	HTMLtree.c
363	legacy.c
364	list.c
365	nanoftp.c
366	nanohttp.c
367	parser.c
368	parserInternals.c
369	pattern.c
370	relaxng.c
371	SAX.c
372	SAX2.c
373	schematron.c
374	threads.c
375	tree.c
376	uri.c
377	valid.c
378	xinclude.c
379	xlink.c
380	xmlIO.c
381	xmlmemory.c
382	xmlmodule.c
383	xmlreader.c
384	xmlregexp.c
385	xmlsave.c
386	xmlschemas.c
387	xmlschemastypes.c
388	xmlstring.c
389	xmlunicode.c
390	xmlwriter.c
391	xpath.c
392	xpointer.c
393	xzlib.c
394)
395
396if(WIN32)
397	list(APPEND LIBXML2_SRCS win32/libxml2.rc)
398	file(
399		WRITE
400		${CMAKE_CURRENT_BINARY_DIR}/rcVersion.h
401		"#define LIBXML_MAJOR_VERSION ${LIBXML_MAJOR_VERSION}\n"
402		"#define LIBXML_MINOR_VERSION ${LIBXML_MINOR_VERSION}\n"
403		"#define LIBXML_MICRO_VERSION ${LIBXML_MICRO_VERSION}\n"
404		"#define LIBXML_DOTTED_VERSION \"${VERSION}\"\n"
405	)
406endif()
407
408if(LIBXML2_WITH_SAX1)
409	list(APPEND LIBXML2_SRCS DOCBparser.c)
410endif()
411
412if(LIBXML2_WITH_TRIO)
413	list(APPEND LIBXML2_SRCS trio.c triostr.c)
414endif()
415
416add_library(LibXml2 ${LIBXML2_HDRS} ${LIBXML2_SRCS})
417
418if(NOT BUILD_SHARED_LIBS)
419	target_compile_definitions(LibXml2 INTERFACE LIBXML_STATIC)
420	set(XML_CFLAGS "-DLIBXML_STATIC")
421endif()
422
423if(LIBXML2_WITH_THREADS)
424	target_compile_definitions(LibXml2 PRIVATE _REENTRANT)
425	if(WIN32)
426		target_compile_definitions(LibXml2 PRIVATE HAVE_WIN32_THREADS)
427	endif()
428endif()
429
430target_include_directories(
431	LibXml2
432	PUBLIC
433	$<BUILD_INTERFACE:${CMAKE_CURRENT_BINARY_DIR}>
434	$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/include>
435	$<INSTALL_INTERFACE:$<INSTALL_PREFIX>/${CMAKE_INSTALL_INCLUDEDIR}/libxml2>
436)
437
438if(HAVE_DLOPEN)
439	target_link_libraries(LibXml2 PRIVATE dl)
440	set(MODULE_PLATFORM_LIBS "-ldl")
441endif()
442
443if(HAVE_SHLLOAD)
444	target_link_libraries(LibXml2 PRIVATE dld)
445	set(MODULE_PLATFORM_LIBS "-ldld")
446endif()
447
448if(UNIX)
449	target_link_libraries(LibXml2 PRIVATE m)
450	set(M_LIBS "-lm")
451endif()
452
453if(WIN32)
454	target_link_libraries(LibXml2 PRIVATE ws2_32)
455	set(WIN32_EXTRA_LIBADD "-lws2_32")
456endif()
457
458if(LIBXML2_WITH_ICONV)
459	target_link_libraries(LibXml2 PUBLIC Iconv::Iconv)
460	if(NOT Iconv_IS_BUILT_IN)
461		set(ICONV_LIBS "-liconv")
462	endif()
463endif()
464
465if(LIBXML2_WITH_ICU)
466	target_link_libraries(LibXml2 PRIVATE ICU::data ICU::i18n ICU::uc)
467	if(WIN32)
468		set(ICU_LIBS "-licudt -licuin -licuuc")
469	else()
470		set(ICU_LIBS "-licudata -licui18n -licuuc")
471	endif()
472endif()
473
474if(LIBXML2_WITH_LZMA)
475	target_link_libraries(LibXml2 PRIVATE LibLZMA::LibLZMA)
476	set(LZMA_LIBS "-llzma")
477endif()
478
479if(LIBXML2_WITH_THREADS)
480	target_link_libraries(LibXml2 PRIVATE Threads::Threads)
481	set(THREAD_LIBS ${CMAKE_THREAD_LIBS_INIT})
482endif()
483
484if(LIBXML2_WITH_ZLIB)
485	target_link_libraries(LibXml2 PRIVATE ZLIB::ZLIB)
486	set(Z_LIBS "-lz")
487endif()
488
489set_target_properties(
490	LibXml2
491	PROPERTIES
492	IMPORT_PREFIX lib
493	OUTPUT_NAME xml2
494	POSITION_INDEPENDENT_CODE ON
495	PREFIX lib
496	VERSION ${PROJECT_VERSION}
497)
498
499if(MSVC)
500	if(BUILD_SHARED_LIBS)
501		set_target_properties(
502			LibXml2
503			PROPERTIES
504			DEBUG_POSTFIX d
505		)
506	else()
507		set_target_properties(
508			LibXml2
509			PROPERTIES
510			DEBUG_POSTFIX sd
511			MINSIZEREL_POSTFIX s
512			RELEASE_POSTFIX s
513			RELWITHDEBINFO_POSTFIX s
514		)
515	endif()
516endif()
517
518install(FILES ${LIBXML2_HDRS} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libxml2/libxml COMPONENT development)
519
520install(
521	TARGETS	LibXml2
522	EXPORT LibXml2
523	ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT development
524	LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime NAMELINK_COMPONENT development
525	RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT runtime
526)
527
528if(MSVC AND BUILD_SHARED_LIBS)
529	install(FILES $<TARGET_PDB_FILE:LibXml2> DESTINATION ${CMAKE_INSTALL_BINDIR} CONFIGURATIONS Debug RelWithDebInfo COMPONENT debug)
530endif()
531
532if(LIBXML2_WITH_PROGRAMS)
533	set(
534		PROGRAMS
535		xmlcatalog
536		xmllint
537	)
538	foreach(PROGRAM ${PROGRAMS})
539		add_executable(${PROGRAM} ${PROGRAM}.c)
540		target_link_libraries(${PROGRAM} LibXml2)
541		if(HAVE_LIBHISTORY)
542			target_link_libraries(${PROGRAM} history)
543		endif()
544		if(HAVE_LIBREADLINE)
545			target_link_libraries(${PROGRAM} readline)
546		endif()
547		install(TARGETS	${PROGRAM} EXPORT LibXml2 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT programs)
548	endforeach()
549endif()
550
551if(LIBXML2_WITH_TESTS)
552	enable_testing()
553	set(
554		TESTS
555		runxmlconf
556		runsuite
557		testapi
558		testAutomata
559		testC14N
560		testchar
561		testdict
562		testHTML
563		testModule
564		testlimits
565		testReader
566		testrecurse
567		testRegexp
568		testRelax
569		testSAX
570		testSchemas
571		testURI
572		testXPath
573	)
574	foreach(TEST ${TESTS})
575		add_executable(${TEST} ${TEST}.c)
576		target_link_libraries(${TEST} LibXml2)
577	endforeach()
578	if(EXISTS ${LIBXML2_XMLCONF_WORKING_DIR}/xmlconf/xmlconf.xml)
579		add_test(NAME runxmlconf COMMAND runxmlconf WORKING_DIRECTORY ${LIBXML2_XMLCONF_WORKING_DIR})
580	endif()
581	if(NOT WIN32)
582		add_test(NAME testapi COMMAND testapi)
583	endif()
584	add_test(NAME testchar COMMAND testchar)
585	add_test(NAME testdict COMMAND testdict)
586	add_test(NAME testrecurse COMMAND testrecurse WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
587	if(Threads_FOUND)
588		set(
589			TESTS_THREADS
590			runtest
591			testThreads
592		)
593		foreach(TEST ${TESTS_THREADS})
594			add_executable(${TEST} ${TEST}.c)
595			if(WIN32)
596				target_compile_definitions(${TEST} PRIVATE HAVE_WIN32_THREADS)
597			endif()
598			target_link_libraries(${TEST} LibXml2 Threads::Threads)
599		endforeach()
600		add_test(NAME runtest COMMAND runtest --out ${CMAKE_CURRENT_BINARY_DIR} WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
601		add_test(NAME testThreads COMMAND testThreads WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR})
602	endif()
603endif()
604
605if(LIBXML2_WITH_PYTHON)
606	execute_process(
607		COMMAND
608		${Python_EXECUTABLE}
609		${CMAKE_CURRENT_SOURCE_DIR}/python/generator.py
610		${CMAKE_CURRENT_SOURCE_DIR}/doc/libxml2-api.xml
611		${CMAKE_CURRENT_SOURCE_DIR}/python/libxml2-python-api.xml
612		WORKING_DIRECTORY
613		${CMAKE_CURRENT_BINARY_DIR}
614	)
615	file(READ python/libxml.py LIBXML_PY)
616	file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/libxml2.py.in "${LIBXML_PY}")
617	file(READ ${CMAKE_CURRENT_BINARY_DIR}/libxml2class.py LIBXML2CLASS_PY)
618	file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/libxml2.py.in "${LIBXML2CLASS_PY}")
619	configure_file(${CMAKE_CURRENT_BINARY_DIR}/libxml2.py.in libxml2.py COPYONLY)
620	add_library(
621		LibXml2Mod
622		libxml2-py.c
623		libxml2-py.h
624		python/libxml.c
625		python/libxml_wrap.h
626		python/types.c
627	)
628	target_include_directories(
629		LibXml2Mod
630		PUBLIC
631		$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/python>
632	)
633	target_link_libraries(LibXml2Mod LibXml2 Python::Python)
634	set_target_properties(
635		LibXml2Mod
636		PROPERTIES
637		IMPORT_PREFIX lib
638		OUTPUT_NAME xml2mod
639		PREFIX lib
640		VERSION ${PROJECT_VERSION}
641	)
642	install(
643		TARGETS	LibXml2Mod
644		ARCHIVE DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT development
645		LIBRARY DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT runtime NAMELINK_COMPONENT development
646		RUNTIME DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT runtime
647	)
648	if(MSVC AND BUILD_SHARED_LIBS)
649		install(FILES $<TARGET_PDB_FILE:LibXml2Mod> DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} CONFIGURATIONS Debug RelWithDebInfo COMPONENT debug)
650	endif()
651	install(FILES python/drv_libxml2.py DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT runtime)
652	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml2.py DESTINATION ${LIBXML2_PYTHON_INSTALL_DIR} COMPONENT runtime)
653endif()
654
655install(FILES libxml.3 DESTINATION ${CMAKE_INSTALL_MANDIR}/man3 COMPONENT documentation)
656install(FILES doc/xmlcatalog.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT documentation)
657install(FILES doc/xmllint.1 DESTINATION ${CMAKE_INSTALL_MANDIR}/man1 COMPONENT documentation)
658install(DIRECTORY doc/ DESTINATION ${CMAKE_INSTALL_DATADIR}/doc/libxml2 COMPONENT documentation PATTERN Makefile.* EXCLUDE)
659
660configure_package_config_file(
661	libxml2-config.cmake.cmake.in libxml2-config.cmake
662	INSTALL_DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION}
663)
664
665install(
666	FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config.cmake
667	DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION}
668	COMPONENT development
669)
670
671write_basic_package_version_file(
672	${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-version.cmake
673	VERSION ${PROJECT_VERSION}
674	COMPATIBILITY ExactVersion
675)
676
677install(
678	FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-version.cmake
679	DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION}
680	COMPONENT development
681)
682
683install(
684	EXPORT LibXml2
685	DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/libxml2-${PROJECT_VERSION}
686	NAMESPACE LibXml2::
687	FILE libxml2-export.cmake
688	COMPONENT development
689)
690
691configure_file(include/libxml/xmlversion.h.in libxml/xmlversion.h)
692install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml/xmlversion.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libxml2/libxml COMPONENT development)
693
694if(MSVC)
695	configure_file(include/libxml/xmlwin32version.h.in libxml/xmlwin32version.h)
696	install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml/xmlwin32version.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/libxml2/libxml COMPONENT development)
697endif()
698
699if(LIBXML2_WITH_PYTHON)
700	set(prefix "${CMAKE_INSTALL_PREFIX}")
701	configure_file(python/setup.py.in setup.py @ONLY)
702endif()
703
704set(XML_INCLUDEDIR "-I\${includedir}/libxml2")
705set(XML_LIBDIR "-L\${libdir}")
706set(XML_LIBS "-lxml2")
707set(XML_PRIVATE_LIBS "${Z_LIBS} ${LZMA_LIBS} ${THREAD_LIBS} ${ICONV_LIBS} ${ICU_LIBS} ${M_LIBS}")
708
709file(RELATIVE_PATH PACKAGE_RELATIVE_PATH "${CMAKE_INSTALL_FULL_LIBDIR}/pkgconfig" "${CMAKE_INSTALL_PREFIX}")
710string(REGEX REPLACE "/$" "" PACKAGE_RELATIVE_PATH "${PACKAGE_RELATIVE_PATH}")
711
712set(prefix "\${pcfiledir}/${PACKAGE_RELATIVE_PATH}")
713set(exec_prefix "\${prefix}")
714set(libdir "\${prefix}/${CMAKE_INSTALL_LIBDIR}")
715set(includedir "\${prefix}/${CMAKE_INSTALL_INCLUDEDIR}")
716configure_file(libxml-2.0.pc.in libxml-2.0.pc @ONLY)
717install(FILES ${CMAKE_CURRENT_BINARY_DIR}/libxml-2.0.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT development)
718
719set(prefix "\$(cd \"\$(dirname \"\$0\")\"; pwd -P)/..")
720configure_file(xml2-config.in xml2-config @ONLY)
721install(PROGRAMS ${CMAKE_CURRENT_BINARY_DIR}/xml2-config DESTINATION ${CMAKE_INSTALL_BINDIR} COMPONENT development)
722
723set(XML_INCLUDEDIR "-I${CMAKE_INSTALL_FULL_INCLUDEDIR}/libxml2")
724set(XML_LIBDIR "-L${CMAKE_INSTALL_FULL_LIBDIR}")
725configure_file(xml2Conf.sh.in xml2Conf.sh @ONLY)
726install(FILES ${CMAKE_CURRENT_BINARY_DIR}/xml2Conf.sh DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT development)
727
728set(CPACK_COMPONENT_DEVELOPMENT_DEPENDS runtime)
729set(CPACK_COMPONENT_PROGRAMS_DEPENDS runtime)
730set(CPACK_DEB_COMPONENT_INSTALL ON)
731set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_DEPENDS "${PACKAGE_TARNAME}")
732set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_NAME "${PACKAGE_TARNAME}-dev")
733set(CPACK_DEBIAN_DEVELOPMENT_PACKAGE_SECTION "libdevel")
734set(CPACK_DEBIAN_PACKAGE_HOMEPAGE ${PACKAGE_URL})
735set(CPACK_DEBIAN_PACKAGE_NAME ${PACKAGE_TARNAME})
736set(CPACK_DEBIAN_PACKAGE_SECTION "devel")
737set(CPACK_DEBIAN_PROGRAMS_PACKAGE_DEPENDS "${PACKAGE_TARNAME}")
738set(CPACK_DEBIAN_PROGRAMS_PACKAGE_NAME "${PACKAGE_TARNAME}-utils")
739set(CPACK_DEBIAN_PROGRAMS_PACKAGE_SECTION "utils")
740set(CPACK_DEBIAN_RUNTIME_PACKAGE_NAME ${PACKAGE_TARNAME})
741set(CPACK_DEBIAN_RUNTIME_PACKAGE_RECOMMENDS "${PACKAGE_TARNAME}-utils")
742set(CPACK_DEBIAN_RUNTIME_PACKAGE_SECTION "libs")
743set(CPACK_NSIS_PACKAGE_NAME ${PACKAGE_STRING})
744set(CPACK_NSIS_URL_INFO_ABOUT ${PACKAGE_URL})
745set(CPACK_PACKAGE_CONTACT ${PACKAGE_BUGREPORT})
746set(CPACK_PACKAGE_DISPLAY_NAME ${PACKAGE_STRING})
747set(CPACK_PACKAGE_INSTALL_DIRECTORY "${PACKAGE_TARNAME}-${PACKAGE_VERSION}")
748set(CPACK_PACKAGE_NAME ${PACKAGE_TARNAME})
749set(CPACK_PACKAGE_VERSION ${PACKAGE_VERSION})
750set(CPACK_PACKAGE_VERSION_MAJOR ${LIBXML_MAJOR_VERSION})
751set(CPACK_PACKAGE_VERSION_MINOR ${LIBXML_MINOR_VERSION})
752set(CPACK_PACKAGE_VERSION_PATCH ${LIBXML_MICRO_VERSION})
753set(CPACK_RESOURCE_FILE_LICENSE ${CMAKE_CURRENT_SOURCE_DIR}/Copyright)
754set(CPACK_RPM_COMPONENT_INSTALL ON)
755set(CPACK_RPM_development_PACKAGE_NAME "${PACKAGE_NAME}-devel")
756set(CPACK_RPM_development_PACKAGE_REQUIRES "${PACKAGE_NAME}")
757set(CPACK_RPM_PACKAGE_GROUP "Development/Libraries")
758set(CPACK_RPM_PACKAGE_NAME ${PACKAGE_TARNAME})
759set(CPACK_RPM_PACKAGE_URL ${PACKAGE_URL})
760set(CPACK_RPM_programs_PACKAGE_NAME "${PACKAGE_NAME}-utils")
761set(CPACK_RPM_programs_PACKAGE_REQUIRES "${PACKAGE_NAME}")
762set(CPACK_RPM_runtime_PACKAGE_NAME "${PACKAGE_NAME}")
763set(CPACK_RPM_runtime_PACKAGE_SUGGESTS "${PACKAGE_NAME}-utils")
764
765include(CPack)
766