diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -16,6 +16,7 @@ include(ECMSetupVersion) include(ECMMarkNonGuiExecutable) include(CMakePackageConfigHelpers) +include(GenerateExportHeader) ecm_setup_version(PROJECT VARIABLE_PREFIX KDOCTOOLS VERSION_HEADER "${CMAKE_CURRENT_BINARY_DIR}/kdoctools_version.h" diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -26,6 +26,40 @@ endif() # needed by KIO, need to export it +add_library(KF5DocTools SHARED xslt.cpp xslt_kde.cpp) +generate_export_header(KF5DocTools BASE_NAME KDocTools EXPORT_FILE_NAME "${CMAKE_CURRENT_BINARY_DIR}/kdoctools_export.h") +add_library(KF5::DocTools ALIAS KF5DocTools) +if (NOT MEINPROC_NO_KARCHIVE) + set (_private_link_karchive "KF5::Archive") +else() + set (_private_link_karchive "") +endif() +target_link_libraries(KF5DocTools + PUBLIC + Qt5::Core + PRIVATE + ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} ${LIBXSLT_EXSLT_LIBRARIES} ${_private_link_karchive} +) +set_target_properties(KF5DocTools PROPERTIES + POSITION_INDEPENDENT_CODE TRUE + EXPORT_NAME KDocTools +) + +target_include_directories(KF5DocTools INTERFACE "$") + +install(FILES + docbookxslt.h + ${CMAKE_CURRENT_BINARY_DIR}/kdoctools_export.h + DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/KDocTools + COMPONENT Devel +) + +set_target_properties(KF5DocTools PROPERTIES VERSION ${KDOCTOOLS_VERSION_STRING} + SOVERSION ${KDOCTOOLS_SOVERSION} + EXPORT_NAME DocTools +) + +# ------------------------------------- add_library(KF5XsltKde STATIC xslt.cpp xslt_kde.cpp) add_library(KF5::XsltKde ALIAS KF5XsltKde) if (NOT MEINPROC_NO_KARCHIVE) @@ -49,11 +83,13 @@ install(FILES xslt.h xslt_kde.h + docbookxslt.h docbookxslt_p.h + ${CMAKE_CURRENT_BINARY_DIR}/kdoctools_export.h DESTINATION ${KDE_INSTALL_INCLUDEDIR_KF5}/XsltKde COMPONENT Devel ) -install(TARGETS KF5XsltKde EXPORT KF5DocToolsTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) +install(TARGETS KF5XsltKde KF5DocTools EXPORT KF5DocToolsTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) ########### next target ############### @@ -68,7 +104,7 @@ add_executable(meinproc5 meinproc.cpp meinproc_common.cpp xslt.cpp ${meinproc_additional_SRCS}) ecm_mark_nongui_executable(meinproc5) -target_link_libraries(meinproc5 Qt5::Core ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} ${LIBXSLT_EXSLT_LIBRARIES} ${meinproc_additional_LIBS}) +target_link_libraries(meinproc5 Qt5::Core KF5::DocTools ${LIBXML2_LIBRARIES} ${LIBXSLT_LIBRARIES} ${LIBXSLT_EXSLT_LIBRARIES} ${meinproc_additional_LIBS}) install(TARGETS meinproc5 EXPORT KF5DocToolsTargets ${KF5_INSTALL_TARGETS_DEFAULT_ARGS}) if(CMAKE_CROSSCOMPILING AND MEINPROC5_EXECUTABLE) diff --git a/src/docbookxslt.h b/src/docbookxslt.h new file mode 100644 --- /dev/null +++ b/src/docbookxslt.h @@ -0,0 +1,70 @@ +/* + * This file is part of KDE Frameworks - KDocTools + * The following contributors changed the signatures of the functions + * exported here: + * Copyright (C) 2001 Stephan Kulow + * Copyright (C) 2005 Frerich Raabe + * Copyright (C) 2010 Albert Astals Cid + * Copyright (C) 2010, 2016, 2017 Luigi Toscano + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library. If not, see . + * + */ + +#ifndef _KDOCTOOLS_XSLT_H_ +#define _KDOCTOOLS_XSLT_H_ + +#include +#include +#include + +class QByteArray; +class QString; + +namespace KDocTools { + +/** + * Tranform and return the content of file with the specified XSLT stylesheet + * (both already in memory) using the optional parameters. + */ +KDOCTOOLS_EXPORT QString transform(const QString &file, const QString &stylesheet, + const QVector ¶ms = QVector()); + +/** + * Extract the content of a single file from the content string + * generated by the transformation scripts. + * @since 5.32 + */ +KDOCTOOLS_EXPORT QByteArray extractFileToBuffer(const QString &content, const QString &filename); + +/** + * Save the content (compressed) in the specified filename. + */ +KDOCTOOLS_EXPORT bool saveToCache(const QString &contents, const QString &filename); + +/** + * Initialize the XML catalog used by XSLT functions from the standard + directories or from the specified srcdir. + */ +KDOCTOOLS_EXPORT void setupStandardDirs(const QString &srcdir = QString()); + + +/** + * Find a specified file amongst the resource shipped with KDocTools. + */ +KDOCTOOLS_EXPORT QString locateFileInDtdResource(const QString &file, const QStandardPaths::LocateOptions option=QStandardPaths::LocateFile); + +} + +#endif diff --git a/src/docbookxslt_p.h b/src/docbookxslt_p.h new file mode 100644 --- /dev/null +++ b/src/docbookxslt_p.h @@ -0,0 +1,11 @@ +#ifndef _KDOCTOOLS_XSLT_P_H_ +#define _KDOCTOOLS_XSLT_P_H_ + +QString splitOut(const QString &parsed, int index); +QByteArray fromUnicode(const QString &data); +void replaceCharsetHeader(QString &output); +QStringList locateFilesInDtdResource(const QString &file, const QStandardPaths::LocateOptions option=QStandardPaths::LocateFile); +QStringList getKDocToolsCatalogs(); + +#endif + diff --git a/src/meinproc.cpp b/src/meinproc.cpp --- a/src/meinproc.cpp +++ b/src/meinproc.cpp @@ -1,6 +1,7 @@ #include "../config-kdoctools.h" -#include "xslt.h" +#include "docbookxslt.h" +#include "docbookxslt_p.h" #include "meinproc_common.h" #include @@ -32,6 +33,8 @@ #include #include +using namespace KDocTools; + #ifndef _WIN32 extern "C" int xmlLoadExtDtdDefaultValue; #endif diff --git a/src/meinproc_common.cpp b/src/meinproc_common.cpp --- a/src/meinproc_common.cpp +++ b/src/meinproc_common.cpp @@ -1,7 +1,8 @@ #include "meinproc_common.h" -#include "xslt.h" +#include "docbookxslt.h" +#include "docbookxslt_p.h" #include #include diff --git a/src/xslt.h b/src/xslt.h --- a/src/xslt.h +++ b/src/xslt.h @@ -1,31 +1,9 @@ #ifndef _MEIN_XSLT_H_ #define _MEIN_XSLT_H_ -#include -#include -#include -#include +#include "docbookxslt.h" +#include "docbookxslt_p.h" -class QByteArray; - -QString transform(const QString &file, const QString &stylesheet, - const QVector ¶ms = QVector()); -QString splitOut(const QString &parsed, int index); -QByteArray fromUnicode(const QString &data); -void replaceCharsetHeader(QString &output); - -/** - * Extract the content of a single file from the content string - * generated by the transformation scripts. - * @since 5.32 - */ -QByteArray extractFileToBuffer(const QString &content, const QString &filename); - -bool saveToCache(const QString &contents, const QString &filename); - -void setupStandardDirs(const QString &srcdir = QString()); -QString locateFileInDtdResource(const QString &file, const QStandardPaths::LocateOptions option=QStandardPaths::LocateFile); -QStringList locateFilesInDtdResource(const QString &file, const QStandardPaths::LocateOptions option=QStandardPaths::LocateFile); -QStringList getKDocToolsCatalogs(); +using namespace KDocTools; #endif diff --git a/src/xslt.cpp b/src/xslt.cpp --- a/src/xslt.cpp +++ b/src/xslt.cpp @@ -1,4 +1,5 @@ -#include "xslt.h" +#include "docbookxslt.h" +#include "docbookxslt_p.h" #ifdef Q_OS_WIN //one of the xslt/xml headers pulls in windows.h and breaks @@ -12,6 +13,7 @@ #include #include #include +#include #include #include #include @@ -24,6 +26,9 @@ #include #include #include +#include +#include +#include #if !defined( SIMPLE_XSLT ) extern HelpProtocol *slave; @@ -126,7 +131,7 @@ } #endif -QString transform(const QString &pat, const QString &tss, +QString KDocTools::transform(const QString &pat, const QString &tss, const QVector ¶ms) { QString parsed; @@ -358,7 +363,7 @@ #endif } -QByteArray extractFileToBuffer(const QString &content, const QString &filename) +QByteArray KDocTools::extractFileToBuffer(const QString &content, const QString &filename) { int index = content.indexOf(QStringLiteral(" #else #include #endif -bool saveToCache(const QString &contents, const QString &filename) +bool KDocTools::saveToCache(const QString &contents, const QString &filename) { #ifndef MEINPROC_NO_KARCHIVE KFilterDev fd(filename);