-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathCMakeLists.txt
393 lines (364 loc) · 12.3 KB
/
CMakeLists.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
# ***** BEGIN LICENSE BLOCK *****
# Version: MPL 1.1/GPL 2.0/LGPL 2.1
#
# The contents of this file are subject to the Mozilla Public License Version
# 1.1 (the "License"); you may not use this file except in compliance with
# the License. You may obtain a copy of the License at
# http://www.mozilla.org/MPL/
#
# Software distributed under the License is distributed on an "AS IS" basis,
# WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
# for the specific language governing rights and limitations under the
# License.
#
# The Original Code is cmgui
#
# The Initial Developer of the Original Code is
# Auckland Uniservices Ltd, Auckland, New Zealand.
# Portions created by the Initial Developer are Copyright (C) 2005
# the Initial Developer. All Rights Reserved.
#
# Contributor(s):
#
# Alternatively, the contents of this file may be used under the terms of
# either the GNU General Public License Version 2 or later (the "GPL"), or
# the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
# in which case the provisions of the GPL or the LGPL are applicable instead
# of those above. If you wish to allow use of your version of this file only
# under the terms of either the GPL or the LGPL, and not to allow others to
# use your version of this file under the terms of the MPL, indicate your
# decision by deleting the provisions above and replace them with the notice
# and other provisions required by the GPL or the LGPL. If you do not delete
# the provisions above, a recipient may use your version of this file under
# the terms of any one of the MPL, the GPL or the LGPL.
#
# ***** END LICENSE BLOCK ***** */
cmake_minimum_required(VERSION 3.0)
project(libxml2 LANGUAGES C CXX VERSION 2.7.6)
option(BUILD_TESTS "${PROJECT_NAME} - Build tests" ON)
set(PACKAGE_CONFIG_DIR "lib/cmake" CACHE STRING "Directory for package config files (relative to CMAKE_INSTALL_PREFIX)")
option(WITH_ZLIB "Build in zlib support" ON)
option(BUILD_SHARED_LIBS "Build shared library." ON)
if (WITH_ZLIB)
find_package(ZLIB ${ZLIB_VERSION} REQUIRED)
endif()
if(NOT BUILD_SHARED_LIBS)
set(LIBRARY_INSTALL_TYPE ARCHIVE )
else()
set(LIBRARY_INSTALL_TYPE LIBRARY )
if(WIN32 )
set(LIBRARY_INSTALL_TYPE RUNTIME )
endif(WIN32 )
endif()
set(XML2_SRCS
c14n.c
catalog.c
chvalid.c
debugXML.c
dict.c
DOCBparser.c
encoding.c
entities.c
error.c
globals.c
hash.c
HTMLparser.c
HTMLtree.c
legacy.c
list.c
nanoftp.c
nanohttp.c
parser.c
parserInternals.c
pattern.c
relaxng.c
SAX.c
SAX2.c
schematron.c
threads.c
tree.c
uri.c
valid.c
xinclude.c
xlink.c
xmlIO.c
xmlmemory.c
xmlmodule.c
xmlreader.c
xmlregexp.c
xmlsave.c
xmlschemas.c
xmlschemastypes.c
xmlstring.c
xmlunicode.c
xmlwriter.c
xpath.c
xpointer.c )
set(PRIVATE_HDRS
acconfig.h
elfgcchack.h
libxml.h
trio.h
triodef.h
trionan.h
triop.h
triostr.h )
set(PUBLIC_HDRS
include/libxml/c14n.h
include/libxml/catalog.h
include/libxml/chvalid.h
include/libxml/debugXML.h
include/libxml/dict.h
include/libxml/DOCBparser.h
include/libxml/encoding.h
include/libxml/entities.h
include/libxml/globals.h
include/libxml/hash.h
include/libxml/HTMLparser.h
include/libxml/HTMLtree.h
include/libxml/list.h
include/libxml/nanoftp.h
include/libxml/nanohttp.h
include/libxml/parser.h
include/libxml/parserInternals.h
include/libxml/pattern.h
include/libxml/relaxng.h
include/libxml/SAX.h
include/libxml/SAX2.h
include/libxml/schemasInternals.h
include/libxml/schematron.h
include/libxml/threads.h
include/libxml/tree.h
include/libxml/uri.h
include/libxml/valid.h
include/libxml/xinclude.h
include/libxml/xlink.h
include/libxml/xmlautomata.h
include/libxml/xmlerror.h
include/libxml/xmlexports.h
include/libxml/xmlIO.h
include/libxml/xmlmemory.h
include/libxml/xmlmodule.h
include/libxml/xmlreader.h
include/libxml/xmlregexp.h
include/libxml/xmlsave.h
include/libxml/xmlschemas.h
include/libxml/xmlschemastypes.h
include/libxml/xmlstring.h
include/libxml/xmlunicode.h
include/libxml/xmlwriter.h
include/libxml/xpath.h
include/libxml/xpathInternals.h
include/libxml/xpointer.h )
set(PUBLIC_HDRS ${PUBLIC_HDRS} ${CMAKE_CURRENT_BINARY_DIR}/include/libxml/xmlversion.h )
if(MACOSX )
list(APPEND PRIVATE_HDRS
macos/src/config-mac.h
macos/src/xmltestprefix.h
macos/src/xmltestprefix2.h )
endif()
if(WIN32)
list(APPEND PRIVATE_HDRS
include/win32config.h
include/wsockcompat.h)
endif()
set(HAVE_PTHREAD_H ${CMAKE_HAVE_PTHREAD_H} )
set(HAVE_UNISTD_H ${CMAKE_HAVE_UNISTD_H} )
set(HAVE_LIMITS_H ${CMAKE_HAVE_LIMITS_H} )
set(HAVE_SYS_TYPES_H ${CMAKE_HAVE_SYS_PRCTL_H} )
set(ICONV_CONST const )
include(CheckIncludeFile)
set(CHECK_INC_FILES alloca ansidecl arpa/inet arpa/nameser
ctype dirent dl dlfcn errno fcntl float fp_class ieeefp
inttypes inttypes malloc math memory nan ndir netdb netinet/in
poll resolv signal stdarg stdint stdlib string strings
sys/dir sys/mman sys/ndir sys/select sys/socket sys/stat
sys/time sys/timeb time zlib)
foreach(incfile ${CHECK_INC_FILES})
string(REPLACE "/" "_" VARPART ${incfile})
string(TOUPPER ${VARPART} VARPART)
set(VARNAME HAVE_${VARPART}_H)
CHECK_INCLUDE_FILE(${incfile}.h ${VARNAME})
endforeach()
include(CheckIncludeFiles)
CHECK_INCLUDE_FILES("stdint.h;stddef.h;inttypes.h;stdlib.h;strings.h;string.h;float.h" StandardHeadersExist)
include(CheckFunctionExists)
set(CHECK_FUNCTIONS finite fpclass fprintf fp_class
ftime gettimeofday isnand localtime printf signal
snprintf sprintf sscanf stat strdup strerror
strftime strndup vfprintf vsnprintf vsprintf
_stat getaddrinfo)
foreach(funcname ${CHECK_FUNCTIONS})
string(TOUPPER ${funcname} FUNCNAME_UPPER)
CHECK_FUNCTION_EXISTS(${funcname} HAVE_${FUNCNAME_UPPER})
endforeach()
if(NOT (HAVE_PRINTF OR HAVE_SPRINTF OR HAVE_FPRINTF OR
HAVE_SNPRINTF OR HAVE_VFPRINTF OR HAVE_VSPRINTF OR HAVE_SSCANF))
message(STATUS "Not all required print functions found. Building with TRIO.")
set(WITH_TRIO 1)
# FYI trio source 'trionan.c' is #included in xpath.c
list(APPEND XML2_SRCS trio.c triostr.c)
else()
# Needed in CMake-configured files (xmlversion.h)
set(WITH_TRIO 0)
endif()
include(CheckSymbolExists)
if(StandardHeadersExist)
CHECK_SYMBOL_EXISTS( memchr string.h memchrExists )
if(memchrExists)
CHECK_SYMBOL_EXISTS(free stdlib.h STDC_HEADERS)
endif()
endif()
CHECK_SYMBOL_EXISTS(DIR "sys/dir.h" HAVE_SYS_DIR_H)
CHECK_SYMBOL_EXISTS(isinf math.h HAVE_ISINF)
CHECK_SYMBOL_EXISTS(isnan math.h HAVE_ISNAN)
CHECK_SYMBOL_EXISTS(va_copy stdarg.h HAVE_VA_COPY)
if (HAVE_SYS_SOCKET_H)
CHECK_SYMBOL_EXISTS(AF_INET6 "sys/types.h;sys/socket.h" SUPPORT_IP6)
endif()
include(CheckLibraryExists)
CHECK_LIBRARY_EXISTS(m exp "" HAVE_LIBM)
if(HAVE_DLFCN_H)
CHECK_LIBRARY_EXISTS(dl dlopen "" HAVE_DLOPEN)
endif()
set(INET_LIBRARIES bsd socket inet)
if(NOT HAVE_GETADDRINFO)
foreach(INET_LIB ${INET_LIBRARIES})
CHECK_LIBRARY_EXISTS(${INET_LIB} "getaddrinfo" "" HAVE_INET_LIB_${INET_LIB})
if (HAVE_INET_LIB_${INET_LIB})
set(HAVE_GETADDRINFO YES)
endif()
endforeach()
endif()
if (HAVE_SYS_SOCKET_H)
include(CheckStructHasMember)
CHECK_STRUCT_HAS_MEMBER(sockaddr_storage ss_family "sys/types.h;sys/socket.h" HAVE_SS_FAMILY)
if(NOT HAVE_SS_FAMILY)
CHECK_STRUCT_HAS_MEMBER(sockaddr_storage __ss_family "sys/types.h;sys/socket.h" HAVE_BROKEN_SS_FAMILY)
if(HAVE_BROKEN_SS_FAMILY)
set(ss_family __ss_family)
endif()
endif()
endif()
find_package(Threads)
if(CMAKE_USE_PTHREADS_INIT)
set(HAVE_LIBPTHREAD YES)
ADD_DEFINITIONS( -D_REENTRANT )
set(WITH_THREADS 1 )
else()
if(CMAKE_USE_WIN32_THREADS_INIT)
ADD_DEFINITIONS( -D_REENTRANT -DHAVE_WIN32_THREADS )
set(WITH_THREADS 1 )
else()
set(WITH_THREADS 0 )
endif()
endif()
set(WITH_TREE 1 )
set(WITH_OUTPUT 1 )
set(WITH_PUSH 1 )
set(WITH_READER 1 )
set(WITH_PATTERN 1 )
set(WITH_WRITER 1 )
set(WITH_SAX1 1 )
set(WITH_FTP 1 )
set(WITH_HTTP 1 )
set(WITH_VALID 1 )
set(WITH_HTML 1 )
set(WITH_LEGACY 0 )
set(WITH_CATALOG 1 )
set(WITH_DOCB 0 )
set(WITH_XPATH 0 )
set(WITH_XPTR 0 )
set(WITH_XINCLUDE 0 )
set(WITH_ICONV 0 )
set(WITH_ISO8859X 1 )
set(WITH_DEBUG 0 )
set(WITH_MEM_DEBUG 0 )
set(WITH_RUN_DEBUG 0 )
set(WITH_REGEXPS 1 )
set(WITH_SCHEMAS 1 )
set(WITH_MODULES 1 )
set(MODULE_EXTENSION ${CMAKE_SHARED_LIBRARY_SUFFIX})
set(WITH_C14N ${WITH_XPATH} )
set(WITH_SCHEMATRON ${WITH_XPATH} )
# Don't need this already a #define to include win32config.h when on windows
#if(WIN32)
# CONFIGURE_FILE(
# ${CMAKE_CURRENT_SOURCE_DIR}/include/win32config.h
# ${CMAKE_CURRENT_BINARY_DIR}/include/xml2_config.h
# COPYONLY )
#ELSE(WIN32)
if(NOT WIN32)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/xml2_config.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/include/xml2_config.h )
endif()
# Best to use 'Header Files' and 'Source Files' because any ungrouped files will be placed there by default
source_group( "Header Files\\libxml" FILES ${PUBLIC_HDRS} )
source_group( "Header Files\\" FILES ${PRIVATE_HDRS} )
source_group( "Source Files\\" FILES ${XML2_SRCS} )
set(LIBXML_VERSION_NUMBER ${PROJECT_VERSION_MAJOR}0${PROJECT_VERSION_MINOR}0${PROJECT_VERSION_PATCH}0)
set(LIBXML_VERSION_EXTRA OpenCMISS)
configure_file(
${CMAKE_CURRENT_SOURCE_DIR}/include/libxml/xmlversion.h.cmake
${CMAKE_CURRENT_BINARY_DIR}/include/libxml/xmlversion.h @ONLY )
set(CMAKE_DEBUG_POSTFIX "d" )
set(CMAKE_MFC_FLAG 0 )
add_library(xml2 ${XML2_SRCS} ${PUBLIC_HDRS} ${PRIVATE_HDRS} )
target_include_directories(xml2 PRIVATE ${CMAKE_CURRENT_BINARY_DIR}/include include)
target_compile_definitions(xml2 PUBLIC LIBXML_XPATH_ENABLED)
if (WIN32)
target_compile_definitions(xml2 PUBLIC _WINDOWS)
# Fix for nanoftp/nanohttp
target_link_libraries(xml2 PUBLIC ws2_32)
if(MSVC)
target_compile_definitions(xml2 PRIVATE _CRT_SECURE_NO_WARNINGS WINVER=0x0600)
endif()
endif()
if(NOT BUILD_SHARED_LIBS)
target_compile_definitions(xml2 PUBLIC LIBXML_STATIC)
set_target_properties(xml2 PROPERTIES POSITION_INDEPENDENT_CODE ON)
endif()
if(WITH_THREADS)
target_compile_definitions(xml2 PRIVATE _REENTRANT)
if(CMAKE_USE_WIN32_THREADS_INIT)
target_compile_definitions(xml2 PRIVATE HAVE_WIN32_THREADS)
endif()
endif()
if(WITH_ZLIB)
target_link_libraries(xml2 PUBLIC zlib)
target_compile_definitions(xml2 PRIVATE HAVE_ZLIB_H)
endif()
# We use dl functionality - other will need it too! (Its most likely libdl.so, so no symbols are pulled in)
if (HAVE_DLOPEN)
target_link_libraries(xml2 PUBLIC dl)
endif()
install(TARGETS xml2
EXPORT libxml2-config
DESTINATION lib
RUNTIME DESTINATION bin
INCLUDES DESTINATION include/libxml2)
install(FILES ${PUBLIC_HDRS}
DESTINATION include/libxml2/libxml)
install(EXPORT libxml2-config DESTINATION ${PACKAGE_CONFIG_DIR})
include(CMakePackageConfigHelpers)
WRITE_BASIC_PACKAGE_VERSION_FILE(${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-version.cmake
COMPATIBILITY AnyNewerVersion)
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-dependencies.cmake
"include(CMakeFindDependencyMacro)\r\n"
"set(${PROJECT_NAME}_IMPORT_PREFIX \${_IMPORT_PREFIX})\r\n")
if (WITH_ZLIB)
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-dependencies.cmake "set(ZLIB_FIND_SYSTEM ${ZLIB_FIND_SYSTEM})\r\nfind_dependency(ZLIB ${ZLIB_VERSION})\r\n")
endif()
file(APPEND ${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-dependencies.cmake "set(_IMPORT_PREFIX \${${PROJECT_NAME}_IMPORT_PREFIX})")
install(FILES
${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-version.cmake
${CMAKE_CURRENT_BINARY_DIR}/libxml2-config-dependencies.cmake
DESTINATION ${PACKAGE_CONFIG_DIR})
set(CPACK_PACKAGE_VERSION_MAJOR ${PROJECT_VERSION_MAJOR})
set(CPACK_PACKAGE_VERSION_MINOR ${PROJECT_VERSION_MINOR})
set(CPACK_PACKAGE_VERSION_PATCH ${PROJECT_VERSION_PATCH})
set(CPACK_PACKAGE_VERSION "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}")
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/Copyright")
set(CPACK_NSIS_MODIFY_PATH ON)
include(CPack)