Autogen: 3.28 regresses some dependencies with Unix Makefiles generator
EDIT: See discussion at #25600 (comment 1469954) for a more direct description of the problem after initial analysis.
In CMake 3.28.1 using the Makefile generator, when you have a target that uses Qt's AUTOMOC as well as a file generated by add_custom_target
and the target being defined is in a subdirectory relative to the generated file running make
fails with no rule to make target
.
This seems to be because the generated filename in the _autogen_timestamp_deps.dir/build.make
file is missing the directory part of the filename.
A minimal reproduction of this bug can be found here: https://github.com/SamVanheer/CMakeGeneratedFileBug
Uncommenting the add_executable
command in the root CMakeLists.txt
and commenting out the one in the src
directory causes it to compile just fine. Note that you'll need to delete the generated header file to test the initial configuration again.
The filenames listed in build.make
are:
src/CMakeFiles/Exe_autogen_timestamp_deps: ProjectInfo.hpp
src/CMakeFiles/Exe_autogen_timestamp_deps: /usr/lib/x86_64-linux-gnu/libQt5Widgets.so.5.15.3
src/CMakeFiles/Exe_autogen_timestamp_deps: /usr/lib/qt5/bin/moc
As you can see it's missing the directory.
Note that Qt does not need to be linked to for this to happen. As long as AUTOMOC is enabled and a valid Qt dependency has been found this will occur.
I encountered this in my own project in Github Actions before reproducing it locally using 3.28.1: https://github.com/SamVanheer/HalfLifeAssetManager/actions/runs/7533460940/job/20507360222
The problem does not appear to happen on Windows so this is probably only happening in the Makefile generator, but I have not tested other generators.