Search code examples
qtqbs

Migrating from qmake to qbs, Analogs for .pri file and install technics


Qbs very easy and cool stuff. But, please, help me understand some qbs technics.

1) Imagine I have dir with some sources. With qmake I could create "include.pri" file in that dir with content:

INCLUDEPATH += $$PWD
DEPENDPATH += $$PWD

HEADERS +=  $$PWD/my_file.h
SOURCES +=  $$PWD/my_file.cpp

and then include it (and many others inc fiels) to ANY project just writing

include (some_path/include.pri)

in .pro (.pri) file.

What the analogue will be for qbs?

I know about Module item, but then any dir I want to include I need to put in "modules" dir. That is need for my main project can it see with qbsSearchPaths. And that wrapping every dir with "modules" will be some uncovient.

2) If then I would like to make static library on the base of this sources' dir, with qmake I could install public headers and lib file to some outer directory, available from any other project. But can I do this with qbs? I've came to conclusion that Group.install provides only paths relative to build dir, and does not some abstract (absolute) path. If so, what's the reason for it?


Solution

  • 1) Depending on your concrete requirements, you have two possible solutions here. The first one is to turn the contents of your .pri file into a static library:

    StaticLibrary {
        name: "helper_lib"
        Depends { name: "cpp" }
        files: ["myfile.cpp", "myfile.h"]
        Export {
            Depends { name: "cpp" }
            cpp.includePaths: path
        }
    }
    

    Then add a dependency on this lib wherever you need its functionality:

    CppApplication {
        name: "myapp"
        Depends { name: "helper_lib" }
    }
    

    This is the most sensible approach if the sources would get compiled the same way from everywhere they get pulled in.

    The second way is to inherit from the Group item:

    Group { // top-level item in file mylibgroup.qbs
        prefix: path + "/"
        files: ["mylib.cpp", "mylib.h"]
    }
    

    Use it like this:

    import "mylibgroup.qbs" as MyLibGroup
    CppApplication {
        MyLibGroup { }
    }
    

    But note that in this case, the include paths will have to be set in the importing product, unless they should only apply to the files in the group.

    2) qbs.installDir points inside an "install root", which you can package up, e.g. into a tar.gz archive or whatever. For a direct installation into the local system, you can set the install root to the system's root directory. For instance:

    $ qbs build --no-install qbs.installRoot:/
    $ sudo qbs install