[CMake] [Insight-developers] 64 bit build detection
Hendrik Sattler
post at hendrik-sattler.de
Sun Jun 14 18:15:39 EDT 2009
Am Sonntag 14 Juni 2009 22:05:14 schrieb Michael Wild:
> On Mac OS X one shouldn't do this kind of detection during configure
> step, because as has been mentioned a single file can be compiled
> multiple times for different architectures during one single compiler
> invocation. The size of void* and even endianness can change. It is
> preferable to have a central config.h.in (or similar) containing
> something like this:
>
> #if defined(__APPLE__)
> # if defined(__i386__)
> # undef HAVE_64_BIT
> # undef HAVE_BIG_ENDIAN
> # elif defined(__ppc__)
> # undef HAVE_64_BIT
> # define HAVE_BIG_ENDIAN
> # elif defined(__x86_64__)
> # define HAVE_64_BIT
> # undef HAVE_BIG_ENDIAN
> # elif defined(__ppc64__)
> # define HAVE_64_BIT
> # define HAVE_BIG_ENDIAN
> # else
> // oops
> # error "Unknown architecture!"
> # endif
> #else
> # cmakedefine HAVE_64_BIT
> # cmakedefine HAVE_BIG_ENDIAN
> #endif
Where do you need to know that you have 32bit vs. 64bit?
When including inttypes.h, you can use e.g. uint64_t portably (you can find
inttypes.h for MSVC on googlecode), else use you can even use:
if (sizeof(void*) == 8) {
...
} else {
...
}
and let the compiler optimize one of them away. Or do something else with C
preprocessor.
Not _everything_ has to be done with CMake.
HS
More information about the CMake
mailing list