diff options
author | Joerg Bornemann <joerg.bornemann@qt.io> | 2023-11-20 10:30:49 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-12-22 20:28:48 +0000 |
commit | fe843e52ad784779f7ac6449e41ee13628356c90 (patch) | |
tree | bde4e8992e2779d7c6a045e11ce0889d26142e11 | |
parent | 231e3436739a0eea828dd78d1aac4e783b3b22bd (diff) |
CMake: Fix deployment of QtWebEngine projects on Linux
This adds a deployment hook for the generic deployment tool, which deploys
- QtWebEngineProcess to QT_DEPLOY_PREFIX/libexec
- resources to QT_DEPLOY_DATA_DIR/resources
- locales to QT_DEPLOY_TRANSLATIONS_DIR/qtwebengine_locales
Since we're picking this to lower branches, we cannot expect that
QT_DEPLOY_LIBEXEC_DIR is set. Therefore, we initialize it if it doesn't
exist.
Pick-to: 6.5
Task-number: QTBUG-119077
Change-Id: I39fde919044d011376d8beb7e892dc9b5205c028
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
(cherry picked from commit 73d58b489e8f4f900042f0ab6c1104e6431752e1)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit 371514b97fa5c4d6f607892469cd3ae9a486ecd7)
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/core/api/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/core/api/Qt6WebEngineCoreDeploySupport.cmake | 176 | ||||
-rw-r--r-- | src/core/api/Qt6WebEngineCoreMacros.cmake | 6 |
4 files changed, 184 insertions, 1 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt index faa9b1a51..8f505967b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,7 +9,6 @@ cmake_minimum_required(VERSION 3.16) include(.cmake.conf) include(ExternalProject) include(cmake/Functions.cmake) -include(src/core/api/Qt6WebEngineCoreMacros.cmake) project(QtWebEngineDummy) find_package(Qt6 6.2 CONFIG REQUIRED COMPONENTS BuildInternals Core) diff --git a/src/core/api/CMakeLists.txt b/src/core/api/CMakeLists.txt index 2c36936dd..da587119d 100644 --- a/src/core/api/CMakeLists.txt +++ b/src/core/api/CMakeLists.txt @@ -55,6 +55,8 @@ qt_internal_add_module(WebEngineCore Qt::Gui Qt::Network Qt::Quick + EXTRA_CMAKE_FILES + "${CMAKE_CURRENT_LIST_DIR}/${INSTALL_CMAKE_NAMESPACE}WebEngineCoreDeploySupport.cmake" ) set_target_properties(WebEngineCore PROPERTIES QTWEBENGINEPROCESS_NAME ${qtWebEngineProcessName}) diff --git a/src/core/api/Qt6WebEngineCoreDeploySupport.cmake b/src/core/api/Qt6WebEngineCoreDeploySupport.cmake new file mode 100644 index 000000000..856a54f17 --- /dev/null +++ b/src/core/api/Qt6WebEngineCoreDeploySupport.cmake @@ -0,0 +1,176 @@ +# Copyright (C) 2023 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +# NOTE: This code should only ever be executed in script mode. It expects to be +# used either as part of an install(CODE) call or called by a script +# invoked via cmake -P as a POST_BUILD step. It would not normally be +# included directly, it should be pulled in automatically by the deploy +# support set up by qtbase. + +cmake_minimum_required(VERSION 3.16...3.21) + +_qt_internal_add_deployment_hook(_qt_internal_webenginecore_deploy_hook) + +if(NOT QT_DEPLOY_WEBENGINECORE_RESOURCES_DIR) + set(QT_DEPLOY_WEBENGINECORE_RESOURCES_DIR "resources") +endif() + +function(_qt_internal_webenginecore_status_message) + if(__QT_DEPLOY_VERBOSE) + message(STATUS ${ARGV}) + endif() +endfunction() + +function(_qt_internal_webenginecore_deploy_hook) + set(no_value_options "") + set(single_value_options "") + set(multi_value_options RESOLVED_DEPENDENCIES) + cmake_parse_arguments(PARSE_ARGV 0 arg + "${no_value_options}" "${single_value_options}" "${multi_value_options}" + ) + + set(webenginecore_dependency_found FALSE) + foreach(dependency IN LISTS arg_RESOLVED_DEPENDENCIES) + if(dependency MATCHES "/libQt[0-9]+WebEngineCore[^/]+") + set(webenginecore_dependency_found TRUE) + break() + endif() + endforeach() + + if(NOT webenginecore_dependency_found) + _qt_internal_webenginecore_status_message( + "No QtWebEngineCore dependency found. " + "Skipping deployment of QtWebEngine assets." + ) + return() + endif() + + _qt_internal_deploy_webenginecore() +endfunction() + +function(_qt_internal_deploy_webenginecore) + _qt_internal_deploy_webenginecore_binary() + _qt_internal_deploy_webenginecore_data() + _qt_internal_deploy_webenginecore_translations() +endfunction() + +function(_qt_internal_deploy_webenginecore_binary) + _qt_internal_webenginecore_status_message("Deploying the WebEngineCore process binary") + + set(candidates "QtWebEngineProcess") + if(__QT_DEPLOY_ACTIVE_CONFIG STREQUAL "Debug" AND __QT_DEPLOY_SYSTEM_NAME STREQUAL "Windows") + list(PREPEND candidates "QtWebEngineProcessd") + endif() + + list(TRANSFORM candidates + PREPEND "${__QT_DEPLOY_QT_INSTALL_PREFIX}/${__QT_DEPLOY_QT_INSTALL_LIBEXECS}/" + ) + + set(process_path "") + foreach(file_path IN LISTS candidates) + if(EXISTS "${file_path}") + set(process_path "${file_path}") + break() + endif() + endforeach() + + set(install_destination "${QT_DEPLOY_PREFIX}/") + if(__QT_DEPLOY_SYSTEM_NAME STREQUAL "Windows") + string(APPEND install_destination "${QT_DEPLOY_BIN_DIR}") + else() + if(NOT DEFINED QT_DEPLOY_LIBEXEC_DIR) + set(QT_DEPLOY_LIBEXEC_DIR "libexec") + endif() + string(APPEND install_destination "${QT_DEPLOY_LIBEXEC_DIR}") + endif() + file(INSTALL "${process_path}" DESTINATION "${install_destination}") + + get_filename_component(process_file_name "${process_path}" NAME) + if(CMAKE_VERSION GREATER_EQUAL "3.19") + file(CHMOD "${install_destination}/${process_file_name}" + PERMISSIONS OWNER_EXECUTE OWNER_READ OWNER_WRITE + GROUP_EXECUTE GROUP_READ + WORLD_EXECUTE WORLD_READ + ) + else() + execute_process( + COMMAND chmod 0755 "${install_destination}/${process_file_name}" + ) + endif() +endfunction() + +function(_qt_internal_deploy_webenginecore_data) + _qt_internal_webenginecore_status_message("Deploying the WebEngineCore data files") + set(data_files + icudtl.dat + qtwebengine_devtools_resources.pak + qtwebengine_resources.pak + qtwebengine_resources_100p.pak + qtwebengine_resources_200p.pak + ) + get_filename_component(resources_dir "resources" ABSOLUTE + BASE_DIR "${__QT_DEPLOY_QT_INSTALL_PREFIX}/${__QT_DEPLOY_QT_INSTALL_DATA}" + ) + + _qt_internal_webenginecore_find_v8_context_snapshot( + snapshot_file + RESOURCES_DIR "${resources_dir}" + ) + if(NOT snapshot_file STREQUAL "") + list(APPEND data_files "${snapshot_file}") + endif() + + get_filename_component(install_destination "${QT_DEPLOY_WEBENGINECORE_RESOURCES_DIR}" ABSOLUTE + BASE_DIR "${QT_DEPLOY_PREFIX}/${QT_DEPLOY_DATA_DIR}" + ) + foreach(data_file IN LISTS data_files) + file(INSTALL "${resources_dir}/${data_file}" DESTINATION "${install_destination}") + endforeach() +endfunction() + +# The V8 snapshot file comes as debug or release build. Multi-config builds have both, a self-built +# Qt might only have the debug one. +# +# This function returns the file name of the V8 context snapshot file in ${out_var}. +# If no snapshot could be found, ${out_var} is the empty string. +function(_qt_internal_webenginecore_find_v8_context_snapshot out_var) + set(no_value_options "") + set(single_value_options RESOURCES_DIR) + set(multi_value_options "") + cmake_parse_arguments(PARSE_ARGV 1 arg + "${no_value_options}" "${single_value_options}" "${multi_value_options}" + ) + + set(result "") + set(candidates + v8_context_snapshot.bin + v8_context_snapshot.debug.bin + ) + if(__QT_DEPLOY_QT_IS_MULTI_CONFIG_BUILD_WITH_DEBUG + AND __QT_DEPLOY_ACTIVE_CONFIG STREQUAL "Debug") + # Favor the debug version of the snapshot. + list(REVERSE candidates) + endif() + foreach(candidate IN LISTS candidates) + if(EXISTS "${arg_RESOURCES_DIR}/${candidate}") + set(result "${candidate}") + break() + endif() + endforeach() + set("${out_var}" "${result}" PARENT_SCOPE) +endfunction() + +function(_qt_internal_deploy_webenginecore_translations) + _qt_internal_webenginecore_status_message("Deploying the WebEngineCore translations") + + get_filename_component(locales_dir "qtwebengine_locales" ABSOLUTE + BASE_DIR "${__QT_DEPLOY_QT_INSTALL_PREFIX}/${__QT_DEPLOY_QT_INSTALL_TRANSLATIONS}" + ) + get_filename_component(install_destination "qtwebengine_locales" ABSOLUTE + BASE_DIR "${QT_DEPLOY_PREFIX}/${QT_DEPLOY_TRANSLATIONS_DIR}" + ) + file(GLOB locale_files "${locales_dir}/*.pak") + foreach(locale_file IN LISTS locale_files) + file(INSTALL "${locale_file}" DESTINATION "${install_destination}") + endforeach() +endfunction() diff --git a/src/core/api/Qt6WebEngineCoreMacros.cmake b/src/core/api/Qt6WebEngineCoreMacros.cmake index 7e23f377e..a5f80f7b4 100644 --- a/src/core/api/Qt6WebEngineCoreMacros.cmake +++ b/src/core/api/Qt6WebEngineCoreMacros.cmake @@ -1,6 +1,12 @@ # Copyright (C) 2022 The Qt Company Ltd. # SPDX-License-Identifier: BSD-3-Clause +# Install support uses the CMAKE_INSTALL_xxxDIR variables. Include this here +# so that it is more likely to get pulled in earlier at a higher level, and also +# to avoid re-including it many times later +include(GNUInstallDirs) +_qt_internal_add_deploy_support("${CMAKE_CURRENT_LIST_DIR}/Qt6WebEngineCoreDeploySupport.cmake") + function(qt6_add_webengine_dictionary) set(options) set(oneValueArgs TARGET SOURCE OUTPUT_DIRECTORY) |