Creating 32-bit / 64-bit Eclipse CDT projects using CMake

I am creating a C ++ project that will be created for 32-bit and 64-bit versions of Windows and Ubuntu. I am using CMake 2.8.4 and, after playing with him for several hours, I got VS2010 32-bit and 64-bit projects. The problem I ran into is that the generator for Eclipse on the Ubuntu side (technically for Eclipse generators on all platforms) does not have separate versions for 32-bit / 64-bit versions.

I understand that there is a GCC compiler to indicate what type of bit you want (-m32, -m64), and I do not mind having separate solutions, but when I run cmake in the assembly directories, tell me which one I want ? If there is no built-in method, is it possible to pass a custom variable / value, for example BITTYPE=64 , to cmake? That way, I could handle the rest in the CMakeLists.txt file with a simple if / else.

+4
source share
1 answer

On Linux, CMake looks at compiler flags to determine if you are compiling for 32-bit or 64-bit. You can pass this information by setting the information CMAKE_C_FLAGS and CMAKE_CXX_FLAGS when cmake starts:

 cmake -G "Eclipse CDT4 - Unix Makefiles" -DCMAKE_C_FLAGS=-m32 -DCMAKE_CXX_FLAGS=-m32 

A portable way to determine if cmake is generating a 32-bit or 64-bit project is to query the CMAKE_SIZEOF_VOID_P variable, for example:

 if (CMAKE_SIZEOF_VOID_P EQUAL 8) # 64-bit project else() # 32-bit project endif() 
+3
source

All Articles