diff --git a/CMakeLists.txt b/CMakeLists.txt index bdda16f59a..7c5c7547ba 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -42,6 +42,9 @@ if (QT_MAJOR_VERSION EQUAL "5") find_package(Qt5XkbCommonSupport REQUIRED) else() find_package(Qt6 ${QT_MIN_VERSION} CONFIG REQUIRED COMPONENTS WaylandClient ShaderTools) + if (Qt6WaylandClient_VERSION VERSION_LESS "6.4.1") # TODO Plasma 6: Drop once minimum Qt version is 6.4.1+ + include(Qt6WaylandClientMacrosKde) + endif() endif() find_package(Qt${QT_MAJOR_VERSION}Test ${QT_MIN_VERSION} CONFIG QUIET) diff --git a/autotests/integration/CMakeLists.txt b/autotests/integration/CMakeLists.txt index 0d2f60e00d..2712391be9 100644 --- a/autotests/integration/CMakeLists.txt +++ b/autotests/integration/CMakeLists.txt @@ -35,15 +35,20 @@ if (QT_MAJOR_VERSION EQUAL "5") BASENAME kde-output-management-v2 ) else() - qt6_generate_wayland_protocol_client_sources(KWinIntegrationTestFramework FILES - ${WaylandProtocols_DATADIR}/unstable/input-method/input-method-unstable-v1.xml - ${WaylandProtocols_DATADIR}/unstable/text-input/text-input-unstable-v3.xml - ${CMAKE_CURRENT_SOURCE_DIR}/protocols/wlr-layer-shell-unstable-v1.xml - ${WaylandProtocols_DATADIR}/stable/xdg-shell/xdg-shell.xml - ${WaylandProtocols_DATADIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml - ${WaylandProtocols_DATADIR}/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml - ${PLASMA_WAYLAND_PROTOCOLS_DIR}/kde-output-device-v2.xml - ${PLASMA_WAYLAND_PROTOCOLS_DIR}/kde-output-management-v2.xml + qt6_generate_wayland_protocol_client_sources(KWinIntegrationTestFramework + NO_INCLUDE_CORE_ONLY + FILES + ${WaylandProtocols_DATADIR}/unstable/input-method/input-method-unstable-v1.xml + ) + qt6_generate_wayland_protocol_client_sources(KWinIntegrationTestFramework + FILES + ${WaylandProtocols_DATADIR}/unstable/text-input/text-input-unstable-v3.xml + ${CMAKE_CURRENT_SOURCE_DIR}/protocols/wlr-layer-shell-unstable-v1.xml + ${WaylandProtocols_DATADIR}/stable/xdg-shell/xdg-shell.xml + ${WaylandProtocols_DATADIR}/unstable/xdg-decoration/xdg-decoration-unstable-v1.xml + ${WaylandProtocols_DATADIR}/unstable/idle-inhibit/idle-inhibit-unstable-v1.xml + ${PLASMA_WAYLAND_PROTOCOLS_DIR}/kde-output-device-v2.xml + ${PLASMA_WAYLAND_PROTOCOLS_DIR}/kde-output-management-v2.xml ) endif() diff --git a/cmake/modules/Qt6WaylandClientMacrosKde.cmake b/cmake/modules/Qt6WaylandClientMacrosKde.cmake new file mode 100644 index 0000000000..ea0ac323f8 --- /dev/null +++ b/cmake/modules/Qt6WaylandClientMacrosKde.cmake @@ -0,0 +1,101 @@ +# Copyright (C) 2022 The Qt Company Ltd. +# SPDX-License-Identifier: BSD-3-Clause + +function(qt6_generate_wayland_protocol_client_sources target) + cmake_parse_arguments(arg "NO_INCLUDE_CORE_ONLY" "__QT_INTERNAL_WAYLAND_INCLUDE_DIR" "FILES" ${ARGN}) + if(DEFINED arg_UNPARSED_ARGUMENTS) + message(FATAL_ERROR "Unknown arguments were passed to qt6_generate_wayland_protocol_client_sources: (${arg_UNPARSED_ARGUMENTS}).") + endif() + + get_target_property(target_binary_dir ${target} BINARY_DIR) + + if(NOT TARGET Wayland::Scanner) + message(FATAL_ERROR "Wayland::Scanner target not found. You might be missing the WaylandScanner CMake package.") + endif() + + if(NOT TARGET Qt6::qtwaylandscanner) + message(FATAL_ERROR "qtwaylandscanner executable not found. Most likely there is an issue with your Qt installation.") + endif() + + string(TOUPPER "${target}" module_define_infix) + string(REPLACE "-" "_" module_define_infix "${module_define_infix}") + string(REPLACE "." "_" module_define_infix "${module_define_infix}") + set(build_macro "QT_BUILD_${module_define_infix}_LIB") + + foreach(protocol_file IN LISTS arg_FILES) + get_filename_component(protocol_name "${protocol_file}" NAME_WLE) + + set(waylandscanner_header_output "${target_binary_dir}/wayland-${protocol_name}-client-protocol.h") + set(waylandscanner_code_output "${target_binary_dir}/wayland-${protocol_name}-protocol.c") + # TODO: Maybe add "client" prefix or suffix to these in Qt6? + set(qtwaylandscanner_header_output "${target_binary_dir}/qwayland-${protocol_name}.h") + set(qtwaylandscanner_code_output "${target_binary_dir}/qwayland-${protocol_name}.cpp") + + if (NOT arg_NO_INCLUDE_CORE_ONLY) + set(waylandscanner_extra_args "--include-core-only") + endif() + add_custom_command( + OUTPUT "${waylandscanner_header_output}" + #TODO: Maybe put the files in ${CMAKE_CURRENT_BINARY_DIR/wayland_generated instead? + COMMAND Wayland::Scanner --strict ${waylandscanner_extra_args} client-header < "${protocol_file}" > "${waylandscanner_header_output}" + ) + + add_custom_command( + OUTPUT "${waylandscanner_code_output}" + COMMAND Wayland::Scanner --strict ${waylandscanner_extra_args} public-code < "${protocol_file}" > "${waylandscanner_code_output}" + ) + + set(wayland_include_dir "") + if(arg___QT_INTERNAL_WAYLAND_INCLUDE_DIR) + set(wayland_include_dir "${arg___QT_INTERNAL_WAYLAND_INCLUDE_DIR}") + else() + get_target_property(qt_module ${target} _qt_module_interface_name) + get_target_property(is_for_module "${target}" _qt_module_has_headers) + if (qt_module) + set(wayland_include_dir "Qt${qt_module}/private") + elseif (is_for_module) + set(wayland_include_dir "QtWaylandClient/private") + endif() + endif() + + add_custom_command( + OUTPUT "${qtwaylandscanner_header_output}" + COMMAND Qt6::qtwaylandscanner client-header + "${protocol_file}" + --build-macro=${build_macro} + --header-path="${wayland_include_dir}" + > "${qtwaylandscanner_header_output}" + DEPENDS ${protocol_file} Qt6::qtwaylandscanner + ) + + set(qtwaylandscanner_code_include "") + if (is_for_module) + set(qtwaylandscanner_code_include "") + endif() + + add_custom_command( + OUTPUT "${qtwaylandscanner_code_output}" + COMMAND Qt6::qtwaylandscanner client-code + "${protocol_file}" + --build-macro=${build_macro} + --header-path='${wayland_include_dir}' + --add-include='${qtwaylandscanner_code_include}' + > "${qtwaylandscanner_code_output}" + DEPENDS ${protocol_file} Qt6::qtwaylandscanner + ) + + target_sources(${target} PRIVATE + "${waylandscanner_header_output}" + "${waylandscanner_code_output}" + "${qtwaylandscanner_header_output}" + "${qtwaylandscanner_code_output}" + ) + endforeach() + target_include_directories(${target} PRIVATE ${target_binary_dir}) +endfunction() + +if(NOT QT_NO_CREATE_VERSIONLESS_FUNCTIONS) + function(qt_generate_wayland_protocol_client_sources) + qt6_generate_wayland_protocol_client_sources(${ARGV}) + endfunction() +endif() diff --git a/src/wayland/autotests/server/CMakeLists.txt b/src/wayland/autotests/server/CMakeLists.txt index 504d49d54a..0db4bca52c 100644 --- a/src/wayland/autotests/server/CMakeLists.txt +++ b/src/wayland/autotests/server/CMakeLists.txt @@ -132,9 +132,14 @@ if (QT_MAJOR_VERSION EQUAL "5") BASENAME text-input-unstable-v1 ) else() - qt6_generate_wayland_protocol_client_sources(testInputMethodInterface FILES - ${WaylandProtocols_DATADIR}/unstable/input-method/input-method-unstable-v1.xml - ${WaylandProtocols_DATADIR}/unstable/text-input/text-input-unstable-v1.xml + qt6_generate_wayland_protocol_client_sources(testInputMethodInterface + NO_INCLUDE_CORE_ONLY + FILES + ${WaylandProtocols_DATADIR}/unstable/input-method/input-method-unstable-v1.xml + ) + qt6_generate_wayland_protocol_client_sources(testInputMethodInterface + FILES + ${WaylandProtocols_DATADIR}/unstable/text-input/text-input-unstable-v1.xml ) endif() target_sources(testInputMethodInterface PRIVATE test_inputmethod_interface.cpp ../../tests/fakeoutput.cpp ${INPUTMETHOD_SRCS})