diff --git a/CMakeLists.txt b/CMakeLists.txt --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -29,12 +29,27 @@ set(REQUIRED_QT_VERSION 5.7.0) find_package(Qt5 ${REQUIRED_QT_VERSION} CONFIG REQUIRED Core) +# TODO: create ECM macro for automoc & json things set(KCoreAddons_AUTOMOC_MACRO_NAMES "K_PLUGIN_FACTORY_WITH_JSON" "K_PLUGIN_FACTORY" "K_PLUGIN_CLASS_WITH_JSON") 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 ${KCoreAddons_AUTOMOC_MACRO_NAMES}) endif() +set(KCoreAddons_AUTOMOC_MACRO_NAMES_WITH_JSON_ARG2 "K_PLUGIN_FACTORY_WITH_JSON" "K_PLUGIN_CLASS_WITH_JSON") +if(NOT CMAKE_VERSION VERSION_LESS "3.9.0") + # CMake's automoc needs help to find names of plugin metadata files in case Q_PLUGIN_METADATA + # is indirectly used via other C++ preprocessor macros + # 3.9+ lets us provide some filter rule pairs (keyword, regexp) to match the names of such files + # in the plain text of the sources. See AUTOMOC_DEPEND_FILTERS docs for details. + foreach(macro_name ${KCoreAddons_AUTOMOC_MACRO_NAMES_WITH_JSON_ARG2}) + list(APPEND CMAKE_AUTOMOC_DEPEND_FILTERS + "${macro_name}" + "[\n^][ \t]*${macro_name}[ \t\n]*\\([^,]*,[ \t\n]*\"([^\"]+)\"" + ) + endforeach() +endif() + find_package(Threads) diff --git a/KF5CoreAddonsConfig.cmake.in b/KF5CoreAddonsConfig.cmake.in --- a/KF5CoreAddonsConfig.cmake.in +++ b/KF5CoreAddonsConfig.cmake.in @@ -9,6 +9,15 @@ # 3.10+ lets us provide more macro names that require automoc. list(APPEND CMAKE_AUTOMOC_MACRO_NAMES @KCoreAddons_AUTOMOC_MACRO_NAMES@) endif() +if(NOT CMAKE_VERSION VERSION_LESS "3.9.0") + foreach(macro_name @KCoreAddons_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() +endif() if(CMAKE_CROSSCOMPILING AND KF5_HOST_TOOLING) find_file(TARGETSFILE KF5CoreAddons/KF5CoreAddonsToolingTargets.cmake