Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt-project as a git-submodule for another Qt-project

Tags:

qt

qmake

I have a Qt-application. It has a .pro file with TEMPLATE = app. One of the project's subfolders is a git-submodule to another Qt project: a collection of libraries, which has it's own .pro file with TEMPLATE = subdirs.

Graphically it looks like:

project/
    app.pro (TEMPLATE = app)
    stuff/
    libs/ <-- git-submodule
        libs.pro (TEMPLATE = subdirs)
        lib1/
            lib1.pro (TEMPLATE = lib)
        lib2/
            lib2.pro (TEMPLATE = lib)

libs as a standalone project compiles well and produces .lib files. But in this case I want somehow include libs.pro to a project as a subdir although app.pro's TEMPLATE is not subdirs but app. Maybe that is why my attempts to write something like SUBDIRS += askelib to app.pro had no effect. All in all my aim is to get .lib files inside build folder of app.pro. I emphasize that libs is a git-submodule because nothing should be changed inside libs project to achieve my goal.

I know that it probably should work if I change app.pro's TEMPLATE to subdirs. But that's not what I really want to do because it will make things more difficult since project hierarchy then will achieve another nesting level:

subdirs_proj/
    app/
    libs/

instead of

app/
    libs/

EDIT: To clerify my reasons:

My aim is to make a project tree as clearer as it can be. Like you clone a project from github, enter into it's directory and see app.pro at the top level. And everything is clear, easy and beautiful. And not like you see a strange subdirs.pro at the top but the actual project is in app subdirectory and you also have posibility to confuse main application subfolder with a library subfolder in case if their names are not so obvious as app and libs but something like torpedo and helios. Hope my thought is clear :)

like image 426
Nikolai Shalakin Avatar asked Jan 29 '23 05:01

Nikolai Shalakin


1 Answers

You already have your answer: make the top-level project a subdir project.

I do not understand why you want to avoid that and why you find it confusing. IMHO, having an app project that has subdirs is more confusing than having a subdir project that has subdirs.

And I don't think removing a folder level compensate for having subdirs in an app .pro. Think about a new developer coming on the project, if he sees TEMPLATE=app he will assume you only build a single project, but it is not. Meaning that your project is not "clear, easy and beautiful" and completely violates the principle of least astonishment.

I regularly have projects that have the following architecture:

project-a/project-a.pro (subdirs)
         /cli-app/cli-app.pro (app)
         /gui-app/gui-app.pro (app)
         /core-lib/core-lib.pro (lib)
         /3rd-party/3rd-party.pro (subdirs)
         /3rd-party/somelib/somelib.pro (lib)

I find it clearer than messing with the project type to remove a folder level. And if you are afraid developers will not know what each sub folder is, maybe you should throw some README files explaining what is what.

Also you can take a look at the Qt project itself, it has many .pro files and not once you have an app project that contains subdirs. And I think it is rather clear, in particular for such a big project.

like image 65
Benjamin T Avatar answered Jan 31 '23 19:01

Benjamin T