client: Add CMake options to control visibility of generated symbols

Using public-code by default is problematic if multiple libraries
contain wayland interface definitions generated with public-code
which exports the symbols of the interface definitions from the
library. If not all libraries are build against the same protocol
version and the symbol is resolved to a version generated from an older
version of the protocol, then libwayland will detect a protocol error
if a request or event from the newer version is used.
This introduces two new options PRIVATE_CODE and PUBLIC_CODE to
qt6_generate_wayland_protocol_client_sources which correspond to the
wayland-scanner options. For backwards compatibility PUBLIC_CODE
is the default.

Change-Id: Ia30ec4b83419962b768207d7353c495e11b0268e
Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@qt.io>
This commit is contained in:
David Redondo 2024-03-01 10:36:58 +01:00
parent ddb35b21ee
commit 2962aa9ed9
2 changed files with 22 additions and 3 deletions

View File

@ -23,6 +23,7 @@ find_package(Qt6 REQUIRED COMPONENTS WaylandClient)
\badcode
qt_generate_wayland_protocol_client_sources(target
[PUBLIC_CODE | PRIVATE_CODE]
FILES file1.xml [file2.xml ...])
\endcode
@ -30,11 +31,15 @@ qt_generate_wayland_protocol_client_sources(target
\section1 Description
qt_generate_wayland_protocol_client_sources() creates the build steps to run \c{waylandscanner} and
qt_generate_wayland_protocol_client_sources() creates the build steps to run \c{wayland-scanner} and
\c{qtwaylandscanner} on one or more Wayland protocol files. The tools will in turn generate binding
code in C and C++ for implementing the protocols, and the resulting files will be built as part
of the \c target.
The options \c{PUBLIC_CODE} and \c{PRIVATE_CODE} correspond to the \c{public-code} and
\c{private-code} options of \c{wayland-scanner}. For backwards compatibility \c{PUBLIC_CODE} is the
default but generally \c{PRIVATE_CODE} is strongly recommended.
qt_generate_wayland_protocol_client_sources() will trigger generation of the files needed to
implement the client side of the protocol. \l{qt_generate_wayland_protocol_server_sources}{qt_generate_wayland_protocol_server_sources()}
is the equivalent function for the compositor.

View File

@ -1,8 +1,14 @@
# 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})
cmake_parse_arguments(arg
"NO_INCLUDE_CORE_ONLY;PRIVATE_CODE;PUBLIC_CODE"
"__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()
@ -34,6 +40,14 @@ function(qt6_generate_wayland_protocol_client_sources target)
if (NOT arg_NO_INCLUDE_CORE_ONLY)
set(waylandscanner_extra_args "--include-core-only")
endif()
if (arg_PRIVATE_CODE)
set(wayland_scanner_code_option "private-code")
else()
set(wayland_scanner_code_option "public-code")
endif()
add_custom_command(
OUTPUT "${waylandscanner_header_output}"
#TODO: Maybe put the files in ${CMAKE_CURRENT_BINARY_DIR/wayland_generated instead?
@ -43,7 +57,7 @@ function(qt6_generate_wayland_protocol_client_sources target)
add_custom_command(
OUTPUT "${waylandscanner_code_output}"
COMMAND Wayland::Scanner ${waylandscanner_extra_args} public-code < "${protocol_file}" > "${waylandscanner_code_output}"
COMMAND Wayland::Scanner ${waylandscanner_extra_args} ${wayland_scanner_code_option} < "${protocol_file}" > "${waylandscanner_code_output}"
DEPENDS ${protocol_file} Wayland::Scanner
)