diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -47,6 +47,11 @@ find_package(Perl REQUIRED) set_package_properties(Perl PROPERTIES PURPOSE "Auto-generate PHP syntax definition files.") +# +# allow to install the "differently" licensed syntax xml files instead of putting them in a QRC and link them in +# +option(QRC_SYNTAX "Bundle the syntax definition files inside the library as resources" ON) +add_feature_info(SYNTAX_RESOURCE ${QRC_SYNTAX} "Bundle the syntax definition files inside the library as resources") # # API documentation @@ -61,6 +66,11 @@ ecm_install_po_files_as_qm(po) endif() +# tell the framework if it shall use the syntax files from the resource +if (QRC_SYNTAX) + add_definitions(-DHAS_SYNTAX_RESOURCE) +endif() + # # Actually build the stuff # diff --git a/autotests/foldingtest.cpp b/autotests/foldingtest.cpp --- a/autotests/foldingtest.cpp +++ b/autotests/foldingtest.cpp @@ -166,6 +166,7 @@ QFETCH(QString, syntax); Repository m_repo; + initRepositorySearchPaths(m_repo); auto def = m_repo.definitionForFileName(inFile); if (!syntax.isEmpty()) diff --git a/autotests/highlighter_benchmark.cpp b/autotests/highlighter_benchmark.cpp --- a/autotests/highlighter_benchmark.cpp +++ b/autotests/highlighter_benchmark.cpp @@ -67,6 +67,7 @@ void initTestCase() { m_repo = new Repository; + initRepositorySearchPaths(*m_repo); } void cleanupTestCase() diff --git a/autotests/htmlhighlighter_test.cpp b/autotests/htmlhighlighter_test.cpp --- a/autotests/htmlhighlighter_test.cpp +++ b/autotests/htmlhighlighter_test.cpp @@ -50,6 +50,7 @@ { QStandardPaths::enableTestMode(true); m_repo = new Repository; + initRepositorySearchPaths(*m_repo); } void cleanupTestCase() diff --git a/autotests/repository_benchmark.cpp b/autotests/repository_benchmark.cpp --- a/autotests/repository_benchmark.cpp +++ b/autotests/repository_benchmark.cpp @@ -21,6 +21,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "test-config.h" + #include #include @@ -36,6 +38,7 @@ { QBENCHMARK { Repository repo; + initRepositorySearchPaths(repo); } } diff --git a/autotests/syntaxrepository_test.cpp b/autotests/syntaxrepository_test.cpp --- a/autotests/syntaxrepository_test.cpp +++ b/autotests/syntaxrepository_test.cpp @@ -61,6 +61,7 @@ void initTestCase() { QStandardPaths::enableTestMode(true); + initRepositorySearchPaths(m_repo); } void testDefinitionByExtension_data() diff --git a/autotests/test-config.h.in b/autotests/test-config.h.in --- a/autotests/test-config.h.in +++ b/autotests/test-config.h.in @@ -21,5 +21,26 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include + +#include + #define TESTSRCDIR "@CMAKE_CURRENT_SOURCE_DIR@" #define TESTBUILDDIR "@CMAKE_CURRENT_BINARY_DIR@" + +/** + * init repository with right search paths, is needed if the files are not compiled in + * as resources + * + * @param repository repository to init search paths + */ +static void initRepositorySearchPaths(KSyntaxHighlighting::Repository &repository) +{ +#ifdef HAS_SYNTAX_RESOURCE + Q_UNUSED(repository) +#else + repository.addCustomSearchPath(QStringLiteral("@CMAKE_SOURCE_DIR@/data")); + repository.addCustomSearchPath(QStringLiteral("@CMAKE_BINARY_DIR@/data")); + repository.reload(); +#endif +} diff --git a/autotests/testhighlighter.cpp b/autotests/testhighlighter.cpp --- a/autotests/testhighlighter.cpp +++ b/autotests/testhighlighter.cpp @@ -100,6 +100,7 @@ { QStandardPaths::enableTestMode(true); m_repo = new Repository; + initRepositorySearchPaths(*m_repo); } void cleanupTestCase() diff --git a/autotests/theme_test.cpp b/autotests/theme_test.cpp --- a/autotests/theme_test.cpp +++ b/autotests/theme_test.cpp @@ -21,6 +21,8 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include "test-config.h" + #include #include #include @@ -58,6 +60,7 @@ void initTestCase() { QStandardPaths::enableTestMode(true); + initRepositorySearchPaths(m_repo); } void testThemes() diff --git a/data/CMakeLists.txt b/data/CMakeLists.txt --- a/data/CMakeLists.txt +++ b/data/CMakeLists.txt @@ -1,10 +1,9 @@ # generate PHP definitions macro(generate_php_syntax_definition targetFile srcFile) - add_custom_command( - OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${targetFile} - COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/generators/generate-php.pl < ${CMAKE_CURRENT_SOURCE_DIR}/syntax/${srcFile} > ${CMAKE_CURRENT_BINARY_DIR}/${targetFile} - DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/generators/generate-php.pl ${CMAKE_CURRENT_SOURCE_DIR}/syntax/${srcFile} - ) + execute_process(COMMAND ${CMAKE_COMMAND} -E make_directory ${CMAKE_CURRENT_BINARY_DIR}/syntax) + execute_process(COMMAND ${PERL_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/generators/generate-php.pl + INPUT_FILE ${CMAKE_CURRENT_SOURCE_DIR}/syntax/${srcFile} + OUTPUT_FILE ${CMAKE_CURRENT_BINARY_DIR}/syntax/${targetFile}) endmacro() generate_php_syntax_definition(javascript-php.xml javascript.xml) @@ -15,34 +14,48 @@ file(GLOB src_defs "${CMAKE_CURRENT_SOURCE_DIR}/syntax/*.xml") set(defs ${src_defs} - ${CMAKE_CURRENT_BINARY_DIR}/html-php.xml - ${CMAKE_CURRENT_BINARY_DIR}/css-php.xml - ${CMAKE_CURRENT_BINARY_DIR}/javascript-php.xml + ${CMAKE_CURRENT_BINARY_DIR}/syntax/html-php.xml + ${CMAKE_CURRENT_BINARY_DIR}/syntax/css-php.xml + ${CMAKE_CURRENT_BINARY_DIR}/syntax/javascript-php.xml ) -# generate the resource file -set(qrc_file ${CMAKE_CURRENT_BINARY_DIR}/syntax-data.qrc) -set(qrc_body "") -foreach(def ${defs}) - get_filename_component(def_name ${def} NAME) - string(APPEND qrc_body "${def}\n") -endforeach() -set(SYNTAX_DATA_QRC_FILES_STRING ${qrc_body}) -configure_file(syntax-data.qrc.in ${qrc_file} @ONLY) - -# generate the index file -add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/index.katesyntax" - COMMAND katehighlightingindexer "${CMAKE_CURRENT_BINARY_DIR}/index.katesyntax" "${CMAKE_CURRENT_SOURCE_DIR}/schema/language.xsd" "${CMAKE_CURRENT_BINARY_DIR}/syntax-data.qrc" - DEPENDS ${defs} ${CMAKE_CURRENT_SOURCE_DIR}/schema/language.xsd ${CMAKE_CURRENT_BINARY_DIR}/syntax-data.qrc -) +# theme data resource +qt5_add_resources(themes_QRC ${CMAKE_CURRENT_SOURCE_DIR}/themes/theme-data.qrc) -# generate the qrc file manually, to make dependencies on generated files work... -add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/qrc_syntax-data.cpp" - COMMAND ${Qt5Core_RCC_EXECUTABLE} --name syntax_data -o "${CMAKE_CURRENT_BINARY_DIR}/qrc_syntax-data.cpp" "${CMAKE_CURRENT_BINARY_DIR}/syntax-data.qrc" - DEPENDS ${defs} ${CMAKE_CURRENT_BINARY_DIR}/index.katesyntax -) -set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/qrc_syntax-data.cpp" PROPERTIES SKIP_AUTOMOC ON) +# do we want syntax files bundled in the library? +if (QRC_SYNTAX) + # generate the resource file + set(qrc_file ${CMAKE_CURRENT_BINARY_DIR}/syntax-data.qrc) + set(qrc_body "") + foreach(def ${defs}) + get_filename_component(def_name ${def} NAME) + string(APPEND qrc_body "${def}\n") + endforeach() + set(SYNTAX_DATA_QRC_FILES_STRING ${qrc_body}) + configure_file(syntax-data.qrc.in ${qrc_file} @ONLY) + + # generate the index file + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/index.katesyntax" + COMMAND katehighlightingindexer "${CMAKE_CURRENT_BINARY_DIR}/index.katesyntax" "${CMAKE_CURRENT_SOURCE_DIR}/schema/language.xsd" "${CMAKE_CURRENT_BINARY_DIR}/syntax-data.qrc" + DEPENDS ${defs} ${CMAKE_CURRENT_SOURCE_DIR}/schema/language.xsd ${CMAKE_CURRENT_BINARY_DIR}/syntax-data.qrc + ) + + # generate the qrc file manually, to make dependencies on generated files work... + add_custom_command(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/qrc_syntax-data.cpp" + COMMAND ${Qt5Core_RCC_EXECUTABLE} --name syntax_data -o "${CMAKE_CURRENT_BINARY_DIR}/qrc_syntax-data.cpp" "${CMAKE_CURRENT_BINARY_DIR}/syntax-data.qrc" + DEPENDS ${defs} ${CMAKE_CURRENT_BINARY_DIR}/index.katesyntax + ) + set_source_files_properties("${CMAKE_CURRENT_BINARY_DIR}/qrc_syntax-data.cpp" PROPERTIES SKIP_AUTOMOC ON) + + # object library to make cross-folder dependencies work, themes + syntax files + add_library(SyntaxHighlightingData OBJECT ${themes_QRC} ${CMAKE_CURRENT_BINARY_DIR}/qrc_syntax-data.cpp) +else() + # install the syntax files as normal files into the prefix + install (FILES ${defs} DESTINATION share/org.kde.syntax-highlighting/syntax) + + # object library to make cross-folder dependencies work, only themes + add_library(SyntaxHighlightingData OBJECT ${themes_QRC}) +endif() -# object library to make cross-folder dependencies work, set PIC to allow use in static and shared libs -add_library(SyntaxHighlightingData OBJECT ${CMAKE_CURRENT_BINARY_DIR}/qrc_syntax-data.cpp) +# set PIC to allow use in static and shared libs set_property(TARGET SyntaxHighlightingData PROPERTY POSITION_INDEPENDENT_CODE 1) diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -26,9 +26,7 @@ CATEGORY_NAME org.kde.ksyntaxhighlighting ) -qt5_add_resources(themes_QRC ${CMAKE_SOURCE_DIR}/data/themes/theme-data.qrc) - -add_library(KF5SyntaxHighlighting ${syntax_highlighting_srcs} ${themes_QRC} $) +add_library(KF5SyntaxHighlighting ${syntax_highlighting_srcs} $) generate_export_header(KF5SyntaxHighlighting BASE_NAME KSyntaxHighlighting) set_target_properties(KF5SyntaxHighlighting PROPERTIES VERSION ${SyntaxHighlighting_VERSION_STRING} diff --git a/src/lib/repository.cpp b/src/lib/repository.cpp --- a/src/lib/repository.cpp +++ b/src/lib/repository.cpp @@ -44,7 +44,9 @@ static void initResource() { +#ifdef HAS_SYNTAX_RESOURCE Q_INIT_RESOURCE(syntax_data); +#endif Q_INIT_RESOURCE(theme_data); }