问题描述
我想学习CMake的,但由于缺乏像样的教程是使它困难(虽然这是可能的,我不看够硬)。我想知道我怎么能写一个CMake的设置,允许编译使用任何编译器和操作系统的x86和x64体系结构,但我似乎无法找到任何教程关于它的信息。
I'm trying to learn CMake, but the lack of decent tutorials is making it difficult (although it's possible I'm not looking hard enough). I want to know how I could write a CMake setup which allows compilation for both x86 and x64 architectures using any compiler and OS, but I cannot seem to find information on it in any tutorials.
推荐答案
这将CMake的,如果有一个32位/ 64位的选项开箱很大。它没有,所以你需要应用不同的编译器或发电机dependend方法之一。例如:
It would be great if CMake had an 32/64bit option out of the box. It does not, so you will need to apply one of different compiler or generator dependend methods. E.g.:
-
GCC(在Linux上)和其他一些编译器,如太阳录音室。设置
CFLAGS
和CXXFLAGS
包括-m32
(32位位版本)或-m64
(64位版本)。
GCC (on Linux) and some other compilers, e.g. Sun Studio. Set
CFLAGS
andCXXFLAGS
to include-m32
(32-bit build) or-m64
(64-bit build).
Windows中,Visual Studio的生成。使用64位发生器,例如
Windows, Visual Studio generator. Use 64 bit generator, e.g.
的CMake -G的Visual Studio 10 Win64的路径\\为\\源\\目录
编译64位(x64)。省略Win64的发电机名称,搭建32位
to compile 64-bit (x64). Omit "Win64" in generator name, to build for 32 bit
Mac OS X中使用 CMAKE_OSX_ARCHITECTURES
CMake的变量。
Mac OS X. Use CMAKE_OSX_ARCHITECTURES
CMake variable.
cmake的-DCMAKE_OSX_ARCHITECTURES = 386 /路径/要/来源/ DIR
将汇编的32位版本。
cmake -DCMAKE_OSX_ARCHITECTURES=i386 /path/to/source/dir
will compile 32 bit build
cmake的-DCMAKE_OSX_ARCHITECTURES = x86_64的/路径/要/来源/ DIR
编译64位。
cmake -DCMAKE_OSX_ARCHITECTURES=x86_64 /path/to/source/dir
will compile 64 bit.
cmake的-DCMAKE_OSX_ARCHITECTURES = x86_64的; I386/路径/要/来源/ DIR
将创造96位通用二进制代码:)
cmake "-DCMAKE_OSX_ARCHITECTURES=x86_64;i386" /path/to/source/dir
will create 96-bit universal binaries :)
以上是稍微改写。
http://dev.mysql.com/doc/internals/en/compiling-for-different-hardware-achitectures.html
这篇关于CMake的Multiarchitecture编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!