[CMake] 32/64 bit flag

pellegrini pellegrini at ill.fr
Mon Dec 9 08:25:31 EST 2013


On 12/9/2013 1:26 PM, Eric Noulard wrote:
> 2013/12/9 pellegrini <pellegrini at ill.fr>:
>> Dear CMakers,
>>
>> I have to build cmake files for a Fortran project using ifort compiler on
>> Windows, linux and macos platform.
>> That project will be linked to Winteracter Fortran library whose
>> installation paths are different depending on the 32
>> or 64 bit versions. Is there a way to automatically detect whether the build
>> is a 32 bit or 64 bit one in order to define
>> the correct path for Winteracter library ? Up to now, the only way I found
>> to do this was by introducing a cmake
>> option to my build (ON for 64bit build and OFF for a 32 one). I also saw the
>> CMAKE_CL_64 flag that could have been
>> interesting but unfortunately it is only for microsoft.
> Usually you chekc the value of CMAKE_SIZEOF_VOID_P
> which will be 8 on 64 bits system and 4 on 32 bits ones.
>
> e.g. here is what I use:
> # Test 32/64 bits
> if("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
>     message(STATUS "Target is 64 bits")
>     if (WIN32)
>         set(WINXXBITS Win64)
>     endif(WIN32)
> else("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
>     message(STATUS "Target is 32 bits")
>     if (WIN32)
>         set(WINXXBITS Win32)
>     endif(WIN32)
> endif("${CMAKE_SIZEOF_VOID_P}" EQUAL "8")
>
>
> See:
> http://www.cmake.org/pipermail/cmake/2011-February/042752.html
> or
> cmake --help-variable CMAKE_SIZEOF_VOID_P
>> thanks for your help
>>
>> Eric
>> --
>>
>> Powered by www.kitware.com
>>
>> Please keep messages on-topic and check the CMake FAQ at:
>> http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Kitware offers various services to support the CMake community. For more
>> information on each offering, please visit:
>>
>> CMake Support: http://cmake.org/cmake/help/support.html
>> CMake Consulting: http://cmake.org/cmake/help/consulting.html
>> CMake Training Courses: http://cmake.org/cmake/help/training.html
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>
>
Thanks Eric for the hint.
I read some time ago some stuffs about the CMAKE_SIZEOF_VOID_P variable 
but unfortunately, in the present case,
the problem is a bit different. It can be for example that on a 64 bit 
machine, I would like to use the 32 bit
ifort version because the only version of Winteracter library I have is 
the 32 bit one. That's why I came to the point
that the only way to proceed was through a cmake option. I could also 
try to guess the kind of build I would like from
the path of my compiler but this approach seems quite restrictive and 
especially hazardous ...

Eric


More information about the CMake mailing list