aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJoão Valverde <joao.valverde@tecnico.ulisboa.pt>2019-01-12 02:33:39 +0000
committerJoão Valverde <j@v6e.pt>2019-02-04 10:14:36 +0000
commitd17e218918a0f9c5df41ce14bbaeea516a4eec1c (patch)
treee115b5de4976517a59021329e33ba4a4e7c9e9d4
parent71d1740579a687bd7cc165212cf0007867717d3b (diff)
CMake: Update FindLibXml2.cmake
Change-Id: I55f77910be642535cba128900c2af40fa6824f04 Reviewed-on: https://code.wireshark.org/review/31874 Petri-Dish: João Valverde <j@v6e.pt> Tested-by: Petri Dish Buildbot Reviewed-by: João Valverde <j@v6e.pt>
-rw-r--r--CMakeLists.txt6
-rw-r--r--cmake/modules/FindLibXml2.cmake134
-rw-r--r--cmake/modules/FindWSWinLibs.cmake19
-rw-r--r--epan/CMakeLists.txt2
4 files changed, 90 insertions, 71 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 4f0ba19961..5cfe7b5265 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1097,12 +1097,6 @@ ws_find_package(SPANDSP ENABLE_SPANDSP HAVE_SPANDSP)
ws_find_package(BCG729 ENABLE_BCG729 HAVE_BCG729)
ws_find_package(LibXml2 ENABLE_LIBXML2 HAVE_LIBXML2)
-if(NOT LIBXML2_FOUND)
- # The (official) FindLibXml2.cmake file sets this cache variable to a
- # non-empty value, be sure to clear it when not found.
- set(LIBXML2_LIBRARIES "")
- set(LIBXML2_INCLUDE_DIR "")
-endif()
# Capabilities
ws_find_package(CAP ENABLE_CAP HAVE_LIBCAP)
diff --git a/cmake/modules/FindLibXml2.cmake b/cmake/modules/FindLibXml2.cmake
index 9677130b17..1f8becaea7 100644
--- a/cmake/modules/FindLibXml2.cmake
+++ b/cmake/modules/FindLibXml2.cmake
@@ -1,41 +1,54 @@
# This code was copied from https://gitlab.kitware.com/cmake/cmake/raw/master/Modules/FindLibXml2.cmake
# and modified to support Wireshark Windows 3rd party packages
-#.rst:
-# FindLibXml2
-# -----------
-#
-# Try to find the LibXml2 xml processing library
-#
-# Once done this will define
-#
-# ::
-#
-# LIBXML2_FOUND - System has LibXml2
-# LIBXML2_INCLUDE_DIR - The LibXml2 include directory
-# LIBXML2_LIBRARIES - The libraries needed to use LibXml2
-# LIBXML2_DEFINITIONS - Compiler switches required for using LibXml2
-# LIBXML2_XMLLINT_EXECUTABLE - The XML checking tool xmllint coming with LibXml2
-# LIBXML2_VERSION_STRING - the version of LibXml2 found (since CMake 2.8.8)
-#
-# :: Included for Wireshark build system
-# LIBXML2_DLL_DIR - (Windows) Path to the libxml2 DLL.
-# LIBXML2_DLL - (Windows) Name of the libxml2 DLL.
-
-
-#=============================================================================
-# Copyright 2006-2009 Kitware, Inc.
-# Copyright 2006 Alexander Neundorf <neundorf@kde.org>
-#
-# Distributed under the OSI-approved BSD License (the "License");
-# see accompanying file Copyright.txt for details.
-#
-# This software is distributed WITHOUT ANY WARRANTY; without even the
-# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-# See the License for more information.
-#=============================================================================
-# (To distribute this file outside of CMake, substitute the full
-# License text for the above reference.)
+# Distributed under the OSI-approved BSD 3-Clause License. See accompanying
+# file Copyright.txt or https://cmake.org/licensing for details.
+
+#[=======================================================================[.rst:
+FindLibXml2
+-----------
+
+Find the XML processing library (libxml2).
+
+IMPORTED Targets
+^^^^^^^^^^^^^^^^
+
+This module defines :prop_tgt:`IMPORTED` target ``LibXml2::LibXml2``, if
+libxml2 has been found.
+
+Result variables
+^^^^^^^^^^^^^^^^
+
+This module will set the following variables in your project:
+
+``LIBXML2_FOUND``
+ true if libxml2 headers and libraries were found
+``LIBXML2_INCLUDE_DIR``
+ the directory containing LibXml2 headers
+``LIBXML2_INCLUDE_DIRS``
+ list of the include directories needed to use LibXml2
+``LIBXML2_LIBRARIES``
+ LibXml2 libraries to be linked
+``LIBXML2_DEFINITIONS``
+ the compiler switches required for using LibXml2
+``LIBXML2_XMLLINT_EXECUTABLE``
+ path to the XML checking tool xmllint coming with LibXml2
+``LIBXML2_VERSION_STRING``
+ the version of LibXml2 found (since CMake 2.8.8)
+
+Cache variables
+^^^^^^^^^^^^^^^
+
+The following cache variables may also be set:
+
+``LIBXML2_INCLUDE_DIR``
+ the directory containing LibXml2 headers
+``LIBXML2_LIBRARY``
+ path to the LibXml2 library
+#]=======================================================================]
+
+include(FindWSWinLibs)
+FindWSWinLibs("libxml2-.*" LIBXML2_HINTS)
# use pkg-config to get the directories and then use these values
# in the find_path() and find_library() calls
@@ -43,27 +56,31 @@ find_package(PkgConfig QUIET)
PKG_CHECK_MODULES(PC_LIBXML QUIET libxml-2.0)
set(LIBXML2_DEFINITIONS ${PC_LIBXML_CFLAGS_OTHER})
-INCLUDE(FindWSWinLibs)
-FindWSWinLibs("libxml2-.*" "LIBXML2_HINTS")
-
find_path(LIBXML2_INCLUDE_DIR NAMES libxml/xpath.h
HINTS
${PC_LIBXML_INCLUDEDIR}
${PC_LIBXML_INCLUDE_DIRS}
- "${LIBXML2_HINTS}/include"
+ ${LIBXML2_HINTS}/include
PATH_SUFFIXES libxml2
)
-find_library(LIBXML2_LIBRARIES NAMES xml2 libxml2 libxml2-2
+# CMake 3.9 and below used 'LIBXML2_LIBRARIES' as the name of
+# the cache entry storing the find_library result. Use the
+# value if it was set by the project or user.
+if(DEFINED LIBXML2_LIBRARIES AND NOT DEFINED LIBXML2_LIBRARY)
+ set(LIBXML2_LIBRARY ${LIBXML2_LIBRARIES})
+endif()
+
+find_library(LIBXML2_LIBRARY NAMES xml2 libxml2 libxml2-2
HINTS
${PC_LIBXML_LIBDIR}
${PC_LIBXML_LIBRARY_DIRS}
- "${LIBXML2_HINTS}/lib"
+ ${LIBXML2_HINTS}/lib
)
find_program(LIBXML2_XMLLINT_EXECUTABLE xmllint
HINTS
- "${LIBXML2_HINTS}/bin"
+ ${LIBXML2_HINTS}/bin
)
# for backwards compat. with KDE 4.0.x:
set(XMLLINT_EXECUTABLE "${LIBXML2_XMLLINT_EXECUTABLE}")
@@ -79,31 +96,20 @@ elseif(LIBXML2_INCLUDE_DIR AND EXISTS "${LIBXML2_INCLUDE_DIR}/libxml/xmlversion.
unset(libxml2_version_str)
endif()
+set(LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR} ${PC_LIBXML_INCLUDE_DIRS})
+set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARY})
+
include(FindPackageHandleStandardArgs)
FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2
- REQUIRED_VARS LIBXML2_LIBRARIES LIBXML2_INCLUDE_DIR
+ REQUIRED_VARS LIBXML2_LIBRARY LIBXML2_INCLUDE_DIR
VERSION_VAR LIBXML2_VERSION_STRING)
-# Included for Wireshark build system. If libxml2 was found, include direct
-# paths to the DLLs for windows
-if(WIN32)
- if(LIBXML2_FOUND)
- set ( LIBXML2_DLL_DIR "${LIBXML2_HINTS}/bin"
- CACHE PATH "Path to Libxml2 DLL"
- )
- file( GLOB _libxml2_dll RELATIVE "${LIBXML2_DLL_DIR}"
- "${LIBXML2_DLL_DIR}/libxml2-*.dll"
- )
- set ( LIBXML2_DLL ${_libxml2_dll}
- # We're storing filenames only. Should we use STRING instead?
- CACHE FILEPATH "Libxml2 DLL file name"
- )
- mark_as_advanced( LIBXML2_DLL_DIR LIBXML2_DLL )
- else()
- set( LIBXML2_LIBRARIES )
- set( LIBXML2_DLL_DIR )
- set( LIBXML2_DLL )
- endif()
+mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARY LIBXML2_XMLLINT_EXECUTABLE)
+
+if(LibXml2_FOUND AND NOT TARGET LibXml2::LibXml2)
+ add_library(LibXml2::LibXml2 UNKNOWN IMPORTED)
+ set_target_properties(LibXml2::LibXml2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBXML2_INCLUDE_DIRS}")
+ set_property(TARGET LibXml2::LibXml2 APPEND PROPERTY IMPORTED_LOCATION "${LIBXML2_LIBRARY}")
endif()
-mark_as_advanced(LIBXML2_INCLUDE_DIR LIBXML2_LIBRARIES LIBXML2_XMLLINT_EXECUTABLE)
+AddWSWinDLL(LibXml2 LIBXML2_HINTS "libxml2-*")
diff --git a/cmake/modules/FindWSWinLibs.cmake b/cmake/modules/FindWSWinLibs.cmake
index 75568d49d8..088a020810 100644
--- a/cmake/modules/FindWSWinLibs.cmake
+++ b/cmake/modules/FindWSWinLibs.cmake
@@ -41,3 +41,22 @@ function( FindWSWinLibs _WS_LIB_SEARCH_PATH _LIB_HINT_VAR )
endforeach()
endif()
endfunction()
+
+function(AddWSWinDLL _PKG_NAME _PKG_HINTS _DLL_GLOB)
+ if(WIN32 AND ${_PKG_NAME}_FOUND)
+ string(TOUPPER ${_PKG_NAME} _PKG_VAR)
+ set ( ${_PKG_VAR}_DLL_DIR "${${_PKG_HINTS}}/bin"
+ CACHE PATH "Path to ${_PKG_NAME} DLL"
+ )
+ file( GLOB _pkg_dll RELATIVE "${${_PKG_VAR}_DLL_DIR}"
+ "${${_PKG_VAR}_DLL_DIR}/${_DLL_GLOB}.dll"
+ )
+ set ( ${_PKG_VAR}_DLL ${_pkg_dll}
+ CACHE STRING "${_PKG_NAME} DLL file name"
+ )
+ mark_as_advanced( ${_PKG_VAR}_DLL_DIR ${_PKG_VAR}_DLL )
+ else()
+ set( ${_PKG_VAR}_DLL_DIR )
+ set( ${_PKG_VAR}_DLL )
+ endif()
+endfunction()
diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt
index 2135d84153..651a8d2711 100644
--- a/epan/CMakeLists.txt
+++ b/epan/CMakeLists.txt
@@ -29,7 +29,7 @@ include_directories(
${SMI_INCLUDE_DIRS}
${SNAPPY_INCLUDE_DIRS}
${ZLIB_INCLUDE_DIRS}
- ${LIBXML2_INCLUDE_DIR}
+ ${LIBXML2_INCLUDE_DIRS}
)
add_definitions(