From 1aa7df411474cd183af7049f3a53c8ac6be75a61 Mon Sep 17 00:00:00 2001 From: Markus Rickert Date: Wed, 22 Apr 2020 21:27:25 +0200 Subject: FindLibXslt: provide imported targets --- Help/release/dev/libxslt.rst | 4 ++++ Modules/FindLibXslt.cmake | 36 ++++++++++++++++++++++++++-- Tests/CMakeLists.txt | 1 + Tests/FindLibXslt/CMakeLists.txt | 10 ++++++++ Tests/FindLibXslt/Test/CMakeLists.txt | 45 +++++++++++++++++++++++++++++++++++ Tests/FindLibXslt/Test/libexslt.c | 16 +++++++++++++ Tests/FindLibXslt/Test/libxslt.c | 24 +++++++++++++++++++ 7 files changed, 134 insertions(+), 2 deletions(-) create mode 100644 Help/release/dev/libxslt.rst create mode 100644 Tests/FindLibXslt/CMakeLists.txt create mode 100644 Tests/FindLibXslt/Test/CMakeLists.txt create mode 100644 Tests/FindLibXslt/Test/libexslt.c create mode 100644 Tests/FindLibXslt/Test/libxslt.c diff --git a/Help/release/dev/libxslt.rst b/Help/release/dev/libxslt.rst new file mode 100644 index 0000000..ce3527e --- /dev/null +++ b/Help/release/dev/libxslt.rst @@ -0,0 +1,4 @@ +libxslt-target +-------------- + +* The :module:`FindLibXslt` module now provides imported targets. diff --git a/Modules/FindLibXslt.cmake b/Modules/FindLibXslt.cmake index 4f366a5..9bc855f 100644 --- a/Modules/FindLibXslt.cmake +++ b/Modules/FindLibXslt.cmake @@ -8,9 +8,22 @@ FindLibXslt Find the XSL Transformations, Extensible Stylesheet Language Transformations (XSLT) library (LibXslt) -Once done this will define +IMPORTED Targets +^^^^^^^^^^^^^^^^ -:: +The following :prop_tgt:`IMPORTED` targets may be defined: + +``LibXslt::LibXslt`` + If the libxslt library has been found +``LibXslt::LibExslt`` + If the libexslt library has been found +``LibXslt::xsltproc`` + If the xsltproc command-line executable has been found + +Result variables +^^^^^^^^^^^^^^^^ + +This module will set the following variables in your project: LIBXSLT_FOUND - system has LibXslt LIBXSLT_INCLUDE_DIR - the LibXslt include directory @@ -90,3 +103,22 @@ mark_as_advanced(LIBXSLT_INCLUDE_DIR LIBXSLT_LIBRARIES LIBXSLT_EXSLT_LIBRARY LIBXSLT_XSLTPROC_EXECUTABLE) + +if(LIBXSLT_FOUND AND NOT TARGET LibXslt::LibXslt) + add_library(LibXslt::LibXslt UNKNOWN IMPORTED) + set_target_properties(LibXslt::LibXslt PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBXSLT_INCLUDE_DIR}") + set_target_properties(LibXslt::LibXslt PROPERTIES INTERFACE_COMPILE_OPTIONS "${LIBXSLT_DEFINITIONS}") + set_property(TARGET LibXslt::LibXslt APPEND PROPERTY IMPORTED_LOCATION "${LIBXSLT_LIBRARIES}") +endif() + +if(LIBXSLT_FOUND AND NOT TARGET LibXslt::LibExslt) + add_library(LibXslt::LibExslt UNKNOWN IMPORTED) + set_target_properties(LibXslt::LibExslt PROPERTIES INTERFACE_INCLUDE_DIRECTORIES "${LIBXSLT_EXSLT_INCLUDE_DIR}") + set_target_properties(LibXslt::LibExslt PROPERTIES INTERFACE_COMPILE_OPTIONS "${LIBXSLT_EXSLT_DEFINITIONS}") + set_property(TARGET LibXslt::LibExslt APPEND PROPERTY IMPORTED_LOCATION "${LIBXSLT_EXSLT_LIBRARY}") +endif() + +if(LIBXSLT_XSLTPROC_EXECUTABLE AND NOT TARGET LibXslt::xsltproc) + add_executable(LibXslt::xsltproc IMPORTED) + set_target_properties(LibXslt::xsltproc PROPERTIES IMPORTED_LOCATION "${LIBXSLT_XSLTPROC_EXECUTABLE}") +endif() diff --git a/Tests/CMakeLists.txt b/Tests/CMakeLists.txt index cf8aa14..bc2b9b8 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1439,6 +1439,7 @@ ${CMake_SOURCE_DIR}/Utilities/Release/push.bash --dir dev -- '${CMake_BUILD_NIGH Libinput LibUV LibXml2 + LibXslt LTTngUST ODBC OpenACC diff --git a/Tests/FindLibXslt/CMakeLists.txt b/Tests/FindLibXslt/CMakeLists.txt new file mode 100644 index 0000000..8a550b2 --- /dev/null +++ b/Tests/FindLibXslt/CMakeLists.txt @@ -0,0 +1,10 @@ +add_test(NAME FindLibXslt.Test COMMAND + ${CMAKE_CTEST_COMMAND} -C $ + --build-and-test + "${CMake_SOURCE_DIR}/Tests/FindLibXslt/Test" + "${CMake_BINARY_DIR}/Tests/FindLibXslt/Test" + ${build_generator_args} + --build-project TestFindLibXslt + --build-options ${build_options} + --test-command ${CMAKE_CTEST_COMMAND} -V -C $ +) diff --git a/Tests/FindLibXslt/Test/CMakeLists.txt b/Tests/FindLibXslt/Test/CMakeLists.txt new file mode 100644 index 0000000..e932661 --- /dev/null +++ b/Tests/FindLibXslt/Test/CMakeLists.txt @@ -0,0 +1,45 @@ +cmake_minimum_required(VERSION 3.4) +project(TestFindLibXslt C) +include(CTest) + +find_package(Iconv) +find_package(LibXml2 REQUIRED) +find_package(LibXslt REQUIRED) + +add_definitions(-DCMAKE_EXPECTED_LibXslt_VERSION="${LIBXSLT_VERSION_STRING}") + +add_executable(libxslt_tgt libxslt.c) +if(Iconv_FOUND) + target_link_libraries(libxslt_tgt Iconv::Iconv) +endif() +target_link_libraries(libxslt_tgt LibXml2::LibXml2 LibXslt::LibXslt) +add_test(NAME libxslt_tgt COMMAND libxslt_tgt) + +add_executable(libxslt_var libxslt.c) +if(Iconv_FOUND) + target_include_directories(libxslt_var PRIVATE ${Iconv_INCLUDE_DIRS}) + target_link_libraries(libxslt_var PRIVATE ${Iconv_LIBRARIES}) +endif() +target_include_directories(libxslt_var PRIVATE ${LIBXML2_INCLUDE_DIRS} ${LIBXSLT_INCLUDE_DIR}) +target_link_libraries(libxslt_var PRIVATE ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES}) +add_test(NAME libxslt_var COMMAND libxslt_var) + +add_executable(libexslt_tgt libexslt.c) +if(Iconv_FOUND) + target_link_libraries(libexslt_tgt Iconv::Iconv) +endif() +target_link_libraries(libexslt_tgt LibXml2::LibXml2 LibXslt::LibXslt LibXslt::LibExslt) +add_test(NAME libexslt_tgt COMMAND libexslt_tgt) + +add_executable(libexslt_var libexslt.c) +if(Iconv_FOUND) + target_include_directories(libexslt_var PRIVATE ${Iconv_INCLUDE_DIRS}) + target_link_libraries(libexslt_var PRIVATE ${Iconv_LIBRARIES}) +endif() +target_include_directories(libexslt_var PRIVATE ${LIBXML2_INCLUDE_DIRS} ${LIBXSLT_INCLUDE_DIR} ${LIBXSLT_EXSLT_INCLUDE_DIR}) +target_link_libraries(libexslt_var PRIVATE ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} ${LIBXSLT_EXSLT_LIBRARIES}) +add_test(NAME libexslt_var COMMAND libexslt_var) + +add_test(NAME xsltproc_tgt COMMAND LibXslt::xsltproc --version) + +add_test(NAME xsltproc_var COMMAND ${LIBXSLT_XSLTPROC_EXECUTABLE} --version) diff --git a/Tests/FindLibXslt/Test/libexslt.c b/Tests/FindLibXslt/Test/libexslt.c new file mode 100644 index 0000000..ea6eb3d --- /dev/null +++ b/Tests/FindLibXslt/Test/libexslt.c @@ -0,0 +1,16 @@ +#include +#include +#include + +int main() +{ + xsltInit(); + + xsltStylesheet* style = xsltNewStylesheet(); + exsltRegisterAll(); + xsltFreeStylesheet(style); + + xsltCleanupGlobals(); + + return 0; +} diff --git a/Tests/FindLibXslt/Test/libxslt.c b/Tests/FindLibXslt/Test/libxslt.c new file mode 100644 index 0000000..5b3d766 --- /dev/null +++ b/Tests/FindLibXslt/Test/libxslt.c @@ -0,0 +1,24 @@ +#include +#include +#include +#include +#include + +int main() +{ + xsltInit(); + + xsltStylesheet* style = xsltNewStylesheet(); + xsltFreeStylesheet(style); + + if (0 != strcmp(CMAKE_EXPECTED_LibXslt_VERSION, LIBXSLT_DOTTED_VERSION)) { + printf("CMAKE_EXPECTED_LibXslt_VERSION: '%s'\n", + CMAKE_EXPECTED_LibXslt_VERSION); + printf("LIBXSLT_DOTTED_VERSION: '%s'\n", LIBXSLT_DOTTED_VERSION); + return 1; + } + + xsltCleanupGlobals(); + + return 0; +} -- cgit v0.12