Details
-
Bug
-
Resolution: Fixed
-
P2: Important
-
5.15.8, 6.4.2
-
1fc42dc2c (tqtc/lts-5.15), 38ee9ee84 (dev), 32124d370 (6.5), 6d5d74c44 (6.4), 6964c01d1 (tqtc/lts-6.2)
Description
When searching for the Qt dependencies from CMake code, both directly e.g. via
find_package(Qt5Core CONFIG REQUIRED)
or indirectly from other CMake config files via
find_dependency(Qt5Core)
the respective included and executed CMake code for Qt resets the value CMAKE_AUTOMOC_MACRO_NAMES, discarding any content set before by other code..
The reason is that Qt5CoreConfig.cmake includes Qt5CoreConfigExtras.cmake which has the line
set(CMAKE_AUTOMOC_MACRO_NAMES Q_OBJECT Q_GADGET Q_NAMESPACE Q_NAMESPACE_EXPORT)
The include of Qt5CoreConfigExtras.cmake is wrapped with the condition
if (NOT TARGET Qt5::Core)
so one can work-around that behaviour by making sure Qt5 was already found before adding own macro names to CMAKE_AUTOMOC_MACRO_NAMES.
With Qt6 things are similar, but the workaround no longer works and it broken also.
This is because there the include of Qt6CoreConfigExtras.cmake is now inside a condition
if (TARGET Qt6::Core)
and as result any
find_package(Qt6Core CONFIG REQUIRED)
or indirectly from other CMake config files via
find_dependency(Qt6Core)
will again result in the inclusion and execution of Qt6CoreConfigExtras.cmake and thus the reset of CMAKE_AUTOMOC_MACRO_NAMES.
Ideally Qt's cmake code would only append its values to the cmake variable if not yet present, by something like
foreach(macro_name Q_OBJECT Q_GADGET Q_NAMESPACE Q_NAMESPACE_EXPORT)
# we can be run multiple times, so add only once
list (FIND CMAKE_AUTOMOC_MACRO_NAMES ${macro_name} _index)
if(_index LESS 0)
list(APPEND CMAKE_AUTOMOC_MACRO_NAMES ${macro_name})
endif()
endforeach()
(inspired from code I authored in https://invent.kde.org/frameworks/extra-cmake-modules/-/blob/master/modules/ECMSetupQtPluginMacroNames.cmake).
The issue has been found during current development of KDE Frameworks 6, where https://api.kde.org/ecm/module/ECMSetupQtPluginMacroNames.html suddenly stopped working as intended,. That one generates cmake code e.g. for own CMake config files to setup {{CMAKE_AUTOMOC_MACRO_NAMES }}with custom C++ macros.
Example (code generated for KF5CoreAddonsConfig.cmake):
foreach(macro_name K_PLUGIN_FACTORY;K_PLUGIN_CLASS;K_PLUGIN_FACTORY_WITH_JSON;K_PLUGIN_CLASS_WITH_JSON) # we can be run multiple times, so add only once list (FIND CMAKE_AUTOMOC_MACRO_NAMES "${macro_name}" _index) if(_index LESS 0) list(APPEND CMAKE_AUTOMOC_MACRO_NAMES ${macro_name}) endif() endforeach()
This code in the CMake config files then automatically prepares things for any projects using KF5CoreAddons by
find_package(KF5CoreAddons CONFIG REQUIRED)
to have automoc know about those additional macros provided by KF5CoreAddons when using them in the own code.
Just any cmake code, also directly or indirectly included, later which once more checks for the Qt6 package now resets {{CMAKE_AUTOMOC_MACRO_NAMES }}again.
Attachments
Issue Links
- mentioned in
-
Page Loading...