[Interest] creating QML module in a subdirectory of backing target

Stefan Seefeld stefan at seefeld.name
Wed Aug 14 16:51:55 CEST 2024


Thanks James,

I'm not sure your suggestion works for me. But to even consider hacking
around a limitation, I need to understand the limitation. Hence I'm asking:
is something wrong in the way I approach this ? Is my code layout not
supported ? I couldn't find any documentation related to this...

Thanks,

On Wed, Aug 14, 2024 at 9:43 AM James DeLisle <james.delisle at qt.io> wrote:

> Hi Stefan,
>
>
>
> Here’s what works for me in Qt 6.5+:
>
>
>
> In A/CMakeLists.txt:
>
>
>
>                 add_subdirectory(qml)
>
>
>
> In A/qml/CMakeLists.txt:
>
>
>
>                 qt_add_library(qml STATIC)
>
>                 qt_add_qml_module(qml
>
>                                 URI qml
>
>                                 QML_FILES
>
>>
>                 )
>
>                 target_link_libraries(qml
>
>                                 PRIVATE
>
>                                 Qt6::Quick
>
>                 )
>
>                 target_link_libraries(${CMAKE_PROJECT_NAME}
>
>                                 PRIVATE
>
>                                 qmlplugin
>
>                 )
>
>
>
> Instead of using add_library from the top-level CMakeLists.txt file, add
> the subdirectory. In the subdirectory’s CMakeLists.txt file, add a static
> library, add the qml module, then link the static library’s plugin to the
> application binary. Hence, the last bit of linking to ‘qmlplugin’. The
> tooling generates this in the build directory and it contains the necessary
> code to register the QML types and load the static library.
>
>
>
> Hope that helps,
>
> James
>
>
>
> *From: *Interest <interest-bounces at qt-project.org> on behalf of Stefan
> Seefeld <stefan at seefeld.name>
> *Date: *Wednesday, August 14, 2024 at 08:29
> *To: *interestqt-project.org <interest at qt-project.org>
> *Subject: *[Interest] creating QML module in a subdirectory of backing
> target
>
> hello,
>
>
>
> in a large CMake / Qt project of mine, I'm building a (shared) library in
> some directory `A`.
>
> Now I want to add a QML module for that, but due to various constraints
> want to do that in a subdirectory `A/qml`.
>
> That is, I have
>
>
>
> *A/*
>
> ├── CMakeLists.txt
>
> ├── qml
>
> │   ├── CMakeLists.txt
>
>
>
> where `A/CMakeLists.txt` calls `addLibrary(A ...)`, and
> `A/qml/CMakeLists.txt` calls `qt_add_qml_module(A ...)`
>
>
>
> This eventually bails with the error
>
>
>
> ```
>
> ... No rule to make target '.../A/A_qmltyperegistrations.cpp`, needed by
> 'CMakeFiles/A.dir/a_qmltyperegistrations.cpp.o'
>
> ```
>
> If I merge the definition of `qml_add_qml_module` in the outer
> CMakeLists.txt file, everything is compiling fine.
>
> Am I missing something ? Is this is known limitation of the build logic ?
>
>
>
> Thanks for any hints,
>
>
> --
>
> [image: Image removed by sender.]
>
>       ...ich hab' noch einen Koffer in Berlin...
>
>

-- 

      ...ich hab' noch einen Koffer in Berlin...
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20240814/0ff3939e/attachment.htm>


More information about the Interest mailing list