[CMake] [Insight-developers] 64 bit build detection

Michael Wild themiwi at gmail.com
Mon Jun 15 00:50:27 EDT 2009


On 15. Jun, 2009, at 0:15, Hendrik Sattler wrote:

> 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
>

True, I can only think of some very low-level stuff where one might  
need this kind of knowledge. In all other cases it probably indicates  
bad code or design. But then, sometimes one has to deal with a code  
somebody else has written...

Michael


More information about the CMake mailing list