Ubuntu – QML app with C++ plugin (cmake) subdirectory

application-developmentccmakeqmlubuntu-sdk

I am developing an Ubuntu Phone application "QML app with C++ plugin (cmake)" but I have so many qml files so I want to separate them by functionality

ApplicationName

  • CMakeListes.txt
  • ..
  • app
    • CmakeListes.txt
    • ApplicationName.desktop.in
    • tests
    • mainComponents
      • sub directories of mainComponents
        • some files
      • some other files
    • ApplicationName.qml
  • po
    • CMakeListes.txt
  • ApplicationName.apparmor
  • manifest.json.in

but the "mainComponents" folder dose not appear in the project tree and after some searches I found that I must add CMakeListes.txt in every new folder and this:

add_subdirectory(folder_name)

instruction in the parent folder CMakeListes.txt file but I don't if there is more to add and I don't know how to create the CMakeListes.txt

thanks

Best Answer

You just need to learn the CMake language. It is the language of the CMakeListes.txt files that are all over the project.

This language specifies how to build the project. And this language is independent from the QtCreator IDE that we are using. So, you can do builds without QtCreator and create CMakeListes.txt manually where you wish.

Back to the problem:

You can use 'add_subdirectory' and write CMakeListes.txt for each subdirectory and append file names to QML_JS_FILES variable in each CMakeListes.txt.

But you can also do as the guys who develop core application do: for example in ubuntu-terminal-app (source code is on https://launchpad.net), they use a recursive include in app/CMakeListes.txt:

file(GLOB_RECURSE QML_JS_FILES *.qml *.js)

instead of non-recursive:

file(GLOB QML_JS_FILES *.qml *.js)

update: Yes, generally, GLOBs are not recommended, but they are already in the project templates to simulate some kind of 'automatic' behavior.