1
0

FindLibXml2.cmake 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. # - Try to find the LibXml2 xml processing library
  2. # Once done this will define
  3. #
  4. # LIBXML2_FOUND - System has LibXml2
  5. # LIBXML2_INCLUDE_DIR - The LibXml2 include directory
  6. # LIBXML2_LIBRARIES - The libraries needed to use LibXml2
  7. # LIBXML2_DEFINITIONS - Compiler switches required for using LibXml2
  8. # LIBXML2_XMLLINT_EXECUTABLE - The XML checking tool xmllint coming with LibXml2
  9. # LIBXML2_VERSION_STRING - the version of LibXml2 found (since CMake 2.8.8)
  10. #=============================================================================
  11. # Copyright 2006-2009 Kitware, Inc.
  12. # Copyright 2006 Alexander Neundorf <[email protected]>
  13. #
  14. # Distributed under the OSI-approved BSD License (the "License");
  15. # see accompanying file Copyright.txt for details.
  16. #
  17. # This software is distributed WITHOUT ANY WARRANTY; without even the
  18. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  19. # See the License for more information.
  20. #=============================================================================
  21. # (To distribute this file outside of CMake, substitute the full
  22. # License text for the above reference.)
  23. # use pkg-config to get the directories and then use these values
  24. # in the find_path() and find_library() calls
  25. find_package(PkgConfig QUIET)
  26. PKG_CHECK_MODULES(PC_LIBXML QUIET libxml-2.0)
  27. set(LIBXML2_DEFINITIONS ${PC_LIBXML_CFLAGS_OTHER})
  28. find_path(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h
  29. HINTS
  30. ${PC_LIBXML_INCLUDEDIR}
  31. ${PC_LIBXML_INCLUDE_DIRS}
  32. PATH_SUFFIXES libxml2
  33. )
  34. find_library(LIBXML2_LIBRARIES NAMES xml2 libxml2
  35. HINTS
  36. ${PC_LIBXML_LIBDIR}
  37. ${PC_LIBXML_LIBRARY_DIRS}
  38. )
  39. find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint)
  40. # for backwards compat. with KDE 4.0.x:
  41. set(XMLLINT_EXECUTABLE "${LIBXML2_XMLLINT_EXECUTABLE}")
  42. if(PC_LIBXML_VERSION)
  43. set(LIBXML2_VERSION_STRING ${PC_LIBXML_VERSION})
  44. elseif(LIBXML2_INCLUDE_DIR AND EXISTS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h")
  45. file(STRINGS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.h" libxml2_version_str
  46. REGEX "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\".*\"")
  47. string(REGEX REPLACE "^#define[\t ]+LIBXML_DOTTED_VERSION[\t ]+\"([^\"]*)\".*" "\\1"
  48. LIBXML2_VERSION_STRING "${libxml2_version_str}")
  49. unset(libxml2_version_str)
  50. endif()
  51. # handle the QUIETLY and REQUIRED arguments and set LIBXML2_FOUND to TRUE if
  52. # all listed variables are TRUE
  53. include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
  54. FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2
  55. REQUIRED_VARS LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR
  56. VERSION_VAR LIBXML2_VERSION_STRING)
  57. mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARIES LIBXML2_XMLLINT_EXECUTABLE)