Help automoc to find metadata JSON files referenced in the code

Summary:
automoc by itself can only detect metadata files referenced by direct
usage of the Q_PLUGIN_METADATA macro. It does not do any C++ preprocessor
evaluation. Instead it needs to be helped with regexp-based filter rules
for detecting any names of files used as additional moc input.
See docs for AUTOMOC_DEPEND_FILTERS for further details.

In the near future all the boilerplate code should be replaced with a yet to
be designed ECM macro. For now explicit code is used to collect use cases
for the macro and still to fix the issue already.

Test Plan:
Changing a JSON file (or for those generated from .desktop files
changing that one) and running make results in the related *.moc file
being regenerated and the related object file being recompiled.
qtplugininfo shows that the created plugin binary has up-to-date JSON
content.

Reviewers: #frameworks, #build_system, apol

Tags: #frameworks

Differential Revision: https://phabricator.kde.org/D10732
This commit is contained in:
Friedrich W. H. Kossebau 2018-02-22 01:59:12 +01:00
parent e80ebab9db
commit c03c2d5265
2 changed files with 48 additions and 6 deletions

View File

@ -127,26 +127,52 @@ endif()
#########################################################################
set(Plasma_AUTOMOC_MACRO_NAMES
# TODO: create ECM macro for automoc & json things
set(Plasma_AUTOMOC_MACRO_NAMES_WITH_NO_JSON
"K_EXPORT_PLASMA_SERVICE"
"K_EXPORT_PLASMA_SERVICE_WITH_JSON"
"K_EXPORT_PLASMA_APPLET"
"K_EXPORT_PLASMA_APPLET_WITH_JSON"
"K_EXPORT_PLASMA_PACKAGE"
"K_EXPORT_PLASMA_PACKAGE_WITH_JSON"
"K_EXPORT_PLASMA_APPLETSCRIPTENGINE"
"K_EXPORT_PLASMA_APPLETSCRIPTENGINE_WITH_JSON"
"K_EXPORT_PLASMA_DATAENGINESCRIPTENGINE"
"K_EXPORT_PLASMA_DATAENGINE"
)
set(Plasma_AUTOMOC_MACRO_NAMES_WITH_JSON_ARG2
"K_EXPORT_PLASMA_PACKAGE_WITH_JSON"
)
set(Plasma_AUTOMOC_MACRO_NAMES_WITH_JSON_ARG3
"K_EXPORT_PLASMA_SERVICE_WITH_JSON"
"K_EXPORT_PLASMA_APPLET_WITH_JSON"
"K_EXPORT_PLASMA_APPLETSCRIPTENGINE_WITH_JSON"
"K_EXPORT_PLASMA_DATAENGINESCRIPTENGINE_WITH_JSON"
"K_EXPORT_PLASMA_CONTAINMENTACTIONS_WITH_JSON"
"K_EXPORT_PLASMA_DATAENGINE"
"K_EXPORT_PLASMA_DATAENGINE_WITH_JSON"
)
set(Plasma_AUTOMOC_MACRO_NAMES
${Plasma_AUTOMOC_MACRO_NAMES_WITH_NO_JSON}
${Plasma_AUTOMOC_MACRO_NAMES_WITH_JSON_ARG2}
${Plasma_AUTOMOC_MACRO_NAMES_WITH_JSON_ARG3}
)
if(NOT CMAKE_VERSION VERSION_LESS "3.10.0")
# CMake 3.9+ warns about automoc on files without Q_OBJECT, and doesn't know about other macros.
# 3.10+ lets us provide more macro names that require automoc.
list(APPEND CMAKE_AUTOMOC_MACRO_NAMES ${Plasma_AUTOMOC_MACRO_NAMES})
endif()
if(NOT CMAKE_VERSION VERSION_LESS "3.9.0")
foreach(macro_name ${Plasma_AUTOMOC_MACRO_NAMES_WITH_JSON_ARG2})
# tell automoc how to find names of plugin metadata files
list(APPEND CMAKE_AUTOMOC_DEPEND_FILTERS
"${macro_name}"
"[\n^][ \t]*${macro_name}[ \t\n]*\\([^,]*,[ \t\n]*\"([^\"]+)\""
)
endforeach()
foreach(macro_name ${Plasma_AUTOMOC_MACRO_NAMES_WITH_JSON_ARG3})
# tell automoc how to find names of plugin metadata files
list(APPEND CMAKE_AUTOMOC_DEPEND_FILTERS
"${macro_name}"
"[\n^][ \t]*${macro_name}[ \t\n]*\\([^,]*,[^,]*,[ \t\n]*\"([^\"]+)\""
)
endforeach()
endif()
add_definitions(-DQT_DISABLE_DEPRECATED_BEFORE=0)

View File

@ -25,5 +25,21 @@ if(NOT CMAKE_VERSION VERSION_LESS "3.10.0")
# 3.10+ lets us provide more macro names that require automoc.
list(APPEND CMAKE_AUTOMOC_MACRO_NAMES @Plasma_AUTOMOC_MACRO_NAMES@)
endif()
if(NOT CMAKE_VERSION VERSION_LESS "3.9.0")
foreach(macro_name @Plasma_AUTOMOC_MACRO_NAMES_WITH_JSON_ARG2@)
# tell automoc how to find names of plugin metadata files
list(APPEND CMAKE_AUTOMOC_DEPEND_FILTERS
"${macro_name}"
"[\n^][ \t]*${macro_name}[ \t\n]*\\([^,]*,[ \t\n]*\"([^\"]+)\""
)
endforeach()
foreach(macro_name @Plasma_AUTOMOC_MACRO_NAMES_WITH_JSON_ARG3@)
# tell automoc how to find names of plugin metadata files
list(APPEND CMAKE_AUTOMOC_DEPEND_FILTERS
"${macro_name}"
"[\n^][ \t]*${macro_name}[ \t\n]*\\([^,]*,[^,]*,[ \t\n]*\"([^\"]+)\""
)
endforeach()
endif()
include("${CMAKE_CURRENT_LIST_DIR}/KF5PlasmaMacros.cmake")