36

Is there a "win64" identifier in Qmake project files? Qt Qmake advanced documentation does not mention other than unix / macx / win32.

So far I've tried using:

win32:message("using win32")
win64:message("using win64")
amd64:message("using amd64")

The result is always "using win32".

Must I use a separate project-file for x32 and x64 projects, so they would compile against correct libraries? Is there any other way to identify between 32-bit and 64-bit environments?

Kurt W. Leucht
  • 4,725
  • 8
  • 33
  • 45
Tuminoid
  • 9,445
  • 7
  • 36
  • 51

5 Answers5

37

I do it like this

win32 {

    ## Windows common build here

    !contains(QMAKE_TARGET.arch, x86_64) {
        message("x86 build")

        ## Windows x86 (32bit) specific build here

    } else {
        message("x86_64 build")

        ## Windows x64 (64bit) specific build here

    }
}
Kuba hasn't forgotten Monica
  • 95,931
  • 16
  • 151
  • 313
did
  • 402
  • 4
  • 4
35

Since Qt5 you can use QT_ARCH to detect whether your configuration is 32 or 64. When the target is 32-bit, that returns i386 and in case of a 64-bit target it has the value of x86_64. So it can be used like:

contains(QT_ARCH, i386) {
    message("32-bit")
} else {
    message("64-bit")
}
Nejat
  • 31,784
  • 12
  • 106
  • 138
12

UPDATE: since very recently, Qt has a way of doing this transparently and easily, without manual hassle:

win32-g++:contains(QMAKE_HOST.arch, x86_64):{
    do something
}

Source: the brand new Qt Dev FAQ

rubenvb
  • 74,642
  • 33
  • 187
  • 332
  • Wow, I've been searching this for days. Thanks for your answer. – Violet Giraffe Jul 05 '11 at 09:05
  • 1
    Shouldn't it be QMAKE_TARGET instead of QMAKE_HOST? – Simon Jul 29 '14 at 14:37
  • 1
    @Simon [`QMAKE_TARGET`](http://qt-project.org/doc/qt-5/qmake-variable-reference.html#qmake-target) contains the name of the project target (i.e. the binary file). `qmake` wasn't ever designed to handle cross-compilation where target != host. – rubenvb Jul 29 '14 at 14:40
  • 1
    @rubenvb `qmake` can cross-compile, e.g. for Windows on Linux. Accepted answer uses `QMAKE_TARGET` but it doesn't work for me – Simon Jul 30 '14 at 15:22
  • 1
    @Simon those are patched Qt sources, and mkspecs, that allow that. So no, qmake (unmodified) does not allow cross-compilation. It's a single-qmake-and-Qt-per-target thing. I don't know if Qt5 changed anything for the better. Just follow the link, QMAKE_TARGET is not what you and the OP think it is. At least if I can believe the documentation... – rubenvb Jul 30 '14 at 15:26
2

I've figured out one way to do it.

Qt allows you to pass arbitrary config parameters which you can use to separate the targets.

By having a conditional config in your project file:

CONFIG(myX64, myX64|myX32) {
    LIBPATH += C:\Coding\MSSDK60A\Lib\x64
} else {
    LIBPATH += C:\Coding\MSSDK60A\Lib
}

and passing that custom config to qmake with

qmake CONFIG+=myX64

you get the wanted result.

rubenvb
  • 74,642
  • 33
  • 187
  • 332
Tuminoid
  • 9,445
  • 7
  • 36
  • 51
  • Of course you can use different .pro files that include the common parts too, but personally I find that a pain in the... – Tuminoid Jan 03 '09 at 17:05
0

No, but you can create and use a new mkspec, I think qmake also defines a platform identifier named after the current mkspec. Why do you need to test for 64 bit?

Reed

Reed Hedges
  • 1,590
  • 2
  • 15
  • 17
  • I want to use Win32 API in Qt and I must link against libraries from Windows SDK. Obviously those libraries are in different directories, and thus I need to include different files using LIBS. Maybe I'm doing it all wrong? Is there a better way to do it? – Tuminoid Dec 11 '08 at 06:10
  • Specifically in Qt Open Source Edition, not commercial Qt with VS integration, but from the command line and via qmake project files. – Tuminoid Dec 11 '08 at 06:12