diff options
-rw-r--r-- | Help/release/dev/libxml2-target.rst | 4 | ||||
-rw-r--r-- | Modules/FindLibXml2.cmake | 12 | ||||
-rw-r--r-- | Tests/CMakeLists.txt | 4 | ||||
-rw-r--r-- | Tests/FindLibXml2/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Tests/FindLibXml2/Test/CMakeLists.txt | 16 | ||||
-rw-r--r-- | Tests/FindLibXml2/Test/main.c | 19 |
6 files changed, 65 insertions, 0 deletions
diff --git a/Help/release/dev/libxml2-target.rst b/Help/release/dev/libxml2-target.rst new file mode 100644 index 0000000..f9933d7 --- /dev/null +++ b/Help/release/dev/libxml2-target.rst @@ -0,0 +1,4 @@ +libxml2-target +-------------- + +* The :module:`FindLibXml2` module now provides imported targets. diff --git a/Modules/FindLibXml2.cmake b/Modules/FindLibXml2.cmake index 8ac2980..615de49 100644 --- a/Modules/FindLibXml2.cmake +++ b/Modules/FindLibXml2.cmake @@ -7,6 +7,12 @@ # # Find the XML processing library (libxml2). # +# IMPORTED Targets +# ^^^^^^^^^^^^^^^^ +# +# This module defines :prop_tgt:`IMPORTED` target ``LibXml2::LibXml2``, if +# libxml2 has been found. +# # Result variables # ^^^^^^^^^^^^^^^^ # @@ -87,3 +93,9 @@ FIND_PACKAGE_HANDLE_STANDARD_ARGS(LibXml2 VERSION_VAR LIBXML2_VERSION_STRING) 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() diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index f34bc04..101502f 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1371,6 +1371,10 @@ ${CMake_BINARY_DIR}/bin/cmake -DDIR=dev -P ${CMake_SOURCE_DIR}/Utilities/Release add_subdirectory(FindLibUV) endif() + if(CMake_TEST_FindLibXml2) + add_subdirectory(FindLibXml2) + endif() + if(CMake_TEST_FindLTTngUST) add_subdirectory(FindLTTngUST) endif() diff --git a/Tests/FindLibXml2/CMakeLists.txt b/Tests/FindLibXml2/CMakeLists.txt new file mode 100644 index 0000000..6c2464f --- /dev/null +++ b/Tests/FindLibXml2/CMakeLists.txt @@ -0,0 +1,10 @@ +add_test(NAME FindLibXml2.Test COMMAND + ${CMAKE_CTEST_COMMAND} -C $<CONFIGURATION> + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindLibXml2/Test" + "${CMake_BINARY_DIR}/Tests/FindLibXml2/Test" + ${build_generator_args} + --build-project TestFindLibXml2 + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $<CONFIGURATION> + ) diff --git a/Tests/FindLibXml2/Test/CMakeLists.txt b/Tests/FindLibXml2/Test/CMakeLists.txt new file mode 100644 index 0000000..df5d8c3 --- /dev/null +++ b/Tests/FindLibXml2/Test/CMakeLists.txt @@ -0,0 +1,16 @@ +cmake_minimum_required(VERSION 3.4) +project(TestFindLibXml2 C) +include(CTest) + +find_package(LibXml2 REQUIRED) + +add_definitions(-DCMAKE_EXPECTED_LibXml2_VERSION="${LIBXML2_VERSION_STRING}") + +add_executable(test_tgt main.c) +target_link_libraries(test_tgt LibXml2::LibXml2) +add_test(NAME test_tgt COMMAND test_tgt) + +add_executable(test_var main.c) +target_include_directories(test_var PRIVATE ${LIBXML2_INCLUDE_DIRS}) +target_link_libraries(test_var PRIVATE ${LIBXML2_LIBRARIES}) +add_test(NAME test_var COMMAND test_var) diff --git a/Tests/FindLibXml2/Test/main.c b/Tests/FindLibXml2/Test/main.c new file mode 100644 index 0000000..264f07d --- /dev/null +++ b/Tests/FindLibXml2/Test/main.c @@ -0,0 +1,19 @@ +#include <assert.h> +#include <libxml/tree.h> +#include <string.h> + +int main() +{ + xmlDoc* doc; + + xmlInitParser(); + + doc = xmlNewDoc(BAD_CAST "1.0"); + xmlFreeDoc(doc); + + assert(strstr(CMAKE_EXPECTED_LibXml2_VERSION, LIBXML_DOTTED_VERSION)); + + xmlCleanupParser(); + + return 0; +} |