PDA

View Full Version : How to determine target architecture in qmake project file?



Infinity
26th December 2013, 23:44
Hi

Does somebody know if it is possible to determine which target architecture is used in the qmake project file?
To clarify: I don't want to determine the architecture of the operating system used when building the application, I need the target architecture of the executables/libraries to be built.
I'm using Qt 5 and GCC (as compiler on Linux) and mingw (as compiler on Windows).

I already read the qmake Variable Reference (http://qt-project.org/doc/qt-5.0/qtdoc/qmake-variable-reference.html) but found nothing useful. The only useful variables I found "have only an effect on Mac OS X".

ChrisW67
27th December 2013, 00:23
What do you mean by target architecture? Unless you are cross compiling the Linux/GCC combination will build for Linux, and Mingw for Windows, in whatever bit-ness your Qt library was built with. You can separate the two in a PRO file with win32 {} and unix {} scopes.

Infinity
27th December 2013, 00:26
By target architecture I mean the CPU architecture (x86, AMD64, ARM, ...), not the operating system (I know the win32/unix scopes).

ChrisW67
27th December 2013, 00:30
What are you trying to achieve in the PRO file that needs to know this?

Infinity
27th December 2013, 00:54
I want to add the right libraries (depending on the target architecture).
If I'm using libraries provided by a Debian package like lcrypto (from OpenSSL) the right library is chosen automatically.
If I want to add one of my own libraries I need to give the (relative) location of the library additionally to its name. Here I need different locations depending on the target architecture. Do you think there is a better way to achieve that the right library is picked automatically (like when using a library provided by a Debian package)?

And thanks for the quick answer :-)

ChrisW67
27th December 2013, 01:47
These libraries of yours are not built as part of the same project with the same settings?
Are you cross compiling?

I think on Windows you can use QMAKE_TARGET.arch to tell "x86" from "x86_64" but that does not exist on Linux.
On Linux something like this might get you there:


linux-g++:QMAKE_TARGET.arch = $$QMAKE_HOST.arch
linux-g++-32:QMAKE_TARGET.arch = x86
linux-g++-64:QMAKE_TARGET.arch = x86_64

Lifted from : http://qt-project.org/faq/answer/how_can_i_detect_in_the_.pro_file_if_i_am_compilin g_for_a_32_bit_or_a_64_bi

Infinity
27th December 2013, 02:07
Are you cross compiling?
No


These libraries of yours are not built as part of the same project with the same settings?
No, these libraries are build separately (using separate project files). But not because I need them to be built separately. I just didn't know that it is possible to build needed projects/libraries together with the project that uses them.
How do I achieve that (that would solve my problem in a more elegant way)? How to tell qmake which header/source files belong to each library? Do I need to add the project files of the libraries to the project that uses them? If that assumption is correct, how do I do that properly?

ChrisW67
27th December 2013, 02:35
You use a subdirs project. For a simple example project.pro:


TEMPLATE = subdirs
SUBDIRS = foo bar app
CONFIG += ordered # makes sure libs foo and bar are built before app

with a source tree like:


- project.pro
+ foo
- foo.pro
- a.cpp
- etc...
+ bar
- bar.pro
- b.cpp
- etc...
+ app
- app.pro
- main.cpp
- mainwindow.cpp
- etc...

The app.pro could reference the libraries:


TEMPLATE = app
TARGET = MyCoolProgram
INCLUDEPATH += ../foo ../bar
LIBS += -L../foo -lfoo
LIBS += -L../bar -lbar
...

and a library PRO would look like:


TEMPLATE = lib
TARGET = foo
SOURCES += ...
HEADERS += ...


Done from memory, check the qmake manual.

Infinity
27th December 2013, 02:47
Thanks for helping. I will try to use a subdirs project tomorrow.