Skip to content

GitLab

  • Projects
  • Groups
  • Snippets
  • Help
    • Loading...
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
CMake
CMake
  • Project overview
    • Project overview
    • Details
    • Activity
    • Releases
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,236
    • Issues 3,236
    • List
    • Boards
    • Labels
    • Service Desk
    • Milestones
  • Merge Requests 14
    • Merge Requests 14
  • CI / CD
    • CI / CD
    • Pipelines
    • Jobs
    • Schedules
  • Operations
    • Operations
    • Incidents
    • Environments
  • Packages & Registries
    • Packages & Registries
    • Container Registry
  • Analytics
    • Analytics
    • CI / CD
    • Repository
    • Value Stream
  • External Wiki
    • External Wiki
  • Members
    • Members
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • CMake
  • CMakeCMake
  • Issues
  • #17750

Closed
Open
Opened Feb 19, 2018 by Friedrich@kossebau

automoc: dependencies added with AUTOGEN_TARGET_DEPENDS do not trigger moc re-run if Q_OBJECT is inside C++ preprocessor macro

Given a file DATA which is registered by AUTOGEN_TARGET_DEPENDS for a target, and given a source file which declares a QObject subclass by a C++ preprocessor macro, incl. the Q_OBJECT macro, then the Makefiles generated by cmake (at least 3.10.2) will not result in a re-run of moc on the sources if the file DATA is changed. It works, if the Q_OBJECT macro is used directly.

This affects at least a lot of KDE projects, where plugins typically are done setting the JSON metadata of the QObject plugin classes by a separate JSON file, which either is edited directly or created on-the-fly during the build from metadata in another format ("desktop" files). And the boilerplate code for defining the plugin entry classes is done via C++ preprocessor macros, which also define those QObject subclasses including Q_OBJECT macros.

I have no idea of the internals of automoc/cmake, so cannot point to anything sadly.

Expected

When autogen target dependencies change, moc is also re-run if the Q_OBJECT call is inside a C++ preprocessor macro (listed in CMAKE_AUTOMOC_MACRO_NAMES as used/needed elsewhere).

Test case

Place the following files in a new subdirectory, then do this in the subdir:

# preparation
mkdir build
cd build
cmake ..
make
# trigger issue
rm pluginA.json pluginF.json
make

With both QObject metadata files removed, one would expect the buildsystem rules to first regenerate both and then also rerun moc and following the recompilation of the sources.

Though that only happens for the source file of pluginA, where the Q_OBJECT is not used as part of a macro. For pluginF moc seems not re-run (the timestamp of pluginF_autogen/include/pluginF.moc does not change):

[ 10%] Generating plugin metadata file pluginA.json
[ 20%] Automatic MOC for target pluginA
[ 20%] Built target pluginA_autogen
Scanning dependencies of target pluginA
[ 30%] Building CXX object CMakeFiles/pluginA.dir/pluginA.cpp.o
[ 40%] Linking CXX shared module libpluginA.so
[ 50%] Built target pluginA
[ 60%] Generating plugin metadata file pluginF.json
[ 70%] Automatic MOC for target pluginF
[ 70%] Built target pluginF_autogen
[100%] Built target pluginF

Things also do not change if adding

list(APPEND CMAKE_AUTOMOC_MACRO_NAMES OBJECT)

to the CMakeLists.txt (as one should do, forgot to add to the uploaded file).

plugin.metadata

CMakeLists.txt

pluginA.cpp

pluginF.cpp

To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information
Assignee
Assign to
None
Milestone
None
Assign milestone
Time tracking
None
Due date
None
Reference: cmake/cmake#17750