浏览代码

FindLibXslt: provide imported targets

Markus Rickert 5 年之前
父节点
当前提交
1aa7df4114

+ 4 - 0
Help/release/dev/libxslt.rst

@@ -0,0 +1,4 @@
+libxslt-target
+--------------
+
+* The :module:`FindLibXslt` module now provides imported targets.

+ 34 - 2
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()

+ 1 - 0
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

+ 10 - 0
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>
+)

+ 45 - 0
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)

+ 16 - 0
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;
+}

+ 24 - 0
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;
+}