Qt Project File: Add Libraries Based on Set

I have a QT project that runs on linux x86 and built in to ARM linux (yocto). For each platform, I defined a set in QtCreator, referring to the corresponding compiler, etc.

Now I want to add LIBS to my pro file, but on each platform I got different libraries. I did not find a way to specify the LIBS directive, depending on the compilation set.

I am looking for something like:

if (Kit == "Desktop") LIBS += ... if (Kit == "Embedded Yocto") LIBS += ... 

How to achieve this? Thank you in advance

+8
qt cross-compiling qt-creator
source share
3 answers

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

I have two sets: one for the local desktop and one for the Target_ARM device, and I would like to easily create both of them without any special modification to the .pro file or anything else. I followed the related answer and added the following:

  • In my desktop set (for both Debug and Release), I added CONFIG+=Desktop as an additional qmake argument during the qmake build phase.
  • For the Target_ARM set, I added CONFIG+=Target_ARM in the same place.

Now that things have moved from a related answer to an OP problem. I didn’t just want the #define ed variables in my code, I wanted to change the qmake behavior based on the selected set. I don’t know if the built-in CONFIG test function supports block assignment or not (ie CONFIG { _several lines here_ } ), but it turned out that I can copy and paste the CONFIG test function before each line so that I want to be conditional; in fact, I could combine several CONFIG , 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 expected, the above statement will run qmake using the appropriate LIBS path, depending on the selected set and configuration. Desktop->debug will generate a Makefile with /path/to/Desktop/debug/lib , while Desktop->release will generate a Makefile with /path/to/Desktop/release/lib . I have similar statements for the Target_ARM set. The following is an example of choosing the correct INCLUDEPATH : both tests will evaluate to true if Target_ARM->release selected.

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

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

I don’t know from the top of my head where CONFIG+=Desktop data is stored (for example), but I would assume in the .pro.user file. Therefore, if someone pulls your .pro file out of the repo, they may have to first set up the project this way at least once, but not after (while the .pro.user file .pro.user saved). QT really should have a simple mechanism for this front-and-center, especially since one of their outlets is multi-platform integration. If there is a better way to do this, I have not seen it on SO or in the QT documentation yet.

+3
source share

Here are all the qmake variables: qt-project.org/doc/qt-4.8/qmake-function-reference.html

You can define a variable

 KIT = Desktop #KIT = EmbeddedYocto 

And use the function

 contains( KIT, Desktop ) { LIBS += ... } contains( KIT, EmbeddedYocto ) { LIBS += ... } 
+1
source share
 MY_QT_INSTALL_PREFIX=$$[QT_INSTALL_PREFIX] equals(MY_QT_INSTALL_PREFIX,"C:/Qt/Qt5.3.1/5.3/msvc2010_opengl"){ message($$[QT_INSTALL_PREFIX]) } 
0
source share

All Articles