# XML (libxml2)
option(FUN_WITH_XML2 "Enable XML (libxml2) support" OFF)
set(LIBXML2_INCLUDE_DIRS "")
set(LIBXML2_LINK_LIBS "")
if(FUN_WITH_XML2)
  add_definitions(-DFUN_WITH_XML2)
  find_package(PkgConfig QUIET)
  if(PKG_CONFIG_FOUND)
    pkg_check_modules(LIBXML2 QUIET libxml-2.0)
  endif()
  if(LIBXML2_FOUND)
    list(APPEND LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIRS} ${LIBXML2_INCLUDE_DIRS})
    list(APPEND LIBXML2_LINK_LIBS ${LIBXML2_LINK_LIBS} ${LIBXML2_LIBRARIES})
  else()
    find_library(LIBXML2_LIB NAMES xml2 libxml2)
    if(LIBXML2_LIB)
      list(APPEND LIBXML2_LINK_LIBS ${LIBXML2_LIB})
      if(EXISTS "/usr/include/libxml2")
        list(APPEND LIBXML2_INCLUDE_DIRS "/usr/include/libxml2")
      endif()
    else()
      message(FATAL_ERROR "libxml2 not found. Install libxml2 (dev headers) or disable FUN_WITH_XML2.")
    endif()
  endif()
endif()
