summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Redondo <qt@david-redondo.de>2024-03-01 10:36:58 +0100
committerDavid Redondo <qt@david-redondo.de>2024-04-15 14:50:16 +0200
commit93e8b36ff5172115404de0a1eeb8174e6618f47e (patch)
tree45718124efaf46d8062b33f559c171c88279b4a6
parentf6c4b2f0691ea0240566c068cf36ed95003153e1 (diff)
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>
-rw-r--r--src/client/Qt6WaylandClientMacros.cmake18
-rw-r--r--src/client/doc/src/cmake/qt_generate_wayland_protocol_client_sources.qdoc7
2 files changed, 22 insertions, 3 deletions
diff --git a/src/client/Qt6WaylandClientMacros.cmake b/src/client/Qt6WaylandClientMacros.cmake
index 485322e6a..b4266c558 100644
--- a/src/client/Qt6WaylandClientMacros.cmake
+++ b/src/client/Qt6WaylandClientMacros.cmake
@@ -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
)
diff --git a/src/client/doc/src/cmake/qt_generate_wayland_protocol_client_sources.qdoc b/src/client/doc/src/cmake/qt_generate_wayland_protocol_client_sources.qdoc
index 97a7f7ed4..43f448fbd 100644
--- a/src/client/doc/src/cmake/qt_generate_wayland_protocol_client_sources.qdoc
+++ b/src/client/doc/src/cmake/qt_generate_wayland_protocol_client_sources.qdoc
@@ -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.