[CMake] Correct way to build for 64 bit?

Bill Hoffman bill.hoffman at kitware.com
Fri Feb 2 09:32:54 EST 2007


Moreland, Kenneth wrote:
> Are there any plans for a more cross-platform mechanism for building a
> 64bit build?  Perhaps there could be an option for ADD_LIBRARY and
> ADD_EXECUTABLE that told CMake whether to build for 32 bit or 64 bit.
>
> I'm thinking of something equivalent to the STATIC/SHARED flags on
> ADD_LIBRARY.  I honestly believe that CMake usage would be far lower if
> CMake did not handle all of the platform idiosyncrasies of building
> shared libraries.  As 64-bit machines become more common (as they
> undoubtedly will), I predict switching between 32- or 64-bit builds will
> become just as important.
>   
I am not sure 64/32 is as high a level distinction as the difference 
between shard and static.  From my
experience with 64 bit it usually works in one of these ways:

1. The whole platform is 64 bit, you can not build 32 bit.
2. You can build 32 or 64 bit applications.  
    - you can not mix 32 and 64 bit in a single applications, 32 bit 
libs can not be linked to a 64 bit app.
       Ways of picking which one:
            - Picking 32 bit or 64 bit is a matter of a flag to the 
compiler and linker. 
            - Picking 32/64 is picked via the PATH because there are 
separate tools chains that are used
              to build each.

Currently cmake does do a few things to help with 64 bit.

1. It checks via a try-run the size of void*, if it is found to be 64 
bit then the search paths in the FIND_* are
modified to have lib64 and some other stuff first.  This will detect if 
the compiler and flags specified to
cmake are a 64 bit compiler.

2. For the windows cl, a try compile is done to figure out which cl you 
are using.  For the IDE,
there is a separate generator for the 64 bit tool because you have to 
use a different tool.  So,
you either run vcvars64.bat then cmake for nmake, or you pick the 64 bit 
IDE build.

So, in most cases it would not be OK to mix 64 and 32 bit libs in the 
same tree.  However, it would
not be a bad idea to abstract out the picking of 64 bit when possible.  
This would only be possible with
compilers that change from 32 to 64 with a flag.   Currently, that would 
be IRIX, OSX, and some linux systems.
It would not be possible on pure 64 bit systems, or on separate tool 
chain systems.  

So, the question is how to make this easiest for the user?  It does not 
seem like the choice
should be in the cmakelists.txt files.   It seems more like a command 
line option to cmake.

cmake --build-64bit
cmake -DBUILD64BIT

If a 64 bit build was not possible with the current PATH/env an error 
could be raised.

I suppose it could work like the global BUILD_SHARED flag.  But I don't 
think it would be feasible to
do this on a per library basis because of the tool chain PATH versions 
of 64 bit selection.

-Bill




More information about the CMake mailing list