我希望能够为本地arch(32位或64位)编译我的项目,并且即使在64位主机上也可以编译为32位。添加option
和一堆带有编译标志的if
是唯一的方法吗?还是有更好的方法?我需要支持UNIX makefile和NMake makefile。
答案 0 :(得分:0)
使用工具链文件:这是@malak提供的文件
# the name of the target operating system
set(CMAKE_SYSTEM_NAME Linux)
# which compilers to use for C and C++
set(CMAKE_C_COMPILER gcc)
set(CMAKE_C_FLAGS -m32)
set(CMAKE_CXX_COMPILER g++)
set(CMAKE_CXX_FLAGS -m32)
# here is the target environment located
set(CMAKE_FIND_ROOT_PATH /usr/i486-linux-gnu )
# adjust the default behaviour of the FIND_XXX() commands:
# search headers and libraries in the target environment, search
# programs in the host environment
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)
然后使用就是:
$ cmake -DCMAKE_TOOLCHAIN_FILE=toolchain.cmake /path/to/source
另外,这里有一些直接来自wiki的信息。
http://www.cmake.org/Wiki/CmakeMingw
我对Nmake不熟悉,但这篇文章似乎有一些类似的信息:http://nmake.alcatel-lucent.com/faq/32and64bit.html