如何设置CMake为iPhone构建库 [英] How to set up CMake to build a library for the iPhone

查看:201
本文介绍了如何设置CMake为iPhone构建库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想通过手动设置某些属性来使用CMake为iPhone生成Xcode配置。我的CMake文件看起来像:

I'm trying to use CMake to generate an Xcode configuration for the iPhone by manually setting certain attributes. (Is this even the right way to go about this?) My CMake file looks like:

project(MYLIB)
set(LIBRARY_OUTPUT_PATH ${PROJECT_BINARY_DIR}/lib)
set(CMAKE_CONFIGURATION_TYPES Debug Release Debug-iPhone)
set(FILES list of my files...)

add_library(mylib FILES)

set(XCODE_ATTRIBUTE_SDKROOT iphoneos2.2.1)
# more attributes later, I'm just trying to get one to work first

首先,这似乎不工作 - 在生成的Xcode项目(我运行 cmake。-G Xcode ), SDKROOT 仍设置为无,因此显示为当前Mac OS。

First of all, this doesn't seem to work - in the generated Xcode project (I'm running cmake . -G Xcode), SDKROOT is still set to nothing, and so it says "Current Mac OS".

其次,假设这是正确的方法,我如何设置属性只有配置 Debug-iPhone

Second, assuming this is the right way to do this, how do I set the attribute only for the configuration Debug-iPhone?

推荐答案

据我所知,有两种方法。最有可能的,你几乎在那里,是使用 CMAKE_OSX_SYSROOT 来设置XCode SDKROOT。还有变量 CMAKE_OSX_ARCHITECTURES ,它映射到XCode中的ARCHS。

As far as I can tell, there are two ways. The one most likely, you are nearly there, is to use CMAKE_OSX_SYSROOT to set the XCode SDKROOT. There is also the variable CMAKE_OSX_ARCHITECTURES, which maps to ARCHS in XCode.

另一种方法是使用 CMake的交叉编译支持。我没有使用它的iphone,但我已经这样做其他ARM处理器。您需要设置一个看起来像这样的工具链文件:

The alternative is to use CMake's cross compiling support. I've not used it for the iphone, but I have done so for other ARM processors. You need to set up a toolchain file that would look something like this:

set(CMAKE_SYSTEM_NAME Generic)
set(CMAKE_SYSTEM_VERSION 1)
set(CMAKE_SYSTEM_PROCESSOR arm-elf)
set(CMAKE_C_COMPILER /path/to/complier/bin/arm-elf-gcc)
set(CMAKE_FIND_ROOT_PATH /path/to/compiler)
set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER)
set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY)
set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY)


b $ b

然后,当您运行cmake时,将 CMAKE_TOOLCHAIN_FILE 变量设置为您的工具链文件的名称。或者如果你只编译到一个架构,你可以硬编码CMakeLists.txt文件中的值。但我想象你需要交叉编译的iphone模拟器和实际的iphone本身,对吧?因此,您可以运行其中一个,可能有几个版本变体:

And then when you run cmake, set the CMAKE_TOOLCHAIN_FILE variable to the name of your toolchain file. Or if you only compile to one architecture, you can hard-code the value in the CMakeLists.txt file. But I imagine you would need to cross compile for the iphone simulator and for the actual iphone itself, right? So you would run one of these, probably having a couple of build variants:

cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/my/iphone-sim.cmake .
cmake -DCMAKE_TOOLCHAIN_FILE=/path/to/my/iphone-real.cmake .

sim / real文件定义模拟器或真正的iphone编译器工具的环境。

Where the sim/real files define the environment for the simulator or real iphone compiler tools.

可能有帮助的其他一些链接此错误报告此邮寄名单会话

Some other links that may help are this bug report and this mailing list conversation.

这篇关于如何设置CMake为iPhone构建库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆