Qt project file: Add libs depending on Kit

cross-compiling, qt, qt-creator

Solution

I scraped together a solution to the OP's problem by using the answer suggested by @vsz in the comments found here.

I have two kits, one for the local Desktop and one for the Target_ARM device, and I wanted a way to easily build for both of those without having to specially modify the `.pro` file or anything else. I followed the linked answer and added the following:

- In my Desktop kit (for both Debug and Release), I added `CONFIG+=Desktop` as an additional `qmake` argument in the `qmake` build step.

- For the Target_ARM kit, I added `CONFIG+=Target_ARM` in the same spot.

Now, this is where things shifted from the linked answer to the OP's problem. I didn't simply want `#define`ed variables in my code, I wanted to alter the behavior of `qmake` based on the selected kit. I don't know if the `CONFIG` built-in test function supports block designations or not (ie, `CONFIG { _several lines here_ }`), but it turned out I could copy and paste the `CONFIG` test function in front of each line that I wanted to be conditional; in fact I could string multiple `CONFIG`s together, like this:

CONFIG(Desktop, Desktop|Target_ARM):unix:!macx:CONFIG(debug, debug|release): LIBS += /path/to/Desktop/debug/lib
else:CONFIG(Desktop, Desktop|Target_ARM):unix:!macx:CONFIG(release, debug|release): LIBS += /path/to/Destop/release/lib

As it suggests, the above statement will run `qmake` with the appropriate `LIBS` path depending on which kit and configuration I have selected. `Desktop->debug` will generate a Makefile with `/path/to/Desktop/debug/lib` in it whereas `Desktop->release` will generate a Makefile with `/path/to/Desktop/release/lib`. I have similar statements for the `Target_ARM` kit. Below is an example of selecting the correct `INCLUDEPATH`: Both tests will evaluate to true when `Target_ARM->release` is selected.

CONFIG(Target_ARM, Desktop|Target_ARM):CONFIG(release, debug|release): INCLUDEPATH += /include/path/for/Target_ARM/release

In all, I used this method to modify `LIBS, INCLUDEPATH, DEPENDPATH, and PRE_TARGETDEPS`. I have 4 possible configurations of include paths and libraries depending on which kit I select (`Desktop` or `Target_ARM`) and which build configuration I select (`build` or `release`). Once this is set up, there is no need to modify the `.pro` file, simply pick your kit, your build configuration, run `qmake`, then rebuild.

I don't know off the top of my head where the `CONFIG+=Desktop` (for example) data is stored, but I would guess in the `.pro.user` file. So if somebody pulls your `.pro` file from a repo, they may have to initially configure the project in this manner at least once, but not afterwards (as long as the `.pro.user` file persists). QT should really have an easy mechanism for doing this front-and-center, especially since one of their selling points is multiple-platform integration. If there's a better way of doing this, I haven't seen it on SO or in the QT documentation yet.

Problem

I have a QT project which runs on x86 linux and ARM linux embedded (yocto). For each platform I defined a Kit within QtCreator referencing the appropriate compiler etc. Now I want to add LIBS to my pro file, but I got different libraries on each platform. I didn't find a way to specify the LIBS-directive dependant on the compiling Kit. I search something like: ``` if (Kit == "Desktop") LIBS += ... if (Kit == "Embedded Yocto") LIBS += ... ``` How to achieve this? Thank you in advance

Original source

Related problems