CMake and importing QML files
-
Hi,
I'm trying to figure out a way to have importing work in a more dynamic way than throwing every single .qml file and folder into CMakeLists.txt.
Example project structure:
project/ ├── src/ │ └── main.cpp └── ui/ ├── panels/ │ └── RoundedPanel.qml ├── buttons/ │ ├── Button.qml │ └── RoundedButton.qml └── root.qmlResults in:
import ui.panels RounedPanel { } import ui.buttons Button { } RoundedButton { }The catch here is that if at any point I would create new directory in ui and add new .qml there, it should automatically work (even if after build/reconfiguring CMake).
So far I only came across
qmldir(which didn't even work for me) andqt_add_qml_modulebut that requires manually adding new qml files.Any suggestions?
-
I believe globbing is supported by CMake but that it is generally recommended not to use it. As a CMake newbie myself I have followed what seemed to be the prevailing wisdom and stuck to hard coded lists.
One compromise that I did come across was to read the file list from an external file, e.g.,
file(STRINGS "sources_list.txt" MYSRCS)and then use theMYSRCSvariable as your file list in CMake commands (e.g.,add_executable(my_app ${MYSRCS})). This would mean maintaining the "sources_list.txt" file externally but that would be easy to automate. I haven't actually tried this though so take all this with a pinch of salt.