unnecessary autogen dependencies?
Is there a good reason for having the compilation of target sources depend on the automoc generation?
cmake_minimum_required(VERSION 3.17)
project(test)
find_package(Qt5 COMPONENTS Core)
set(CMAKE_AUTOMOC ON)
add_executable(test test.cpp)
target_link_libraries(test Qt5::Core)
#include "test.h"
int main()
{}
#include <QObject>
class Foo final : public QObject
{
Q_OBJECT
};
produces build.ninja
:
test_autogen: phony CMakeFiles/test_autogen test_autogen/mocs_compilation.cpp
CMakeFiles/test_autogen test_autogen/mocs_compilation.cpp: CUSTOM_COMMAND
cmake_object_order_depends_target_test: phony || test_autogen
CMakeFiles/test.dir/test_autogen/mocs_compilation.cpp.o: CXX_COMPILER__test_ test_autogen/mocs_compilation.cpp || cmake_object_order_depends_target_test
CMakeFiles/test.dir/test.cpp.o: CXX_COMPILER__test_ test.cpp || cmake_object_order_depends_target_test
test: CXX_EXECUTABLE_LINKER__test_ CMakeFiles/test.dir/test_autogen/mocs_compilation.cpp.o CMakeFiles/test.dir/test.cpp.o | /usr/lib/libQt5Core.so.5.6.2 || test_autogen
I can't see why test.cpp.o
compilation should depend on the mocs_compilation.cpp
generation.
Also there are "artificial" dependencies in the other direction which is not covered in the example: autogen => (shared lib) dependencies of the exe target
This creates a huge bottleneck in our real-world code where automoc takes up to 1 minute for some targets and nothing else happens during that process.