在iOS下创建XCode工程

作者: osgChina 发布于2018-10-19 15:36:52 分类 : iOS

准备阶段

Simulator or Device

在iOS下需要选择是使用Simulator还是使用Device,因此在编译之前需要打开CmakeList.txt在源码根目录,找到OSG_BUILD_PLATFORM_IPHONE项会有如下两行:

    OPTION(OSG_BUILD_PLATFORM_IPHONE "Enable IPhoneSDK Device support" OFF)
    OPTION(OSG_BUILD_PLATFORM_IPHONE_SIMULATOR "Enable IPhoneSDK Simulator support" OFF)

选择其中一个,设置为ON,另一个为OFF:

    OPTION(OSG_BUILD_PLATFORM_IPHONE "Enable IPhoneSDK Device support" ON)
    OPTION(OSG_BUILD_PLATFORM_IPHONE_SIMULATOR "Enable IPhoneSDK Simulator support" OFF) 

开始CMake

将"Where is the source" 选择源码目录。将"Where to build the binaries" 选择到 XCode 工程的产生目录。


Platform SDK and Min Version

CMake使用CMAKE_OSX_SYSROOT变量来指向 iOS sdk的位置,OSG会自动检测到该位置:

    /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk

你也可以手工对其进行修改。

也可以通过指定 -miphoneos-version-min选项(在CMAKE_CXX_FLAGS中)来指定SDK的最小版本号,默认是4.0,如果使用的是CMAKE GUI,打开Advance选项才能看到CMAKE_CXX_FLAGS项。 


指定静态编译

iOS 要求OSG必须要静态编译,找到如下项:

    DYNAMIC_OPENSCENEGRAPH = OFF
    DYNAMIC_OPENTHREADS = OFF

GLES1 or GLES2

iOS 同时运动GLES1和GLES2,其中GLES2支持可编程管线,因此建议选择GLES2,下面是不同的选择的设置:

GLES1

    OSG_GL1_AVAILABLE = OFF
    OSG_GL2_AVAILABLE = OFF
    OSG_GL3_AVAILABLE = OFF
    OSG_GLES1_AVAILABLE = ON
    OSG_GLES2_AVAILABLE = OFF
    OSG_GL_LIBRARY_STATIC = OFF 
    OSG_GL_DISPLAYLISTS_AVAILABLE = OFF
    OSG_GL_MATRICES_AVAILABLE = ON
    OSG_GL_VERTEX_FUNCS_AVAILABLE = ON
    OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE = ON
    OSG_GL_FIXED_FUNCTION_AVAILABLE  = ON

GLES2

    OSG_GL1_AVAILABLE  = OFF
    OSG_GL2_AVAILABLE = OFF
    OSG_GL3_AVAILABLE = OFF
    OSG_GLES1_AVAILABLE = OFF
    OSG_GLES2_AVAILABLE = ON
    OSG_GL_LIBRARY_STATIC = OFF
    OSG_GL_DISPLAYLISTS_AVAILABLE = OFF
    OSG_GL_MATRICES_AVAILABLE = OFF
    OSG_GL_VERTEX_FUNCS_AVAILABLE = OFF
    OSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE = OFF
    OSG_GL_FIXED_FUNCTION_AVAILABLE = OFF


插件

插件至少需要选择 freetype 插件,用来读取 ttf字体。右侧为FreeType插件地址:https://github.com/stmh/osg/tree/iphone/IPhone_Project/3rdParty


Applications and Examples

对Applications和Exameple进行设置 ,applications是诸如osgviewer, osgconv, osgversion等,Examples是例子程序。

    BUILD_OSG_APPLICATIONS=OFF
    BUILD_OSG_EXAMPLES=OFF

如果上述打开,则可能生成错误,到时候自己改吧。对OSG贡献代码的人并不怎么考虑iOS。


编译

点击 'Generate' 生成工程,然后编译 BUILD_ALL。