Debian Codegraph @

cmake/backports/3.15.7/FindLibXml2.cmake

raw
1 # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
2 # file Copyright.txt or https://cmake.org/licensing for details.
3
4 #[=======================================================================[.rst:
5 FindLibXml2
6 -----------
7
8 Find the XML processing library (libxml2).
9
10 IMPORTED Targets
11 ^^^^^^^^^^^^^^^^
12
13 This module defines :prop_tgt:`IMPORTED` target ``LibXml2::LibXml2``, if
14 libxml2 has been found.
15
16 Result variables
17 ^^^^^^^^^^^^^^^^
18
19 This module will set the following variables in your project:
20
21 ``LibXml2_FOUND``
22 true if libxml2 headers and libraries were found
23 ``LIBXML2_INCLUDE_DIR``
24 the directory containing LibXml2 headers
25 ``LIBXML2_INCLUDE_DIRS``
26 list of the include directories needed to use LibXml2
27 ``LIBXML2_LIBRARIES``
28 LibXml2 libraries to be linked
29 ``LIBXML2_DEFINITIONS``
30 the compiler switches required for using LibXml2
31 ``LIBXML2_XMLLINT_EXECUTABLE``
32 path to the XML checking tool xmllint coming with LibXml2
33 ``LIBXML2_VERSION_STRING``
34 the version of LibXml2 found (since CMake 2.8.8)
35
36 Cache variables
37 ^^^^^^^^^^^^^^^
38
39 The following cache variables may also be set:
40
41 ``LIBXML2_INCLUDE_DIR``
42 the directory containing LibXml2 headers
43 ``LIBXML2_LIBRARY``
44 path to the LibXml2 library
45 #]=======================================================================]
46
47 # use pkg-config to get the directories and then use these values
48 # in the find_path() and find_library() calls
49 find_package(PkgConfig QUIET)
50 PKG_CHECK_MODULES(PC_LIBXML QUIET libxml-2.0)
51 set(LIBXML2_DEFINITIONS ${PC_LIBXML_CFLAGS_OTHER})
52
53 find_path(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h
54 HINTS
55 ${PC_LIBXML_INCLUDEDIR}
56 ${PC_LIBXML_INCLUDE_DIRS}
57 PATH_SUFFIXES libxml2
58 )
59
60 # CMake 3.9 and below used 'LIBXML2_LIBRARIES' as the name of
61 # the cache entry storing the find_library result. Use the
62 # value if it was set by the project or user.
63 if(DEFINED LIBXML2_LIBRARIES AND NOT DEFINED LIBXML2_LIBRARY)
64 set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES})
65 endif()
66
67 find_library(LIBXML2_LIBRARY NAMES xml2 libxml2
68 HINTS
69 ${PC_LIBXML_LIBDIR}
70 ${PC_LIBXML_LIBRARY_DIRS}
71 )
72
73 find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint)
74 # for backwards compat. with KDE 4.0.x:
75 set(XMLLINT_EXECUTABLE "${LIBXML2_XMLLINT_EXECUTABLE}")
76
77 if(PC_LIBXML_VERSION)
78 set(LIBXML2_VERSION_STRING ${PC_LIBXML_VERSION})
79 elseif(LIBXML2_INCLUDE_DIR AND EXISTS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h")
80 file(STRINGS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h" libxml2_version_str
81 REGEX "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\".*\"")
82
83 string(REGEX REPLACE "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\"([^\"]*)\".*" "\\1"
84 LIBXML2_VERSION_STRING "${libxml2_version_str}")
85 unset(libxml2_version_str)
86 endif()
87
88 set(LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR} ${PC_LIBXML_INCLUDE_DIRS})
89 set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARY})
90
91 include(FindPackageHandleStandardArgs)
92 FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2
93 REQUIRED_VARS LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR
94 VERSION_VAR LIBXML2_VERSION_STRING)
95
96 mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARY LIBXML2_XMLLINT_EXECUTABLE)
97
98 if(LibXml2_FOUND AND NOT TARGET LibXml2::LibXml2)
99 add_library(LibXml2::LibXml2 UNKNOWN IMPORTED)
100 set_target_properties(LibXml2::LibXml2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBXML2_INCLUDE_DIRS}")
101 set_property(TARGET LibXml2::LibXml2 APPEND PROPERTY IMPORTED_LOCATION "${LIBXML2_LIBRARY}")
102 endif()