summaryrefslogtreecommitdiffstats
path: root/cmake/modules/FindLibXml2.cmake
diff options
context:
space:
mode:
Diffstat (limited to 'cmake/modules/FindLibXml2.cmake')
-rw-r--r--cmake/modules/FindLibXml2.cmake84
1 files changed, 84 insertions, 0 deletions
diff --git a/cmake/modules/FindLibXml2.cmake b/cmake/modules/FindLibXml2.cmake
new file mode 100644
index 0000000..d6e389a
--- /dev/null
+++ b/cmake/modules/FindLibXml2.cmake
@@ -0,0 +1,84 @@
1#.rst:
2# FindLibXml2
3# -----------
4#
5# Try to find the LibXml2 xml processing library
6#
7# Once done this will define
8#
9# ::
10#
11# LIBXML2_FOUND - System has LibXml2
12# LIBXML2_INCLUDE_DIR - The LibXml2 include directory
13# LIBXML2_LIBRARIES - The libraries needed to use LibXml2
14# LIBXML2_DEFINITIONS - Compiler switches required for using LibXml2
15# LIBXML2_XMLLINT_EXECUTABLE - The XML checking tool xmllint coming with LibXml2
16# LIBXML2_VERSION_STRING - the version of LibXml2 found (since CMake 2.8.8)
17
18#=============================================================================
19# Copyright 2006-2009 Kitware, Inc.
20# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
21# Copyright 2016 Team Kodi
22#
23# Distributed under the OSI-approved BSD License (the "License");
24# see accompanying file Copyright.txt for details.
25#
26# This software is distributed WITHOUT ANY WARRANTY; without even the
27# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
28# See the License for more information.
29#=============================================================================
30# (To distribute this file outside of CMake, substitute the full
31# License text for the above reference.)
32
33# use pkg-config to get the directories and then use these values
34# in the find_path() and find_library() calls
35find_package(PkgConfig QUIET)
36PKG_CHECK_MODULES(PC_LIBXML QUIET libxml-2.0)
37set(LIBXML2_DEFINITIONS ${PC_LIBXML_CFLAGS_OTHER})
38
39find_path(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h
40 HINTS
41 ${PC_LIBXML_INCLUDEDIR}
42 ${PC_LIBXML_INCLUDE_DIRS}
43 PATH_SUFFIXES libxml2
44 )
45
46find_library(LIBXML2_LIBRARY NAMES xml2 libxml2
47 HINTS
48 ${PC_LIBXML_LIBDIR}
49 ${PC_LIBXML_LIBRARY_DIRS}
50 )
51
52find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint)
53# for backwards compat. with KDE 4.0.x:
54set(XMLLINT_EXECUTABLE "${LIBXML2_XMLLINT_EXECUTABLE}")
55
56# Make sure to use static flags if appropriate
57if(PC_LIBXML_FOUND)
58 if(${LIBXML2_LIBRARY} MATCHES ".+\.a$" AND PC_LIBXML_STATIC_LDFLAGS)
59 set(LIBXML2_LIBRARY ${LIBXML2_LIBRARY} ${PC_LIBXML_STATIC_LDFLAGS})
60 endif()
61endif()
62
63if(PC_LIBXML_VERSION)
64 set(LIBXML2_VERSION_STRING ${PC_LIBXML_VERSION})
65elseif(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)
71endif()
72
73
74include(FindPackageHandleStandardArgs)
75FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2
76 REQUIRED_VARS LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR
77 VERSION_VAR LIBXML2_VERSION_STRING)
78
79if(LibXml2_FOUND)
80 set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARY})
81 set(LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR})
82endif()
83
84mark_as_advanced(LIBXML2_INCLUDE_DIRS LIBXML2_LIBRARIES LIBXML2_XMLLINT_EXECUTABLE)