2
votes

I am writing a QML plugin/module for custom GUI controls for a big project at work. We use CMake for project building. The main structure of the QML module (after compilation) must be like this:

MyModule myplugin.dll control1.qml control2.qml …

The most important thing is that all qml files and the shared library plugin (myplugin.dll in the example) MUST be placed in the directory with EXACTLRY the name of the module (MyModule in the example). As a post build step all qml files are copied into this binary output directory.

And here is the problem: compiled binary files (myplugin.dll in the example) are placed in the directories Debug, Release, and so on, inside the output directory. Because of that the result looks like: MyModule/Debug/myplugin.dll - and module does not work. I’ve tried manipulating RUNTIME_OUTPUT_DIRECTORY_DEBUG, RUNTIME_OUTPUT_DIRECTORY_RELEASE and all that messy zoo, but… it is not an option, because as far as I know build-config types can be custom, so I cannot foresee all possible RUNTIME_OUTPUT_DIRECTORY_ variants and specify them in advance.

Is there any normal way to structure my output directory inside those Debug, Release, ConfigIDontKnowAboutYet? For example, instead of making it like this: MyModule/Debug/myplugin.dll - turning it into this: MyModule/Debug/MyModule/myplugin.dll – because the last part of the path must be exactly .../MyModule/myplugin.dll, otherwise it won’t work. If there is no such way, how do people deal with it?

Another important thing is that this module is supposed to be used by a bigger project by add_subdirectory(). And here all that DebugRelease - MyOwnConfig mess makes it all even much harder.

The only more-or-less solution found so far was to install() resulting compiled and qml files of MyModule into binary output directory of the bigger project that contains MyModule as a dependency. However, there is another problem. It turns out in this case I have to install MyModule twice: one time into binary output directory of the bigger project in order to build / test / run it, and the second time when I install the bigger project itself.

I would very much appreciate any suggestions. Also, if someone has a quite big project that uses CMake, C++ and depends on QML modules I would be really grateful if they provided a link to have a look at it. Thanks.

1

1 Answers

0
votes

CMake offers the possibility of installing files after compilation. The effect is similar to make install commands. With this command, you can choose to install all or only specific products of your build. Below is an example of what I use in my CMakeLists.txt.

# The installation is prepended by the CMAKE_INSTALL_PREFIX variable
install(TARGETS ${CMAKE_PROJECT_NAME}
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
    PUBLIC_HEADER DESTINATION include
)

This will copy your products, depending on their file types. But you still need to set the library/include paths. To do so, I recommend compiling several targets, and using the install destination of the first target as a lib/inc path (most likely append, with something like include_directories or link_directories).

For the QML file handling, there is most likely a way to do the same with very similar syntax. QT gives the developer the choice between CMake and QMake, so they likely have a mechanism to do so.

Also, please keep in mind that the paths to your QML files in your C++ code must reflect the the final project structure.