TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags
[wireshark-sm.git] / cmake / modules / FindLibXml2.cmake
blobd36b390b338c87689250f511be6a1d58190395d1
1 # This code was copied from https://gitlab.kitware.com/cmake/cmake/raw/master/Modules/FindLibXml2.cmake
2 # and modified to support Wireshark Windows 3rd party packages
4 # Distributed under the OSI-approved BSD 3-Clause License.  See accompanying
5 # file Copyright.txt or https://cmake.org/licensing for details.
7 #[=======================================================================[.rst:
8 FindLibXml2
9 -----------
11 Find the XML processing library (libxml2).
13 IMPORTED Targets
14 ^^^^^^^^^^^^^^^^
16 This module defines :prop_tgt:`IMPORTED` target ``LibXml2::LibXml2``, if
17 libxml2 has been found.
19 Result variables
20 ^^^^^^^^^^^^^^^^
22 This module will set the following variables in your project:
24 ``LIBXML2_FOUND``
25   true if libxml2 headers and libraries were found
26 ``LIBXML2_INCLUDE_DIR``
27   the directory containing LibXml2 headers
28 ``LIBXML2_INCLUDE_DIRS``
29   list of the include directories needed to use LibXml2
30 ``LIBXML2_LIBRARIES``
31   LibXml2 libraries to be linked
32 ``LIBXML2_DEFINITIONS``
33   the compiler switches required for using LibXml2
34 ``LIBXML2_XMLLINT_EXECUTABLE``
35   path to the XML checking tool xmllint coming with LibXml2
36 ``LIBXML2_VERSION_STRING``
37   the version of LibXml2 found (since CMake 2.8.8)
39 Cache variables
40 ^^^^^^^^^^^^^^^
42 The following cache variables may also be set:
44 ``LIBXML2_INCLUDE_DIR``
45   the directory containing LibXml2 headers
46 ``LIBXML2_LIBRARY``
47   path to the LibXml2 library
48 #]=======================================================================]
50 include(FindWSWinLibs)
51 FindWSWinLibs("vcpkg-export-.*" LIBXML2_HINTS)
53 if (NOT USE_REPOSITORY) # else we'll find Strawberry Perl's pkgconfig
54     # use pkg-config to get the directories and then use these values
55     # in the find_path() and find_library() calls
56     find_package(PkgConfig QUIET)
57     PKG_CHECK_MODULES(PC_LIBXML QUIET libxml-2.0)
58     set(LIBXML2_DEFINITIONS ${PC_LIBXML_CFLAGS_OTHER})
59 endif()
61 find_path(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h
62    HINTS
63    ${PC_LIBXML_INCLUDEDIR}
64    ${PC_LIBXML_INCLUDE_DIRS}
65    ${LIBXML2_HINTS}/include
66    PATH_SUFFIXES libxml2
67    )
69 find_path(ICONV_INCLUDE_DIR  NAMES iconv.h
70    HINTS
71    ${LIBXML2_HINTS}/include
72    )
74 # CMake 3.9 and below used 'LIBXML2_LIBRARIES' as the name of
75 # the cache entry storing the find_library result.  Use the
76 # value if it was set by the project or user.
77 if(DEFINED LIBXML2_LIBRARIES AND NOT DEFINED LIBXML2_LIBRARY)
78   set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES})
79 endif()
81 find_library(LIBXML2_LIBRARY NAMES xml2 libxml2 libxml2-2
82    HINTS
83    ${PC_LIBXML_LIBDIR}
84    ${PC_LIBXML_LIBRARY_DIRS}
85    ${LIBXML2_HINTS}/lib
86    )
88 find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint
89    HINTS
90    ${LIBXML2_HINTS}/bin
91    )
92 # for backwards compat. with KDE 4.0.x:
93 set(XMLLINT_EXECUTABLE "${LIBXML2_XMLLINT_EXECUTABLE}")
95 if(PC_LIBXML_VERSION)
96     set(LIBXML2_VERSION_STRING ${PC_LIBXML_VERSION})
97 elseif(LIBXML2_INCLUDE_DIR AND EXISTS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h")
98     file(STRINGS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h" libxml2_version_str
99          REGEX "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\".*\"")
101     string(REGEX REPLACE "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\"([^\"]*)\".*" "\\1"
102            LIBXML2_VERSION_STRING "${libxml2_version_str}")
103     unset(libxml2_version_str)
104 endif()
106 set(LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR} ${PC_LIBXML_INCLUDE_DIRS} ${ICONV_INCLUDE_DIR})
107 set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARY})
109 include(FindPackageHandleStandardArgs)
110 FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2
111                                   REQUIRED_VARS LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR
112                                   VERSION_VAR LIBXML2_VERSION_STRING)
114 mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARY LIBXML2_XMLLINT_EXECUTABLE)
116 if(LibXml2_FOUND)
117     # Include transitive dependencies for static linking.
118     if(UNIX AND CMAKE_FIND_LIBRARY_SUFFIXES STREQUAL ".a")
119         list(APPEND LIBXML2_LIBRARIES ${PC_LIBXML_LIBRARIES})
120     endif()
122     if (NOT TARGET LibXml2::LibXml2)
123         add_library(LibXml2::LibXml2 UNKNOWN IMPORTED)
124         set_target_properties(LibXml2::LibXml2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBXML2_INCLUDE_DIRS}")
125         set_property(TARGET LibXml2::LibXml2 APPEND PROPERTY IMPORTED_LOCATION "${LIBXML2_LIBRARY}")
126     endif()
127 endif()
129 AddWSWinDLLS(LibXml2 LIBXML2_HINTS "libxml2*" "liblzma*")