Cmake recompile qml modules even if the qml files did not change.
-
Hi everyone.
I create applications that use qt6_add_qml_module cmake to define qml modules and export the targets to link in other applications.
The thing is, that every time a compile a project that creates a qml module the compiler rebuilds things like :
[ 48%] Building CXX object _deps/account-build/CMakeFiles/account.dir/account_qmltyperegistrations.cpp.o [ 50%] Building CXX object _deps/account-build/CMakeFiles/account.dir/.rcc/qmlcache/account_qml/AccountQml_qml.cpp.o [ 50%] Building CXX object _deps/account-build/CMakeFiles/account.dir/.rcc/qmlcache/account_qml/ShowSeed_qml.cpp.o [ 50%] Building CXX object _deps/account-build/CMakeFiles/account.dir/.rcc/qmlcache/account_qml/RestoreAccount_qml.cpp.o [ 50%] Linking CXX shared library libaccount.so
Although the source code of the account qml module did have not changed.
This take time if you have many targets that define a qml module.
Is there a way to stop this behavior?One example of my cmake configuration here.
Thank you in advance for your time.
-
@Mesrine said in Cmake recompile qml modules even if the qml files did not change.:
Is there a way to stop this behavior?
You have 2 options:
- Use the Ninja generator instead of the Makefile generator (recommended), OR
- Upgrade to Qt 6.5.2 (see https://bugreports.qt.io/browse/QTBUG-106683 )
Note that Qt 6.5.2 no longer causes the Makefile generator to rebuild the *.o and *.so files unnecessarily, but there are still other inefficiencies: https://bugreports.qt.io/browse/QTBUG-115166
@d_h_mcinnes said in Cmake recompile qml modules even if the qml files did not change.:
I notice that if I build my project from the command line, it rebuilds the .qml files every time. However, if I build from inside qtcreator, it only rebuilds when necessary.
It sounds like Qt Creator uses the Ninja generator but your command line does not.
-
as I understand it, this is normal, qt_add_qml_module adds the qml files to the executable as if they were declared in a qrc file, and still if I understand things right, this step is done at build time.
-
@Mesrine , I had this issue as well. Then, I noticed that if I built the qt example project 'qml-i18n' (on my machine, this is installed at /opt/Qt/Examples/Qt-6.5.2/qml/qml-i18n) the .qml files are not recompiled every time. This example project also uses 'qt_add_qml_module'. I think there must be some difference in the CMakeLists.txt file. If you find out what it is, please let me know!
I notice that if I build my project from the command line, it rebuilds the .qml files every time. However, if I build from inside qtcreator, it only rebuilds when necessary.
-
@Mesrine said in Cmake recompile qml modules even if the qml files did not change.:
Is there a way to stop this behavior?
You have 2 options:
- Use the Ninja generator instead of the Makefile generator (recommended), OR
- Upgrade to Qt 6.5.2 (see https://bugreports.qt.io/browse/QTBUG-106683 )
Note that Qt 6.5.2 no longer causes the Makefile generator to rebuild the *.o and *.so files unnecessarily, but there are still other inefficiencies: https://bugreports.qt.io/browse/QTBUG-115166
@d_h_mcinnes said in Cmake recompile qml modules even if the qml files did not change.:
I notice that if I build my project from the command line, it rebuilds the .qml files every time. However, if I build from inside qtcreator, it only rebuilds when necessary.
It sounds like Qt Creator uses the Ninja generator but your command line does not.
-