From 816071d440127f2e1794d10481448a3c1b87db93 Mon Sep 17 00:00:00 2001 From: Alexey Edelev Date: Thu, 16 May 2024 13:58:40 +0200 Subject: [PATCH] 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 Reviewed-by: Alexandru Croitor --- cmake/QtAppHelpers.cmake | 2 -- cmake/QtFlagHandlingHelpers.cmake | 23 ------------ cmake/QtModuleHelpers.cmake | 2 -- cmake/QtPluginHelpers.cmake | 2 -- cmake/QtTestHelpers.cmake | 4 --- cmake/QtToolHelpers.cmake | 2 -- qmake/CMakeLists.txt | 3 -- src/corelib/CMakeLists.txt | 36 +++++++++++++++++++ src/corelib/global/qtconfigmacros.h | 1 + .../global/qtdeprecationdefinitions.h.in | 28 +++++++++++++++ src/corelib/global/qtdeprecationmarkers.h | 23 +----------- 11 files changed, 66 insertions(+), 60 deletions(-) create mode 100644 src/corelib/global/qtdeprecationdefinitions.h.in diff --git a/cmake/QtAppHelpers.cmake b/cmake/QtAppHelpers.cmake index c0ad53ab9e2..f0dbd110ab1 100644 --- a/cmake/QtAppHelpers.cmake +++ b/cmake/QtAppHelpers.cmake @@ -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() diff --git a/cmake/QtFlagHandlingHelpers.cmake b/cmake/QtFlagHandlingHelpers.cmake index 6a62b85c03c..251a356df0e 100644 --- a/cmake/QtFlagHandlingHelpers.cmake +++ b/cmake/QtFlagHandlingHelpers.cmake @@ -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 "") diff --git a/cmake/QtModuleHelpers.cmake b/cmake/QtModuleHelpers.cmake index ba031730738..cc111affad8 100644 --- a/cmake/QtModuleHelpers.cmake +++ b/cmake/QtModuleHelpers.cmake @@ -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() diff --git a/cmake/QtPluginHelpers.cmake b/cmake/QtPluginHelpers.cmake index 787788c9a94..a4188b72897 100644 --- a/cmake/QtPluginHelpers.cmake +++ b/cmake/QtPluginHelpers.cmake @@ -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) diff --git a/cmake/QtTestHelpers.cmake b/cmake/QtTestHelpers.cmake index b6bba5ed129..62ee91296f6 100644 --- a/cmake/QtTestHelpers.cmake +++ b/cmake/QtTestHelpers.cmake @@ -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} diff --git a/cmake/QtToolHelpers.cmake b/cmake/QtToolHelpers.cmake index 7dd507c0eec..54ddefa7608 100644 --- a/cmake/QtToolHelpers.cmake +++ b/cmake/QtToolHelpers.cmake @@ -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() diff --git a/qmake/CMakeLists.txt b/qmake/CMakeLists.txt index 5a545701947..ee7a91eae6d 100644 --- a/qmake/CMakeLists.txt +++ b/qmake/CMakeLists.txt @@ -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) diff --git a/src/corelib/CMakeLists.txt b/src/corelib/CMakeLists.txt index 3707d5f8869..1055cf4ab53 100644 --- a/src/corelib/CMakeLists.txt +++ b/src/corelib/CMakeLists.txt @@ -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() diff --git a/src/corelib/global/qtconfigmacros.h b/src/corelib/global/qtconfigmacros.h index 03d52d885ad..b643122d5c1 100644 --- a/src/corelib/global/qtconfigmacros.h +++ b/src/corelib/global/qtconfigmacros.h @@ -9,6 +9,7 @@ #endif #include +#include #include #include diff --git a/src/corelib/global/qtdeprecationdefinitions.h.in b/src/corelib/global/qtdeprecationdefinitions.h.in new file mode 100644 index 00000000000..0570f63a5aa --- /dev/null +++ b/src/corelib/global/qtdeprecationdefinitions.h.in @@ -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 diff --git a/src/corelib/global/qtdeprecationmarkers.h b/src/corelib/global/qtdeprecationmarkers.h index 6df5ebce6d2..68f4fda1863 100644 --- a/src/corelib/global/qtdeprecationmarkers.h +++ b/src/corelib/global/qtdeprecationmarkers.h @@ -5,6 +5,7 @@ #define QTDEPRECATIONMARKERS_H #include +#include #include #include // 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.