FindLibXml2.cmake
Go to the documentation of this file.
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 # XXX: Copied from CMake, but includes vtkDetectLibraryType and the ICU dependency.
5 # See https://gitlab.kitware.com/cmake/cmake/-/issues/18564
6 
7 #[=======================================================================[.rst:
8 FindLibXml2
9 -----------
10 
11 Find the XML processing library (libxml2).
12 
13 IMPORTED Targets
14 ^^^^^^^^^^^^^^^^
15 
16 This module defines :prop_tgt:`IMPORTED` target ``LibXml2::LibXml2``, if
17 libxml2 has been found.
18 
19 Result variables
20 ^^^^^^^^^^^^^^^^
21 
22 This module will set the following variables in your project:
23 
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)
38 
39 Cache variables
40 ^^^^^^^^^^^^^^^
41 
42 The following cache variables may also be set:
43 
44 ``LIBXML2_INCLUDE_DIR``
45  the directory containing LibXml2 headers
46 ``LIBXML2_LIBRARY``
47  path to the LibXml2 library
48 #]=======================================================================]
49 
50 # use pkg-config to get the directories and then use these values
51 # in the find_path() and find_library() calls
52 find_package(PkgConfig QUIET)
53 PKG_CHECK_MODULES(PC_LIBXML QUIET libxml-2.0)
54 set(LIBXML2_DEFINITIONS ${PC_LIBXML_CFLAGS_OTHER})
55 
56 find_path(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h
57  HINTS
58  ${PC_LIBXML_INCLUDEDIR}
59  ${PC_LIBXML_INCLUDE_DIRS}
60  PATH_SUFFIXES libxml2
61  )
62 
63 # CMake 3.9 and below used 'LIBXML2_LIBRARIES' as the name of
64 # the cache entry storing the find_library result. Use the
65 # value if it was set by the project or user.
66 if(DEFINED LIBXML2_LIBRARIES AND NOT DEFINED LIBXML2_LIBRARY)
67  set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES})
68 endif()
69 
70 find_library(LIBXML2_LIBRARY NAMES xml2 libxml2
71  HINTS
72  ${PC_LIBXML_LIBDIR}
73  ${PC_LIBXML_LIBRARY_DIRS}
74  )
75 
76 find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint)
77 # for backwards compat. with KDE 4.0.x:
78 set(XMLLINT_EXECUTABLE "${LIBXML2_XMLLINT_EXECUTABLE}")
79 
80 if(PC_LIBXML_VERSION)
81  set(LIBXML2_VERSION_STRING ${PC_LIBXML_VERSION})
82 elseif(LIBXML2_INCLUDE_DIR AND EXISTS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h")
83  file(STRINGS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h" libxml2_version_str
84  REGEX "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\".*\"")
85 
86  string(REGEX REPLACE "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\"([^\"]*)\".*" "\\1"
87  LIBXML2_VERSION_STRING "${libxml2_version_str}")
88  unset(libxml2_version_str)
89 endif()
90 
91 set(LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR} ${PC_LIBXML_INCLUDE_DIRS})
92 set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARY})
93 
94 include(FindPackageHandleStandardArgs)
95 FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2
96  REQUIRED_VARS LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR
97  VERSION_VAR LIBXML2_VERSION_STRING)
98 
99 mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARY LIBXML2_XMLLINT_EXECUTABLE)
100 
101 if(LibXml2_FOUND AND NOT TARGET LibXml2::LibXml2)
102  include(vtkDetectLibraryType)
103  vtk_detect_library_type(libxml2_library_type
104  PATH "${LIBXML2_LIBRARY}")
105  add_library(LibXml2::LibXml2 "${libxml2_library_type}" IMPORTED)
106  unset(libxml2_library_type)
107  set_target_properties(LibXml2::LibXml2
108  PROPERTIES
109  IMPORTED_LOCATION "${LIBXML2_LIBRARY}"
110  IMPORTED_IMPLIB "${LIBXML2_LIBRARY}"
111  INTERFACE_INCLUDE_DIRECTORIES "${LIBXML2_INCLUDE_DIRS}")
112 
113  find_package(ICU QUIET COMPONENTS uc)
114  if (ICU_FOUND)
115  set_target_properties(LibXml2::LibXml2
116  PROPERTIES
117  IMPORTED_LINK_INTERFACE_LIBRARIES "ICU::uc")
118  endif ()
119 endif()
boost::graph_traits< vtkGraph *>::vertex_descriptor target(boost::graph_traits< vtkGraph *>::edge_descriptor e, vtkGraph *)
function vtk_detect_library_type(output)
Detect library type of a library.
version
string