FindLibXml2.cmake 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  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. # 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(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  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)