AUTOMOC depfile support for Ninja is broken for a CMake nested project
Top level CMakeLists.txt
cmake_minimum_required(VERSION 3.15)
project(automoc_deps_top VERSION 1.0.0 LANGUAGES CXX)
add_subdirectory(nested)
./nested/CMakeLists.txt
project(automoc_deps VERSION 1.0.0 LANGUAGES CXX)
set(CMAKE_INCLUDE_CURRENT_DIR ON)
set(CMAKE_AUTOMOC ON)
set(CMAKE_AUTOGEN_VERBOSE ON)
find_package(Qt5 COMPONENTS Core)
add_executable(app main.cpp)
target_link_libraries(app PUBLIC Qt5::Core)
./nested/main.cpp
#include <QCoreApplication>
int main(int argc, char *argv[])
{
QCoreApplication app(argc, argv);
return app.exec();
}
#include "moc_main.cpp"
./nested/main.h
#include <QObject>
class MyBuffer : public QObject
{
Q_OBJECT
};
Configure with cmake -GNinja -DCMAKE_PREFIX_PATH=/path/to/qt/5.15 build
Run ninja -v
twice, notice that the second run runs the autogen target, recompiles mocs_compilation.cpp and re-links the app.
[1/3] cd /Volumes/T3/Dev/projects/cmake/qt5/automoc_deps/build/nested && /Users/alex/Dev/cmake/deps_build/bin/cmake -E cmake_autogen /Volumes/T3/Dev/projects/cmake/qt5/automoc_deps/build/nested/CMakeFiles/app_autogen.dir/AutogenInfo.json "" && /Users/alex/Dev/cmake/deps_build/bin/cmake -E touch /Volumes/T3/Dev/projects/cmake/qt5/automoc_deps/build/nested/app_autogen/timestamp
AutoMoc: Merging MOC dependencies
[2/3] /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -DQT_CORE_LIB -DQT_NO_DEBUG -Inested -I../nested -Inested/app_autogen/include -isystem /Volumes/T3/Dev/qt/qt515_built/qtbase/include -isystem /Volumes/T3/Dev/qt/qt515_built/qtbase/include/QtCore -isystem /Volumes/T3/Dev/qt/qt515_built/qtbase/../../qt515_source/qtbase/mkspecs/macx-clang-path -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -fPIC -std=gnu++11 -MD -MT nested/CMakeFiles/app.dir/app_autogen/mocs_compilation.cpp.o -MF nested/CMakeFiles/app.dir/app_autogen/mocs_compilation.cpp.o.d -o nested/CMakeFiles/app.dir/app_autogen/mocs_compilation.cpp.o -c nested/app_autogen/mocs_compilation.cpp
[3/3] : && /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++ -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.sdk -Wl,-search_paths_first -Wl,-headerpad_max_install_names nested/CMakeFiles/app.dir/app_autogen/mocs_compilation.cpp.o nested/CMakeFiles/app.dir/main.cpp.o -o nested/app -Wl,-rpath,/Volumes/T3/Dev/qt/qt515_built/qtbase/lib /Volumes/T3/Dev/qt/qt515_built/qtbase/lib/libQt5Core_debug.5.15.0.dylib
ninja -d explain
ninja explain: expected depfile '/Volumes/T3/Dev/projects/cmake/qt5/automoc_deps/build/nested/app_autogen/deps' to mention 'nested/app_autogen/timestamp', got 'app_autogen/timestamp'
ninja explain: nested/app_autogen/timestamp is dirty
ninja explain: nested/app_autogen/mocs_compilation.cpp is dirty
ninja explain: nested/app_autogen/mocs_compilation.cpp is dirty
ninja explain: nested/CMakeFiles/app_autogen is dirty
ninja explain: nested/app_autogen/mocs_compilation.cpp is dirty
ninja explain: nested/app_autogen/timestamp is dirty
ninja explain: nested/CMakeFiles/app.dir/app_autogen/mocs_compilation.cpp.o is dirty
ninja explain: nested/app is dirty
ninja explain: nested/all is dirty
[1/3] Automatic MOC for target app
AutoMoc: Merging MOC dependencies
[3/3] Linking CXX executable nested/app
Looks like the generated depfile content doesn't have the full relative path that it should for the timestamp file.
$ cat /Volumes/T3/Dev/projects/cmake/qt5/automoc_deps/build/nested/app_autogen/deps
app_autogen/timestamp: \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/Availability.h \
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX.sdk/usr/include/AvailabilityInternal.h \
# ....