Jump to content

  • Log In with Google      Sign In   
  • Create Account


[CMAKE] CMAKE_SIZEOF_VOID_P and project


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Alundra   Members   -  Reputation: 827

Like
0Likes
Like

Posted 21 April 2013 - 03:13 PM

Hi,

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 :

project(Test)
if( CMAKE_SIZEOF_VOID_P EQUAL 8 )
  project(Test_x64)
else()
  project(Test_x86)
endif()
 

Is the only way to handle that correctly ?

Thanks


Edited by Alundra, 21 April 2013 - 03:14 PM.


Sponsor:

#2 AllEightUp   Moderators   -  Reputation: 4180

Like
0Likes
Like

Posted 21 April 2013 - 06:06 PM

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:

 

 

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

Note:  

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, 21 April 2013 - 06:12 PM.


#3 AllEightUp   Moderators   -  Reputation: 4180

Like
0Likes
Like

Posted 22 April 2013 - 09:44 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS