[CMake] Detecting 32/64 bit systems

Michael Jackson mike.jackson at bluequartz.net
Mon Feb 14 13:55:49 EST 2011


 This will FAIL on windows. MSVC defines "long" as 32 bits on BOTH 32 and 64 bit compiles. Stick with the already defined CMAKE_SIZE_OF_VOID_P instead. It is known to work correctly on all the systems that CMake defines.
  As mentioned earlier, when building for OS X and universal binaries there are some special considerations to examine.
___________________________________________________________
Mike Jackson                      www.bluequartz.net
Principal Software Engineer       mike.jackson at bluequartz.net 
BlueQuartz Software               Dayton, Ohio

On Feb 14, 2011, at 1:39 PM, Yngve Inntjore Levinsen wrote:

> Sorry, I meant LONG actually, I was a bit tired when I wrote the mail. Perhaps I should change to VOID instead, thanks for the tip.
> 
> This was my previous code:
> INCLUDE(CheckTypeSize)
> CHECK_TYPE_SIZE (long LONG_SIZE) #4 if 32bit, 8 if 64bit...
> 
> I don't actually build for Windows yet, so I suppose that is why I didn't notice the potential problem...
> 
> Cheers,
> Yngve
> 
> 
> On Monday 14 February 2011 10:35:26 AM Rolf Eike Beer wrote:
>>> I have done the same thing myself, using size of INT instead of P which is
>>> of course following the exact same logic.
>>> After attempting several strategies I found this one to be the safest way
>>> to detect 32/64bit systems, so I recommend using SIZEOF as well.
>> 
>> sizeof(int) is 4 on basically all systems I have ever seen (ignoring those
>> 16bit machines of 286 areas or things like that) so this test is basically
>> useless. Also testing for sizeof(long) will get you into trouble as this 8
>> for Un*x64 but 4 for Win64. The best way is usually sizeof(void*) even if
>> there are programming model where you would get a 32 bit pointer even in a
>> 64 bit executable but those have to be explicitely enabled and are barely
>> ever used from my experience.
>> 
>> Eike
>> _______________________________________________
>> Powered by www.kitware.com
>> 
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>> 
>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>> 
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>> 
> _______________________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake



More information about the CMake mailing list