Edit: With make there is also an error message, which might be more helpful?
CMake Error: The inter-target dependency graph contains the following strongly connected component (cycle):
"BeansClient_autogen" of type UTILITY
depends on "BeansClient_tooling" (strong)
"BeansClient_automoc_json_extraction" of type UTILITY
depends on "BeansClient_autogen" (strong)
"BeansClient_tooling" of type INTERFACE_LIBRARY
depends on "BeansClient_automoc_json_extraction" (strong)
At least one of these targets is not a STATIC_LIBRARY. Cyclic dependencies are allowed only among static libraries.
CMake Generate step failed. Build files cannot be regenerated correctly.
It’s not entirely clear how exactly your project setup looks like.
Maybe you could post a small example that exhibits the issue.
But your issue seems similar to Loading...
Quote from the comments:
You should keep the QML files in the same directory as the CMakeLists.txt that declares the module. Otherwise you’re in for a world of pain.
Here is a small sample project. Currently it doesn’t work. If you remove in src/CMakeLists.txt the add_subdirectory and use the qml module command there, it should work.
So I see two potential issues:
I don’t have the qml files in the same directory => World of pain? (Note: I also don’t have them in the same directory with the working solution)
So the comments there state that you should always put the qml files in the same directory for reasons.
Question 1: Why doesn’t the docs mention it?
Question 2: Why is there no explicit warning about this
Question 3: Most importantly: How should this work in any real project? This is crazy!! Putting everything in one folder, what a mess. And the only solution is to declare a new module for each subfolder? This makes QML a lot harder to use and in the end will lead to projects where having it dumped into one folder and a huge mess. I think this is inacceptable. Just imagine the requirement would be for the whole C++ project. Please don’t use subfolders
Thanks for the example. It’s indeed QTBUG-99768 you’re hitting.
Question 1: Why doesn’t the docs mention it?
They mention it implicitly by having the executable target and the qt_add_qml_module call in the same directory scope in every example.
It could be made clearer like suggested by Nils in QTBUG-99768.
Question 2: Why is there no explicit warning about this
This can be done. Ideally, we’d find a way to lift the restriction.
Question 3: Most importantly: How should this work in any real project?
You don’t have to “put everything into one folder”.
The restriction is that you have to put your add_executable and qt_add_qml_module calls into the same CMakeLists.txt (or at least the same CMake directory scope).
I’m a little bit confused right now what the issue really is about. Because the quote part:
"You should keep the QML files in the same directory as the CMakeLists.txt that declares the module. "
Sounds like the qml files, i.e. main.qml, button.qml, *.qml should all be in the same directory as the CMakeLists.txt or “I’m in a world of pain”.
This means
- myfolder
- CMakeLists.txt
- main.qml <- Same folder
- button.qml <- Same folder
- subfolder
- subfolderComponent.qml <- Not the same folder!
But the issue / you are also talking about qt_add_qml_module and add_executable should only be in the same scope. And the rest (-> The qml files themself) can be anywhere.
Did I just misunderstood the quote or are these two separate statements / problems?
And what would be the way forward? From what I can see the linked Issue QTBUG-99768 is not a bug, but a feature request, which is mainly motivated by the bug (as it turned out in the comments). So in general, this should probably be converted into a bug, because bugs have higher priority than feature requests for obvious reasons. And I think this bug is quite bad. (Ideally the restriction would be completly fixed, but the bad part is that it’s right now very easy to do wrong).
Is this even a Qt Bug or a CMake Bug?
That the terms folder/subdirectory/directory scope are used in different context doesn’t make things clearer I have to admit.
add_subdirectory introduces a new directory scope, and that causes the problem you’re facing. You can work around the issue by avoiding add_subdirectory for your qt_add_qml_module call. You can do that by either putting qt_add_qml_module back into your CMakeLists.txt that calls add_executable or by including a .cmake file that calls qt_add_qml_module.
Creating a follow-up bug report at bugreports.qt.io would be appropriate.
One thing I wonder as well is: Would it be useful to have additional commands like target_sources for qml modules?
With my regular C++ files I usually define a target in the top level source folder and then do add_subdirectory and target sources to collect the files.
I think it would be cool to do the same with qml files (and also C++ files, other ressources in a qml module)