diff options
-rw-r--r-- | Help/release/dev/libxslt.rst | 4 | ||||
-rw-r--r-- | Modules/FindLibXslt.cmake | 60 | ||||
-rw-r--r-- | Tests/CMakeLists.txt | 1 | ||||
-rw-r--r-- | Tests/FindLibXslt/CMakeLists.txt | 10 | ||||
-rw-r--r-- | Tests/FindLibXslt/Test/CMakeLists.txt | 45 | ||||
-rw-r--r-- | Tests/FindLibXslt/Test/libexslt.c | 16 | ||||
-rw-r--r-- | Tests/FindLibXslt/Test/libxslt.c | 24 |
7 files changed, 157 insertions, 3 deletions
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 01a9d8b..fc7adeb 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 @@ -21,6 +34,8 @@ Once done this will define Additionally, the following two variables are set (but not required for using xslt): +``LIBXSLT_EXSLT_INCLUDE_DIR`` + The include directory for exslt. ``LIBXSLT_EXSLT_LIBRARIES`` Link to these if you need to link against the exslt library. ``LIBXSLT_XSLTPROC_EXECUTABLE`` @@ -39,16 +54,36 @@ find_path(LIBXSLT_INCLUDE_DIR NAMES libxslt/xslt.h ${PC_LIBXSLT_INCLUDE_DIRS} ) -find_library(LIBXSLT_LIBRARIES NAMES xslt libxslt +# CMake 3.17 and below used 'LIBXSLT_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 LIBXSLT_LIBRARIES AND NOT DEFINED LIBXSLT_LIBRARY) + set(LIBXSLT_LIBRARY ${LIBXSLT_LIBRARIES}) +endif() + +find_library(LIBXSLT_LIBRARY NAMES xslt libxslt HINTS ${PC_LIBXSLT_LIBDIR} ${PC_LIBXSLT_LIBRARY_DIRS} ) +set(LIBXSLT_LIBRARIES ${LIBXSLT_LIBRARY}) + +PKG_CHECK_MODULES(PC_LIBXSLT_EXSLT QUIET libexslt) +set(LIBXSLT_EXSLT_DEFINITIONS ${PC_LIBXSLT_EXSLT_CFLAGS_OTHER}) + +find_path(LIBXSLT_EXSLT_INCLUDE_DIR NAMES libexslt/exslt.h + HINTS + ${PC_LIBXSLT_EXSLT_INCLUDEDIR} + ${PC_LIBXSLT_EXSLT_INCLUDE_DIRS} +) + find_library(LIBXSLT_EXSLT_LIBRARY NAMES exslt libexslt HINTS ${PC_LIBXSLT_LIBDIR} ${PC_LIBXSLT_LIBRARY_DIRS} + ${PC_LIBXSLT_EXSLT_LIBDIR} + ${PC_LIBXSLT_EXSLT_LIBRARY_DIRS} ) set(LIBXSLT_EXSLT_LIBRARIES ${LIBXSLT_EXSLT_LIBRARY} ) @@ -75,3 +110,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_LIBRARY}") +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 5011863..f44a209 100644 --- a/Tests/CMakeLists.txt +++ b/Tests/CMakeLists.txt @@ -1441,6 +1441,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 $<CONFIGURATION> + --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 $<CONFIGURATION> +) 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 <libexslt/exslt.h> +#include <libxslt/xslt.h> +#include <libxslt/xsltInternals.h> + +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 <libxslt/xslt.h> +#include <libxslt/xsltInternals.h> +#include <libxslt/xsltconfig.h> +#include <stdio.h> +#include <string.h> + +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; +} |