1、解决方案1
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:
1 contains(QT_ARCH, i386) {
2 message("32-bit")
3 } else {
4 message("64-bit")
5 }
2、解决方案2
貌似也有人用QMAKE_TARGET.arch进行判断,但是可能只适用windows,不适合跨平台。
1 win32 {
2 ## Windows common build here
3 !contains(QMAKE_HOST.arch, x86_64) {
4 message("x86 build")
5 ## Windows x86 (32bit) specific build here
6 } else {
7 message("x86_64 build")
8 ## Windows x64 (64bit) specific build here
9 }
10 }
3、解决方案3
利用自定义的字符变量进行判断。
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:
1 CONFIG(myX64, myX64|myX32) {
2 LIBPATH += C:\Coding\MSSDK60A\Lib\x64
3 } else {
4 LIBPATH += C:\Coding\MSSDK60A\Lib
5 }
and passing that custom config to qmake with
qmake CONFIG+=myX64
you get the wanted result.
4、解决方案4
The following code works on Windows (at least with all the recent MSVC compilers - didn't test MinGW), Mac OS X (clang) and Linux (GCC). Feel free to omit the first clause and refer to QT_ARCH directly if you don't need Qt 4 support.
1 #Firstly,Set TARGET_ARCH variable.
2 greaterThan(QT_MAJOR_VERSION, 4) {
3 TARGET_ARCH=$${QT_ARCH}
4 } else {
5 TARGET_ARCH=$${QMAKE_HOST.arch}
6 }
7 #Secondly, use TARGET_ARCH to check.
8 contains(TARGET_ARCH, x86_64) {
9 ARCHITECTURE = x64
10 } else {
11 ARCHITECTURE = x86
12 }