diff --git a/libxml2-config.cmake.cmake.in b/libxml2-config.cmake.cmake.in index 4dec6275..8614f21b 100644 --- a/libxml2-config.cmake.cmake.in +++ b/libxml2-config.cmake.cmake.in @@ -2,18 +2,21 @@ # -------------------- # # Libxml2 cmake module. -# THis module sets the following variables: +# This module sets the following variables: # # :: # -# LIBXML2_INCLUDE_DIRS - Directory where libxml2 headers are located. -# LIBXML2_LIBRARIES - xml2 libraries to link against. -# LIBXML2_DEFINITIONS - the compiler switches required for using LibXml2 -# LIBXML2_VERSION_MAJOR - The major version of libxml2. -# LIBXML2_VERSION_MINOR - The minor version of libxml2. -# LIBXML2_VERSION_PATCH - The patch version of libxml2. -# LIBXML2_VERSION_STRING - version number as a string (ex: "2.3.4") -# LIBXML2_MODULES - whether libxml2 has dso support +# LIBXML2_INCLUDE_DIR - Directory where LibXml2 headers are located. +# LIBXML2_INCLUDE_DIRS - list of the include directories needed to use LibXml2. +# LIBXML2_LIBRARY - path to the LibXml2 library. +# LIBXML2_LIBRARIES - xml2 libraries to link against. +# LIBXML2_DEFINITIONS - the compiler switches required for using LibXml2. +# LIBXML2_VERSION_MAJOR - The major version of libxml2. +# LIBXML2_VERSION_MINOR - The minor version of libxml2. +# LIBXML2_VERSION_PATCH - The patch version of libxml2. +# LIBXML2_VERSION_STRING - version number as a string (ex: "2.3.4") +# LIBXML2_MODULES - whether libxml2 has dso support +# LIBXML2_XMLLINT_EXECUTABLE - path to the XML checking tool xmllint coming with LibXml2 include("${CMAKE_CURRENT_LIST_DIR}/libxml2-export.cmake") @@ -24,7 +27,7 @@ set(LIBXML2_VERSION_MINOR @LIBXML_MINOR_VERSION@) set(LIBXML2_VERSION_PATCH @LIBXML_MICRO_VERSION@) set(LIBXML2_VERSION_STRING "@VERSION@") set(LIBXML2_INSTALL_PREFIX ${PACKAGE_PREFIX_DIR}) -set(LIBXML2_INCLUDE_DIRS ${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@ ${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@/libxml2) +set(LIBXML2_INCLUDE_DIR ${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_INCLUDEDIR@/libxml2) set(LIBXML2_LIBRARY_DIR ${PACKAGE_PREFIX_DIR}/@CMAKE_INSTALL_LIBDIR@) macro(select_library_location target basename) @@ -33,26 +36,47 @@ macro(select_library_location target basename) get_target_property(${basename}_${property}_MINSIZEREL ${target} ${property}_MINSIZEREL) get_target_property(${basename}_${property}_RELEASE ${target} ${property}_RELEASE) get_target_property(${basename}_${property}_RELWITHDEBINFO ${target} ${property}_RELWITHDEBINFO) - + if(${basename}_${property}_DEBUG AND ${basename}_${property}_RELEASE) - set(${basename}_LIBRARIES debug ${${basename}_${property}_DEBUG} optimized ${${basename}_${property}_RELEASE}) + set(${basename}_LIBRARY debug ${${basename}_${property}_DEBUG} optimized ${${basename}_${property}_RELEASE}) elseif(${basename}_${property}_DEBUG AND ${basename}_${property}_RELWITHDEBINFO) - set(${basename}_LIBRARIES debug ${${basename}_${property}_DEBUG} optimized ${${basename}_${property}_RELWITHDEBINFO}) + set(${basename}_LIBRARY debug ${${basename}_${property}_DEBUG} optimized ${${basename}_${property}_RELWITHDEBINFO}) elseif(${basename}_${property}_DEBUG AND ${basename}_${property}_MINSIZEREL) - set(${basename}_LIBRARIES debug ${${basename}_${property}_DEBUG} optimized ${${basename}_${property}_MINSIZEREL}) + set(${basename}_LIBRARY debug ${${basename}_${property}_DEBUG} optimized ${${basename}_${property}_MINSIZEREL}) elseif(${basename}_${property}_RELEASE) - set(${basename}_LIBRARIES ${${basename}_${property}_RELEASE}) + set(${basename}_LIBRARY ${${basename}_${property}_RELEASE}) elseif(${basename}_${property}_RELWITHDEBINFO) - set(${basename}_LIBRARIES ${${basename}_${property}_RELWITHDEBINFO}) + set(${basename}_LIBRARY ${${basename}_${property}_RELWITHDEBINFO}) elseif(${basename}_${property}_MINSIZEREL) - set(${basename}_LIBRARIES ${${basename}_${property}_MINSIZEREL}) + set(${basename}_LIBRARY ${${basename}_${property}_MINSIZEREL}) elseif(${basename}_${property}_DEBUG) - set(${basename}_LIBRARIES ${${basename}_${property}_DEBUG}) + set(${basename}_LIBRARY ${${basename}_${property}_DEBUG}) endif() endforeach() endmacro() +macro(select_executable_location target basename) + get_target_property(${basename}_IMPORTED_LOCATION_DEBUG ${target} IMPORTED_LOCATION_DEBUG) + get_target_property(${basename}_IMPORTED_LOCATION_MINSIZEREL ${target} IMPORTED_LOCATION_MINSIZEREL) + get_target_property(${basename}_IMPORTED_LOCATION_RELEASE ${target} IMPORTED_LOCATION_RELEASE) + get_target_property(${basename}_IMPORTED_LOCATION_RELWITHDEBINFO ${target} IMPORTED_LOCATION_RELWITHDEBINFO) + + if(${basename}_IMPORTED_LOCATION_RELEASE) + set(${basename}_EXECUTABLE ${${basename}_IMPORTED_LOCATION_RELEASE}) + elseif(${basename}_IMPORTED_LOCATION_RELWITHDEBINFO) + set(${basename}_EXECUTABLE ${${basename}_IMPORTED_LOCATION_RELWITHDEBINFO}) + elseif(${basename}_IMPORTED_LOCATION_MINSIZEREL) + set(${basename}_EXECUTABLE ${${basename}_IMPORTED_LOCATION_MINSIZEREL}) + elseif(${basename}_IMPORTED_LOCATION_DEBUG) + set(${basename}_EXECUTABLE ${${basename}_IMPORTED_LOCATION_DEBUG}) + endif() +endmacro() + select_library_location(LibXml2::LibXml2 LIBXML2) +select_executable_location(LibXml2::xmllint LIBXML2_XMLLINT) + +set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARY}) +set(LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR}) include(CMakeFindDependencyMacro) @@ -100,4 +124,4 @@ endif() # whether libxml2 has dso support set(LIBXML2_MODULES @LIBXML2_WITH_MODULES@) -mark_as_advanced( LIBXML2_INCLUDE_DIRS LIBXML2_LIBRARIES ) +mark_as_advanced(LIBXML2_LIBRARY LIBXML2_XMLLINT_EXECUTABLE) diff --git a/libxml2-config.cmake.in b/libxml2-config.cmake.in index 6b16fc2e..73112efc 100644 --- a/libxml2-config.cmake.in +++ b/libxml2-config.cmake.in @@ -2,17 +2,26 @@ # -------------------- # # Libxml2 cmake module. -# THis module sets the following variables: +# This module sets the following variables: # # :: # -# LIBXML2_INCLUDE_DIRS - Directory where libxml2 headers are located. -# LIBXML2_LIBRARIES - xml2 libraries to link against. -# LIBXML2_VERSION_MAJOR - The major version of libxml2. -# LIBXML2_VERSION_MINOR - The minor version of libxml2. -# LIBXML2_VERSION_PATCH - The patch version of libxml2. -# LIBXML2_VERSION_STRING - version number as a string (ex: "2.3.4") -# LIBXML2_MODULES - whether libxml2 as dso support +# LIBXML2_INCLUDE_DIR - Directory where LibXml2 headers are located. +# LIBXML2_INCLUDE_DIRS - list of the include directories needed to use LibXml2. +# LIBXML2_LIBRARY - path to the LibXml2 library. +# LIBXML2_LIBRARIES - xml2 libraries to link against. +# LIBXML2_DEFINITIONS - the compiler switches required for using LibXml2. +# LIBXML2_VERSION_MAJOR - The major version of libxml2. +# LIBXML2_VERSION_MINOR - The minor version of libxml2. +# LIBXML2_VERSION_PATCH - The patch version of libxml2. +# LIBXML2_VERSION_STRING - version number as a string (ex: "2.3.4") +# LIBXML2_MODULES - whether libxml2 has dso support +# LIBXML2_XMLLINT_EXECUTABLE - path to the XML checking tool xmllint coming with LibXml2 +# +# The following targets are defined: +# +# LibXml2::LibXml2 - the LibXml2 library +# LibXml2::xmllint - the xmllint command-line executable get_filename_component(_libxml2_rootdir ${CMAKE_CURRENT_LIST_DIR}/../../../ ABSOLUTE) @@ -20,31 +29,78 @@ set(LIBXML2_VERSION_MAJOR @LIBXML_MAJOR_VERSION@) set(LIBXML2_VERSION_MINOR @LIBXML_MINOR_VERSION@) set(LIBXML2_VERSION_MICRO @LIBXML_MICRO_VERSION@) set(LIBXML2_VERSION_STRING "@VERSION@") +set(LIBXML2_DEFINITIONS "@XML_CFLAGS@") set(LIBXML2_INSTALL_PREFIX ${_libxml2_rootdir}) -set(LIBXML2_INCLUDE_DIRS ${_libxml2_rootdir}/include ${_libxml2_rootdir}/include/libxml2) +set(LIBXML2_INCLUDE_DIR ${_libxml2_rootdir}/include/libxml2) set(LIBXML2_LIBRARY_DIR ${_libxml2_rootdir}/lib) -set(LIBXML2_LIBRARIES -L${LIBXML2_LIBRARY_DIR} -lxml2) + +find_library(LIBXML2_LIBRARY NAMES xml2 HINTS ${LIBXML2_LIBRARY_DIR} NO_DEFAULT_PATH) +find_program(LIBXML2_XMLLINT_EXECUTABLE NAMES xmllint HINTS ${_libxml2_rootdir}/bin NO_DEFAULT_PATH) + +set(LIBXML2_LIBRARIES ${LIBXML2_LIBRARY}) +set(LIBXML2_INCLUDE_DIRS ${LIBXML2_INCLUDE_DIR}) +unset(LIBXML2_INTERFACE_LINK_LIBRARIES) + +include(CMakeFindDependencyMacro) + +if(@WITH_ICONV@) + find_dependency(Iconv) + list(APPEND LIBXML2_LIBRARIES ${Iconv_LIBRARIES}) + list(APPEND LIBXML2_INCLUDE_DIRS ${Iconv_INCLUDE_DIRS}) + list(APPEND LIBXML2_INTERFACE_LINK_LIBRARIES "Iconv::Iconv") +endif() if(@WITH_THREADS@) - find_package(Threads REQUIRED) - list(APPEND LIBXML2_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + find_dependency(Threads) + list(APPEND LIBXML2_LIBRARIES ${CMAKE_THREAD_LIBS_INIT}) + list(APPEND LIBXML2_INTERFACE_LINK_LIBRARIES "\$") +endif() + +if(@WITH_ICU@) + find_dependency(ICU) + list(APPEND LIBXML2_LIBRARIES ${ICU_LIBRARIES}) + list(APPEND LIBXML2_INCLUDE_DIRS ${ICU_INCLUDE_DIRS}) + list(APPEND LIBXML2_INTERFACE_LINK_LIBRARIES "\$") endif() if(@WITH_LZMA@) - find_package(LibLZMA REQUIRED) + find_dependency(LibLZMA) list(APPEND LIBXML2_LIBRARIES ${LIBLZMA_LIBRARIES}) list(APPEND LIBXML2_INCLUDE_DIRS ${LIBLZMA_INCLUDE_DIRS}) + list(APPEND LIBXML2_INTERFACE_LINK_LIBRARIES "\$") endif() if(@WITH_ZLIB@) - find_package(ZLIB REQUIRED) + find_dependency(ZLIB) list(APPEND LIBXML2_LIBRARIES ${ZLIB_LIBRARIES}) list(APPEND LIBXML2_INCLUDE_DIRS ${ZLIB_INCLUDE_DIRS}) + list(APPEND LIBXML2_INTERFACE_LINK_LIBRARIES "\$") endif() -list(APPEND LIBXML2_LIBRARIES @ICU_LIBS@ @ICONV_LIBS@ @M_LIBS@ @WIN32_EXTRA_LIBADD@ @LIBS@) +if(UNIX) + list(APPEND LIBXML2_LIBRARIES m) + list(APPEND LIBXML2_INTERFACE_LINK_LIBRARIES "\$") +endif() + +if(WIN32) + list(APPEND LIBXML2_LIBRARIES ws2_32) + list(APPEND LIBXML2_INTERFACE_LINK_LIBRARIES "\$") +endif() # whether libxml2 has dso support set(LIBXML2_MODULES @WITH_MODULES@) -mark_as_advanced( LIBXML2_INCLUDE_DIRS LIBXML2_LIBRARIES ) +mark_as_advanced(LIBXML2_LIBRARY LIBXML2_XMLLINT_EXECUTABLE) + +if(NOT TARGET LibXml2::LibXml2) + add_library(LibXml2::LibXml2 UNKNOWN IMPORTED) + set_target_properties(LibXml2::LibXml2 PROPERTIES IMPORTED_LOCATION "${LIBXML2_LIBRARY}") + set_target_properties(LibXml2::LibXml2 PROPERTIES INTERFACE_COMPILE_OPTIONS "${LIBXML2_DEFINITIONS}") + set_target_properties(LibXml2::LibXml2 PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBXML2_INCLUDE_DIRS}") + set_target_properties(LibXml2::LibXml2 PROPERTIES INTERFACE_LINK_LIBRARIES "${LIBXML2_INTERFACE_LINK_LIBRARIES}") +endif() + +if(NOT TARGET LibXml2::xmllint) + add_executable(LibXml2::xmllint IMPORTED) + set_target_properties(LibXml2::xmllint PROPERTIES IMPORTED_LOCATION "${LIBXML2_XMLLINT_EXECUTABLE}") +endif()