Move QT_DISABLE_DEPRECATED_UP_TO and QT_WARN_DEPRECATED_UP_TO to header

The new approach allows to imply the macro definitions for every Qt
submodule and user project without the need of setting it explicitly
from CMake. This also prevent users from introducing the
incompatibility between Qt modules due to defining
the QT_DISABLE_DEPRECATED_UP_TO version lower than qtbase was built
with.

Task-number: QTBUG-124765
Change-Id: I7ba481f62cb9073ae0343c400ffc26f239f080f1
Reviewed-by: Ivan Solovev <ivan.solovev@qt.io>
Reviewed-by: Alexandru Croitor <alexandru.croitor@qt.io>
This commit is contained in:
Alexey Edelev 2024-05-16 13:58:40 +02:00
parent 8f03bb6bd8
commit 816071d440
11 changed files with 66 additions and 60 deletions

View File

@ -35,8 +35,6 @@ function(qt_internal_add_app target)
"a future Qt version. Use the LIBRARIES option instead.")
endif()
qt_internal_library_deprecation_level(deprecation_define)
if(arg_NO_UNITY_BUILD)
set(arg_NO_UNITY_BUILD "NO_UNITY_BUILD")
else()

View File

@ -258,29 +258,6 @@ function(qt_internal_apply_intel_cet target visibility)
endif()
endfunction()
function(qt_internal_library_deprecation_level result)
# QT_DISABLE_DEPRECATED_UP_TO controls which version we use as a cut-off
# compiling in to the library. E.g. if it is set to QT_VERSION then no
# code which was deprecated before QT_VERSION will be compiled in.
if (NOT DEFINED QT_DISABLE_DEPRECATED_UP_TO)
if(WIN32)
# On Windows, due to the way DLLs work, we need to export all functions,
# including the inlines
list(APPEND deprecations "QT_DISABLE_DEPRECATED_UP_TO=0x040800")
else()
# On other platforms, Qt's own compilation does need to compile the Qt 5.0 API
list(APPEND deprecations "QT_DISABLE_DEPRECATED_UP_TO=0x050000")
endif()
else()
list(APPEND deprecations "QT_DISABLE_DEPRECATED_UP_TO=${QT_DISABLE_DEPRECATED_UP_TO}")
endif()
# QT_WARN_DEPRECATED_UP_TO controls the upper-bound of deprecation
# warnings that are emitted. E.g. if it is set to 0x060500 then all use of
# things deprecated in or before 6.5.0 will be warned against.
list(APPEND deprecations "QT_WARN_DEPRECATED_UP_TO=0x070000")
set("${result}" "${deprecations}" PARENT_SCOPE)
endfunction()
# Sets the exceptions flags for the given target according to exceptions_on
function(qt_internal_set_exceptions_flags target exceptions_on)
set(_defs "")

View File

@ -497,8 +497,6 @@ function(qt_internal_add_module target)
endif()
endif()
qt_internal_library_deprecation_level(deprecation_define)
if(NOT arg_HEADER_MODULE)
qt_autogen_tools_initial_setup(${target})
endif()

View File

@ -170,8 +170,6 @@ function(qt_internal_add_plugin target)
qt_handle_multi_config_output_dirs("${target}")
qt_internal_library_deprecation_level(deprecation_define)
qt_autogen_tools_initial_setup(${target})
unset(plugin_install_package_suffix)

View File

@ -38,8 +38,6 @@ function(qt_internal_add_benchmark target)
endif()
endif()
qt_internal_library_deprecation_level(deprecation_define)
qt_internal_add_executable(${target}
NO_INSTALL # we don't install benchmarks
NO_UNITY_BUILD # excluded by default
@ -251,7 +249,6 @@ function(qt_internal_add_test_to_batch batch_name name)
# Lazy-init the test batch
if(NOT TARGET ${target})
qt_internal_library_deprecation_level(deprecation_define)
qt_internal_add_executable(${target}
${exceptions_text}
${gui_text}
@ -513,7 +510,6 @@ function(qt_internal_add_test name)
list(APPEND private_includes ${arg_INCLUDE_DIRECTORIES})
qt_internal_prepare_test_target_flags(version_arg exceptions_text gui_text ${ARGN})
qt_internal_library_deprecation_level(deprecation_define)
qt_internal_add_executable("${name}"
${exceptions_text}

View File

@ -100,8 +100,6 @@ function(qt_internal_add_tool target_name)
"removed in a future Qt version. Use the LIBRARIES option instead.")
endif()
qt_internal_library_deprecation_level(deprecation_define)
if(arg_NO_UNITY_BUILD)
set(arg_NO_UNITY_BUILD "NO_UNITY_BUILD")
else()

View File

@ -35,8 +35,6 @@ if("${hostdatadir}" STREQUAL "")
set(hostdatadir ".")
endif()
qt_internal_library_deprecation_level(deprecation_define)
target_compile_definitions(QtLibraryInfo PUBLIC
PROEVALUATOR_FULL
QT_BUILD_QMAKE
@ -44,7 +42,6 @@ target_compile_definitions(QtLibraryInfo PUBLIC
QT_HOST_MKSPEC="${QT_QMAKE_HOST_MKSPEC}"
QT_TARGET_MKSPEC="${QT_QMAKE_TARGET_MKSPEC}"
QT_HOST_DATADIR="${hostdatadir}"
${deprecation_define}
)
qt_internal_set_exceptions_flags(QtLibraryInfo OFF)

View File

@ -1484,3 +1484,39 @@ qt_internal_extend_target(Core
# QReadWriteLock::destroyRecursive(QReadWriteLockPrivate*)
"_ZN*14QReadWriteLock16destroyRecursiveEP*21QReadWriteLockPrivate*"
)
function(qt_internal_library_deprecation_level)
# QT_DISABLE_DEPRECATED_UP_TO controls which version we use as a cut-off
# compiling in to the library. E.g. if it is set to QT_VERSION then no
# code which was deprecated before QT_VERSION will be compiled in.
if(NOT DEFINED QT_DISABLE_DEPRECATED_UP_TO)
if(WIN32)
# On Windows, due to the way DLLs work, we need to export all functions,
# including the inlines
set(QT_DISABLE_DEPRECATED_UP_TO "0x040800")
else()
# On other platforms, Qt's own compilation does need to compile the Qt 5.0 API
set(QT_DISABLE_DEPRECATED_UP_TO "0x050000")
endif()
elseif(NOT QT_DISABLE_DEPRECATED_UP_TO MATCHES "^0x[0-9][0-9][0-9][0-9][0-9][0-9]$")
message(FATAL_ERROR "Ivalid format of the QT_DISABLE_DEPRECATED_UP_TO macro:"
" ${QT_DISABLE_DEPRECATED_UP_TO}. The expected format is the hexadecimal number,"
" e.g. 0x060102")
endif()
# QT_WARN_DEPRECATED_UP_TO controls the upper-bound of deprecation
# warnings that are emitted. E.g. if it is set to 0x060500 then all use of
# things deprecated in or before 6.5.0 will be warned against.
set(QT_WARN_DEPRECATED_UP_TO 0x070000)
set(output_header "${CMAKE_CURRENT_BINARY_DIR}/global/qtdeprecationdefinitions.h")
configure_file(
"${CMAKE_CURRENT_SOURCE_DIR}/global/qtdeprecationdefinitions.h.in"
"${output_header}"
@ONLY
NEWLINE_STYLE UNIX
)
target_sources(Core PRIVATE "${output_header}")
set_source_files_properties("${output_header}" PROPERTIES GENERATED TRUE)
endfunction()
qt_internal_library_deprecation_level()

View File

@ -9,6 +9,7 @@
#endif
#include <QtCore/qtconfiginclude.h>
#include <QtCore/qtdeprecationdefinitions.h>
#include <QtCore/qtversionchecks.h>
#include <assert.h>

View File

@ -0,0 +1,28 @@
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only OR GPL-2.0-only OR GPL-3.0-only
#ifndef QTDEPRECATIONDEFINITIONS_H
#define QTDEPRECATIONDEFINITIONS_H
#ifndef QT_DISABLE_DEPRECATED_UP_TO
# ifdef QT_DISABLE_DEPRECATED_BEFORE // If the deprecated macro is defined, use its value
# define QT_DISABLE_DEPRECATED_UP_TO QT_DISABLE_DEPRECATED_BEFORE
# else
# define QT_DISABLE_DEPRECATED_UP_TO @QT_DISABLE_DEPRECATED_UP_TO@
# endif
#endif
#if QT_DISABLE_DEPRECATED_UP_TO < @QT_DISABLE_DEPRECATED_UP_TO@
# warning QT_DISABLE_DEPRECATED_UP_TO is set to the version that is lower than the version that \
Qt was built with. This may lead to linking issues.
#endif
#ifndef QT_WARN_DEPRECATED_UP_TO
# ifdef QT_DEPRECATED_WARNINGS_SINCE // If the deprecated macro is defined, use its value
# define QT_WARN_DEPRECATED_UP_TO QT_DEPRECATED_WARNINGS_SINCE
# else
# define QT_WARN_DEPRECATED_UP_TO @QT_WARN_DEPRECATED_UP_TO@
# endif
#endif
#endif // QTDEPRECATIONDEFINITIONS_H

View File

@ -5,6 +5,7 @@
#define QTDEPRECATIONMARKERS_H
#include <QtCore/qtconfigmacros.h>
#include <QtCore/qtdeprecationdefinitions.h>
#include <QtCore/qtversionchecks.h>
#include <QtCore/qcompilerdetection.h> // for Q_DECL_DEPRECATED
@ -44,28 +45,6 @@ QT_BEGIN_NAMESPACE
# define Q_DECL_ENUMERATOR_DEPRECATED_X(ignored)
#endif
// If the deprecated macro is defined, use its value
#if !defined(QT_DISABLE_DEPRECATED_UP_TO) && defined(QT_DISABLE_DEPRECATED_BEFORE)
# define QT_DISABLE_DEPRECATED_UP_TO QT_DISABLE_DEPRECATED_BEFORE
#endif
// If the deprecated macro is defined, use its value
#if !defined(QT_WARN_DEPRECATED_UP_TO) && defined(QT_DEPRECATED_WARNINGS_SINCE)
# define QT_WARN_DEPRECATED_UP_TO QT_DEPRECATED_WARNINGS_SINCE
#endif
#ifndef QT_WARN_DEPRECATED_UP_TO
# ifdef QT_DISABLE_DEPRECATED_UP_TO
# define QT_WARN_DEPRECATED_UP_TO QT_DISABLE_DEPRECATED_UP_TO
# else
# define QT_WARN_DEPRECATED_UP_TO QT_VERSION
# endif
#endif
#ifndef QT_DISABLE_DEPRECATED_UP_TO
#define QT_DISABLE_DEPRECATED_UP_TO QT_VERSION_CHECK(5, 0, 0)
#endif
/*
QT_DEPRECATED_SINCE(major, minor) evaluates as true if the Qt version is greater than
the deprecation point specified.