使用 CMake 生成 32 位/64 位 Eclipse CDT 项目
我正在建立一个 C++ 项目,该项目将为 32 位和 64 位版本的 Windows 和 Ubuntu 构建。我正在使用 CMake 2.8.4,在使用了几个小时后,设置了 VS2010 32 位和 64 位项目。我遇到的问题是 Ubuntu 端的 Eclipse 生成器(技术上适用于所有平台上的 Eclipse 生成器)没有针对 32 位/64 位的单独版本。
我意识到有一个 GCC 编译器开关来指示您想要哪种位类型(-m32、-m64)并且我不介意有单独的解决方案,但是当我在构建目录中运行 cmake 时,我如何告诉它哪个我想要一个吗?如果没有内置方法,是否可以将自定义变量/值(例如 BITTYPE=64
)传递给 cmake 命令?这样我就可以使用简单的 if/else 处理 CMakeLists.txt 文件中的其余部分。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在 Linux 下,CMake 会查看编译器标志以确定您是针对 32 位还是 64 位进行编译。您可以通过在运行 cmake 时设置 CMAKE_C_FLAGS 和 CMAKE_CXX_FLAGS 信息来传递该信息:
确定 cmake 生成的是 32 位还是 64 位项目的可移植方法,是查询CMAKE_SIZEOF_VOID_P 变量,例如:
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
andCMAKE_CXX_FLAGS
information upon running cmake: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.: