Sign in to follow this  


Recommended Posts


I'm using cmake to generate my project and I have recently learned the existence of "CMAKE_SIZEOF_VOID_P".

Is "CMAKE_SIZEOF_VOID_P" a portable solution ?

To generate project name for x86 and x64 I need to use this trick :


Is the only way to handle that correctly ?


Edited by Alundra

Share this post

Link to post
Share on other sites

It is only partially portable.  For Visual Studio it is fine since CMake only outputs 32 or 64 bit specific solutions.  Unfortunately though, since it is a project generation time test it won't work on items which allow switching between 32 and 64 bits on the fly, for instance Xcode automatically inserts both targets.  As such, you need to really use a compile time test.  A version I've been using which seems to be pretty consistent is:



#include <stdint.h>
#if UINTPTR_MAX == 0xffffffff
# define BUILDING_32BIT
#elif UINTPTR_MAX == 0xffffffffffffffff
# define BUILDING_64BIT
# error Unknown architecture.


Obviously this only works on compilers with stdint, VC2010-2012 have it, 2008 didn't and you have to deal with it using specific compiler tricks.


Edited by AllEightUp

Share this post

Link to post
Share on other sites

Somehow I overlooked that you were just trying to change the name.  The basic reasoning against using the flag to control output is still true; it is done at generation time and doesn't translate to the build environments which deal with multiple targets automatically.

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this