I have settings in my program that depend on the bit-width of the target of my compilation. In case the width is 32-bit, some special macro has to be defined due to memory constraints.
I could not find any way in qmake to detect the bit-width of the target, while the same option is available in cmake with: CMAKE_SIZEOF_VOID_P
; where 8 is 64-bit and 4 is 32-bit.
Is there something similar for qmake?
EDIT: Background on the problem as requested in the comments
Part 1: There's a C library that I'm using in my C++11 program that needs a macro to act differently on 32-bit systems.
Part 2: In 32-bit systems, the memory is limited to 4 GB of virtual memory. Even if you're running a 64-bit system and machine, and even if you have 500 GB of swap memory, a 32-bit program cannot use more than 4 GB. That's why, the library I'm using has special settings for 32-bit as to limit the amount of memory it uses. Hence, I need to know whether we're compiling for a 32-bit target (e.g., Raspberry Pi), to activate a required macro.
Part 3: The library is built as a custom target in qmake before building my software. Once the library is built, my software is built and is linked to that library.
I ended up using this solution. First I added this to support linux:
linux-g++:QMAKE_TARGET.arch = $$QMAKE_HOST.arch
linux-g++-32:QMAKE_TARGET.arch = x86
linux-g++-64:QMAKE_TARGET.arch = x86_64
and then this:
contains(QMAKE_TARGET.arch, x86_64) {
message("Compiling for a 64-bit system")
} else {
DEFINES += ABC
message("Compiling for a 32-bit system")
}
Learned this from here.