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

发布于 2024-11-18 22:48:37 字数 397 浏览 5 评论 0原文

我正在建立一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

清风挽心 2024-11-25 22:48:37

在 Linux 下,CMake 会查看编译器标志以确定您是针对 32 位还是 64 位进行编译。您可以通过在运行 cmake 时设置 CMAKE_C_FLAGS 和 CMAKE_CXX_FLAGS 信息来传递该信息:

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

确定 cmake 生成的是 32 位还是 64 位项目的可移植方法,是查询CMAKE_SIZEOF_VOID_P 变量,例如:

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

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()
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文