FindLibXml2.cmake 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. # file Copyright.txt or https://cmake.org/licensing for details.
  3. #.rst:
  4. # FindLibXml2
  5. # -----------
  6. #
  7. # Find the XML processing library (libxml2).
  8. #
  9. # Result variables
  10. # ^^^^^^^^^^^^^^^^
  11. #
  12. # This module will set the following variables in your project:
  13. #
  14. # ``LIBXML2_FOUND``
  15. # true if libxml2 headers and libraries were found
  16. # ``LIBXML2_INCLUDE_DIR``
  17. # the directory containing LibXml2 headers
  18. # ``LIBXML2_INCLUDE_DIRS``
  19. # list of the include directories needed to use LibXml2
  20. # ``LIBXML2_LIBRARIES``
  21. # LibXml2 libraries to be linked
  22. # ``LIBXML2_DEFINITIONS``
  23. # the compiler switches required for using LibXml2
  24. # ``LIBXML2_XMLLINT_EXECUTABLE``
  25. # path to the XML checking tool xmllint coming with LibXml2
  26. # ``LIBXML2_VERSION_STRING``
  27. # the version of LibXml2 found (since CMake 2.8.8)
  28. #
  29. # Cache variables
  30. # ^^^^^^^^^^^^^^^
  31. #
  32. # The following cache variables may also be set:
  33. #
  34. # ``LIBXML2_INCLUDE_DIR``
  35. # the directory containing LibXml2 headers
  36. # ``LIBXML2_LIBRARY``
  37. # path to the LibXml2 library
  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. find_library(LIBXML2_LIBRARY NAMES xml2 libxml2
  50. HINTS
  51. ${PC_LIBXML_LIBDIR}
  52. ${PC_LIBXML_LIBRARY_DIRS}
  53. )
  54. find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint)
  55. # for backwards compat. with KDE 4.0.x:
  56. set(XMLLINT_EXECUTABLE "${LIBXML2_XMLLINT_EXECUTABLE}")
  57. if(PC_LIBXML_VERSION)
  58. set(LIBXML2_VERSION_STRING ${PC_LIBXML_VERSION})
  59. elseif(LIBXML2_INCLUDE_DIR AND EXISTS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h")
  60. file(STRINGS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h" libxml2_version_str
  61. REGEX "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\".*\"")
  62. string(REGEX REPLACE "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\"([^\"]*)\".*" "\\1"
  63. LIBXML2_VERSION_STRING "${libxml2_version_str}")
  64. unset(libxml2_version_str)
  65. endif()
  66. set(LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR} ${PC_LIBXML_INCLUDE_DIRS})
  67. set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARY})
  68. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  69. FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2
  70. REQUIRED_VARS LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR
  71. VERSION_VAR LIBXML2_VERSION_STRING)
  72. mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARY LIBXML2_XMLLINT_EXECUTABLE)