How to detect target architecture using CMake?

Viewed 111800

I've done a lot of research and been unable to find an answer to this... how can I reliably find the target architecture I'm compiling for, using CMake? Basically, the equivalent to QMAKE_TARGET.arch in qmake.

Most sources seem to suggest CMAKE_SYSTEM_PROCESSOR, but that's a bad solution because that will always return i386 on OS X for example, no matter whether you're compiling for i386, x86_64, ppc or ppc64.

Similarly, CMAKE_SIZEOF_VOID_P gives the pointer size of the system, not the target.

I understand there is CMAKE_OSX_ARCHITECTURES, but this can be empty if not set, in which case it seems to default to whatever the system is capable of. So how can I find the target architecture information?

And specifically for OS X, how can I differentiate between 32, 64, and Intel Universal?

7 Answers
Related