开发者

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

I'm setting up a C++ project which will be built for 32-bit and 64-bit versions of Windows and Ubuntu. I'm using CMake 2.8.4 and, after having played with it for a few hours, got the VS2010 32-bit and 64-bit projects set up. The problem I ran into is that the generator for Eclipse on the Ubuntu side (technically for Eclipse generators on all platforms), doesn't have separate versions for 32-bit/64-bit.

I realize that there's a GCC compiler switch to indicate开发者_高级运维 which bit type you want (-m32, -m64) and I don't mind having separate solutions, but when I'm running cmake in the build directories, how do I tell it which one I want? If there is no built-in way, is it possible to pass a custom variable/value, like BITTYPE=64, to the cmake command? That way I could handle the rest in the CMakeLists.txt file with a simple if/else.


Under Linux CMake looks at the compiler flags to determine if you are compiling for 32-bit or 64-bit. You can pass that information by setting the CMAKE_C_FLAGS and CMAKE_CXX_FLAGS information upon running cmake:

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

The portable way to determine if cmake is generating a 32-bit or 64-bit project then, is to query the CMAKE_SIZEOF_VOID_P variable, e.g.:

if (CMAKE_SIZEOF_VOID_P EQUAL 8)
   # 64-bit project
else()
   # 32-bit project
endif()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜