FindLibXml2.cmake 3.9 KB

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