diff options
author | Michal Klocek <michal.klocek@qt.io> | 2021-10-25 13:23:44 +0200 |
---|---|---|
committer | Michal Klocek <michal.klocek@qt.io> | 2021-11-17 20:45:40 +0100 |
commit | 3a2dd40b179405da84c85d5877a6e2678b36ce8a (patch) | |
tree | 8c881aa86ea6d897b56d03dc12482a1516e8ac0e | |
parent | 23cc5bb2588100c6053d9d11b20778724cdbd6e7 (diff) |
Add cmake api for 'bdict' dictionary conversion
Fix spellchecker example and test to use new api.
Note we should not use qt6 prefix in cmake api in examples.
Change-Id: Ib800bf2b7bd83e10060fa01ccd8d4a262752e09b
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
Reviewed-by: Michael BrĂ¼ning <michael.bruning@qt.io>
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | examples/webenginewidgets/spellchecker/CMakeLists.txt | 35 | ||||
-rw-r--r-- | src/core/api/Qt6WebEngineCoreMacros.cmake | 57 | ||||
-rw-r--r-- | src/core/doc/src/qt_webengine_add_convert_dictionary.qdoc | 75 | ||||
-rw-r--r-- | tests/auto/widgets/spellchecking/CMakeLists.txt | 31 |
5 files changed, 144 insertions, 55 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index 95f5cdfc2..b0a0c7ffb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -3,6 +3,7 @@ cmake_minimum_required(VERSION 3.19) include(.cmake.conf) include(ExternalProject) include(cmake/Functions.cmake) +include(src/core/api/Qt6WebEngineCoreMacros.cmake) project(QtWebEngine VERSION "${QT_REPO_MODULE_VERSION}" diff --git a/examples/webenginewidgets/spellchecker/CMakeLists.txt b/examples/webenginewidgets/spellchecker/CMakeLists.txt index 16bb677c5..1a0c76b06 100644 --- a/examples/webenginewidgets/spellchecker/CMakeLists.txt +++ b/examples/webenginewidgets/spellchecker/CMakeLists.txt @@ -39,7 +39,7 @@ set(spellchecker_resource_files "data/style.css" ) -qt6_add_resources(spellchecker "spellchecker" +qt_add_resources(spellchecker "spellchecker" PREFIX "/" BASE @@ -55,38 +55,15 @@ install(TARGETS spellchecker ) file(GLOB_RECURSE dicts - RELATIVE ${CMAKE_CURRENT_LIST_DIR}/dict + ABSOLUTE ${CMAKE_CURRENT_LIST_DIR}/dict */*.dic ) -if(QT_GENERATOR_IS_MULTI_CONFIG) - set(spellcheckerDir ${CMAKE_CURRENT_BINARY_DIR}/dict/qtwebengine_dictionaries) -else() - set(spellcheckerDir ${CMAKE_CURRENT_BINARY_DIR}/qtwebengine_dictionaries) -endif() - -# note setting QT_WEBENGINE_ICU_DATA below is not required if this example -# is not compiled as part of qtwebengine module build - foreach(dictFile ${dicts}) - get_filename_component(dictName ${dictFile} NAME_WE) - add_custom_command(TARGET spellchecker - PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory ${spellcheckerDir} - COMMAND ${CMAKE_COMMAND} -E env - $<TARGET_FILE:${QT_CMAKE_EXPORT_NAMESPACE}::qwebengine_convert_dict> - ${CMAKE_CURRENT_SOURCE_DIR}/dict/${dictFile} ${spellcheckerDir}/${dictName}.bdic - COMMENT "Running qwebengine_convert_dict" + qt_add_webengine_dictionary( + TARGET spellchecker + SOURCE "${dictFile}" + OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) endforeach() -# copy dictionaries to $<CONFIG> build dir -if(QT_GENERATOR_IS_MULTI_CONFIG) - add_custom_command(TARGET spellchecker - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E echo Copying dictionares - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/dict - ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG> - ) -endif() - diff --git a/src/core/api/Qt6WebEngineCoreMacros.cmake b/src/core/api/Qt6WebEngineCoreMacros.cmake new file mode 100644 index 000000000..ada067b3a --- /dev/null +++ b/src/core/api/Qt6WebEngineCoreMacros.cmake @@ -0,0 +1,57 @@ +function(qt6_add_webengine_dictionary) + set(options) + set(oneValueArgs TARGET SOURCE OUTPUT_DIRECTORY) + set(multiValueArgs) + + cmake_parse_arguments(ARGS "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN}) + + if (NOT ARGS_SOURCE OR NOT EXISTS "${ARGS_SOURCE}" OR NOT IS_ABSOLUTE "${ARGS_SOURCE}") + message(FATAL_ERROR "Function qt_add_webengine_dictionary requires an absolute path to SOURCE dictionary.") + endif() + + if (NOT ARGS_OUTPUT_DIRECTORY) + set(ARGS_OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}) + endif() + + get_property(isMultiConfig GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) + if(isMultiConfig) + set(spellcheckerDir ${ARGS_OUTPUT_DIRECTORY}/dict/qtwebengine_dictionaries) + set(copyCommand COMMAND ${CMAKE_COMMAND} -E copy_directory ${ARGS_OUTPUT_DIRECTORY}/dict + ${ARGS_OUTPUT_DIRECTORY}/$<CONFIG> + ) + else() + set(spellcheckerDir ${ARGS_OUTPUT_DIRECTORY}/qtwebengine_dictionaries) + endif() + + get_filename_component(dictName ${ARGS_SOURCE} NAME_WE) + add_custom_command( + OUTPUT ${spellcheckerDir}/${dictName}.bdic + DEPENDS ${ARGS_SOURCE} + COMMENT "Running qwebengine_convert_dict for ${ARGS_SOURCE}" + COMMAND ${CMAKE_COMMAND} -E make_directory ${spellcheckerDir} + COMMAND ${CMAKE_COMMAND} -E env + $<TARGET_FILE:${QT_CMAKE_EXPORT_NAMESPACE}::qwebengine_convert_dict> + ${ARGS_SOURCE} ${spellcheckerDir}/${dictName}.bdic + ${copyCommand} + ) + if(NOT TARGET webengine_dictionaries) + add_custom_target(webengine_dictionaries) + endif() + + # in case of large project gen target should have unique name since it can collide, use TARGET + if (ARGS_TARGET) + add_custom_target(gen-${ARGS_TARGET}-${dictName} DEPENDS ${spellcheckerDir}/${dictName}.bdic) + add_dependencies(${ARGS_TARGET} gen-${ARGS_TARGET}-${dictName}) + add_dependencies(webengine_dictionaries gen-${ARGS_TARGET}-${dictName}) + else() + add_custom_target(gen-${dictName} DEPENDS ${spellcheckerDir}/${dictName}.bdic) + add_dependencies(webengine_dictionaries gen-${dictName}) + endif() + +endfunction() + +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_add_webengine_dictionary) + qt6_add_webengine_dictionary(${ARGN}) + endfunction() +endif() diff --git a/src/core/doc/src/qt_webengine_add_convert_dictionary.qdoc b/src/core/doc/src/qt_webengine_add_convert_dictionary.qdoc new file mode 100644 index 000000000..cbb4a41fd --- /dev/null +++ b/src/core/doc/src/qt_webengine_add_convert_dictionary.qdoc @@ -0,0 +1,75 @@ +/**************************************************************************** +** +** Copyright (C) 2021 The Qt Company Ltd. +** Contact: https://www.qt.io/licensing/ +** +** This file is part of the documentation of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:FDL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and The Qt Company. For licensing terms +** and conditions see https://www.qt.io/terms-conditions. For further +** information use the contact form at https://www.qt.io/contact-us. +** +** GNU Free Documentation License Usage +** Alternatively, this file may be used under the terms of the GNU Free +** Documentation License version 1.3 as published by the Free Software +** Foundation and appearing in the file included in the packaging of +** this file. Please review the following information to ensure +** the GNU Free Documentation License version 1.3 requirements +** will be met: https://www.gnu.org/licenses/fdl-1.3.html. +** $QT_END_LICENSE$ +** +****************************************************************************/ + +/*! +\page qt_add_webengine_dictionary.html +\ingroup cmake-commands + +\title qt_add_webengine_dictionary +\target qt6_add_webengine_dictionary + +\brief Converts the hunspell dictionary format into \e bdict binary format. + +\section1 Synopsis + +\badcode +qt_add_webengine_dictionary( + [TARGET] + [SOURCE] + [OUTPUT_DIRECTORY] +) + +\endcode + +\versionlessCMakeCommandsNote qt6_webengine_add_dictionary() + +\section1 Description + + A spell checker in Qt Web Engine needs dictionaries in a specific binary format. + This CMake command converts dictionaries from the \l{Hunspell project}. into the \c bdict + binary format. It creates a \c webengine_dictionaries target, which your project can + use as a dependency. This way your project can easily add dictionaries for the spell + checker. Refer to the \l{WebEngine Widgets Spellchecker Example}{spell checker example} + for more details. + +\section1 Arguments + + \c TARGET is an optinal argument and specifies the name of the application target that should + depend on \c webengine_dictionaries target. In other words it is used to define a build + dependency to create the binary format of dictionaries before building \c TARGET. + + \c SOURCE is the absolute path to the \l{Hunspell project} dictionary for which + a corresponding binary format (\c.bdict) will be created. + + \c OUTPUT_DIRECTORY is an optional argument and specifies the directory where the binary format + of the dictionary will be created. If not specified, \c CMAKE_CURRENT_BINARY_DIR will be used + as \c OUTPUT_DIRECTORY. + + \note The \c webengine_dictionaries directory or \c <CONFIG>/webengine_dictionaries directories + in the case of the multi-config generator is appended to OUTPUT_DIRECTORY. This helps to + utilize dictionaries, as the \c webengine_dictionaries directory is the default search location. +*/ diff --git a/tests/auto/widgets/spellchecking/CMakeLists.txt b/tests/auto/widgets/spellchecking/CMakeLists.txt index a0cd4d052..2c1926476 100644 --- a/tests/auto/widgets/spellchecking/CMakeLists.txt +++ b/tests/auto/widgets/spellchecking/CMakeLists.txt @@ -16,35 +16,14 @@ qt_internal_add_resource(tst_spellchecking "tst_spellchecking" ) file(GLOB_RECURSE dicts - RELATIVE ${CMAKE_CURRENT_LIST_DIR}/dict + ABSOLUTE ${CMAKE_CURRENT_LIST_DIR}/dict *.dic ) -if(QT_GENERATOR_IS_MULTI_CONFIG) - set(spellcheckerDir ${CMAKE_CURRENT_BINARY_DIR}/dict/qtwebengine_dictionaries) -else() - set(spellcheckerDir ${CMAKE_CURRENT_BINARY_DIR}/qtwebengine_dictionaries) -endif() - foreach(dictFile ${dicts}) - get_filename_component(dictName ${dictFile} NAME_WE) - add_custom_command(TARGET tst_spellchecking - PRE_BUILD - COMMAND ${CMAKE_COMMAND} -E make_directory ${spellcheckerDir} - COMMAND ${CMAKE_COMMAND} -E env - $<TARGET_FILE:${QT_CMAKE_EXPORT_NAMESPACE}::qwebengine_convert_dict> - ${CMAKE_CURRENT_SOURCE_DIR}/dict/${dictFile} - ${spellcheckerDir}/${dictName}.bdic - COMMENT "Running qwebengine_convert_dict" + qt_add_webengine_dictionary( + TARGET tst_spellchecking + SOURCE "${dictFile}" + OUTPUT_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR} ) endforeach() - -# copy dictionaries to $<CONFIG> build dir -if(QT_GENERATOR_IS_MULTI_CONFIG) - add_custom_command(TARGET tst_spellchecking - POST_BUILD - COMMAND ${CMAKE_COMMAND} -E echo Copying dictionares - COMMAND ${CMAKE_COMMAND} -E copy_directory ${CMAKE_CURRENT_BINARY_DIR}/dict - ${CMAKE_CURRENT_BINARY_DIR}/$<CONFIG> - ) -endif() |