[CMake] Determine 32 vs 64 bit cpu

Michael Wild themiwi at gmail.com
Thu Dec 22 07:05:40 EST 2011


On 12/22/2011 12:23 PM, pellegrini wrote:
> Hi all,
> 
> I have a program that uses an external library whose path name depends
> on its version (32 or 64 bit).
> 
> Is there a direct way in cmake to test whether my cpu is 32 or 64 bit ?

You don't actually care about the CPU, but the operating system (you can
install a 32-bit OS on a 64-bit machine)

> 
> The one I found up to now is the following:
> 
> if(CMAKE_SIZEOF_VOID_P EQUAL 8)
>    set(arch_64 TRUE)
> else()
>     set(arch_64 FALSE)
> endif()

Yes, that's the way to go. However, remember that on Mac OS X this is
almost always the wrong thing to do when you're building universal
binaries. So, if your software is supposed to work on Mac, you will need
to take special precautions.

> 
> thanks a lot and merry Christmas !

Same to you too!

> 
> Eric
> 
> 

Michael


More information about the CMake mailing list