[CMake] How can I know the target is 32-bit, or 64bit
Michael Wild
themiwi at gmail.com
Tue Aug 30 02:40:08 EDT 2011
On Tue 30 Aug 2011 07:54:45 AM CEST, Dongsheng Song wrote:
> Hi,
>
> In CMakeLists.txt, I want to know whether cmake has built-in mechanism that
> I can know the target is 32-bit, or 64bit ?
>
> Thanks,
> Dongsheng
Look at the CMAKE_SIZEOF_VOID_P variable. However, normally this is
better handled in the code through #ifdef's, because on some platforms
(e.g. Mac) it is possible to compile for multiple architecture at once
with a single compiler invocation. I.e., something like
gcc -arch i386 -arch ppc -arch x86_64 -arch ppc64 hello.c
will compile hello.c *four* times, first with __i386__ defined, then
with __ppc__, followed by __x86_64__ and finally with __ppc64__. If you
ever plan to support Mac OS X and allow your users to set the
CMAKE_OSX_ARCHITECTURES variable to a list of architectures with
varying bit-sex and pointer sizes, you should *not* rely on
CMAKE_SIZEOF_VOID_P, since that will only contain the pointer size of
the *first* architecture.
HTH
Michael
More information about the CMake
mailing list