简体   繁体   English

使用 CMake 生成 32 位/64 位 Eclipse CDT 项目

[英]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.我正在设置一个 C++ 项目,该项目将为 Windows 和 Ubuntu 的 32 位和 64 位版本构建。 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.我正在使用 CMake 2.8.4,在玩了几个小时后,设置了 VS2010 32 位和 64 位项目。 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.我遇到的问题是 Ubuntu 端的 Eclipse 的生成器(技术上对于 Eclipse 生成器在所有平台上都有单独的版本),没有单独的版本 3-bit/6

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?我意识到有一个 GCC 编译器开关来指示您想要哪种位类型(-m32,-m64),我不介意有单独的解决方案,但是当我在构建目录中运行 cmake 时,我该如何告诉它我想要一个? If there is no built-in way, is it possible to pass a custom variable/value, like BITTYPE=64 , to the cmake command?如果没有内置方法,是否可以将自定义变量/值(如BITTYPE=64 )传递给 cmake 命令? That way I could handle the rest in the CMakeLists.txt file with a simple if/else.这样我就可以使用简单的 if/else 处理 CMakeLists.txt 文件中的 rest。

Under Linux CMake looks at the compiler flags to determine if you are compiling for 32-bit or 64-bit.在 Linux CMake 下查看编译器标志以确定您是为 32 位还是 64 位编译。 You can pass that information by setting the CMAKE_C_FLAGS and CMAKE_CXX_FLAGS information upon running cmake:您可以通过在运行 cmake 时设置CMAKE_C_FLAGSCMAKE_CXX_FLAGS信息来传递该信息:

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, eg:确定 cmake 是否正在生成 32 位或 64 位项目的可移植方法是查询CMAKE_SIZEOF_VOID_P变量,例如:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM