文档参照:Building osgEarth for IOS Generating an IOS XCode Project
Mac OS 10.8.3
XCode 4.6(4H127)
CMake 2.8.12.1
随便安装个能下载代码的就行
OpenSceneGraph3.2.1-rc1 osgearth2.4
项目工程目录:
osgearth-build
-- osg-ios
-- osgearth-ios
-- 3rdparty
ios 3rdparty JavaScriptCore
osgearth ios application,只需要拷贝osgearth/src/applications/osgearth_viewIOS工程即可,其他部分仍使用下载的IOS代码
编译前必须搞定Xcode开发者许可证,否则编译过程报错。
Check /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs // 检查该路径是否存在、SDK版本 Open CMakeList.txt and change line 236 to your SDK version: (SET (IPHONE_SDKVER "5.1" CACHE STRING "IOS SDK-Version") // 设置SDK版本,Xcode4.6默认使用6.1SDK
Use below command line to generate static GLES2 build for iOS devices, change 3rdparty paths to reflect your 3rdparty path cd ./osg-ios cmake ./ -G Xcode -DOSG_BUILD_PLATFORM_IPHONE:BOOL=ON \ -DBUILD_OSG_APPLICATIONS:BOOL=OFF \ -DOSG_WINDOWING_SYSTEM:STRING=IOS \ -DOSG_DEFAULT_IMAGE_PLUGIN_FOR_OSX="imageio" \ -DOSG_GL1_AVAILABLE:BOOL=OFF \ -DOSG_GL2_AVAILABLE:BOOL=OFF \ -DOSG_GLES1_AVAILABLE:BOOL=OFF \ -DOSG_GLES2_AVAILABLE:BOOL=ON \ -DOSG_GL_DISPLAYLISTS_AVAILABLE:BOOL=OFF \ -DOSG_GL_FIXED_FUNCTION_AVAILABLE:BOOL=OFF \ -DOSG_GL_LIBRARY_STATIC:BOOL=OFF \ -DOSG_GL_MATRICES_AVAILABLE:BOOL=OFF \ -DOSG_GL_VERTEX_ARRAY_FUNCS_AVAILABLE:BOOL=OFF \ -DOSG_GL_VERTEX_FUNCS_AVAILABLE:BOOL=OFF \ -DCURL_INCLUDE_DIR:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/curl-ios-device/include" \ -DCURL_LIBRARY:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/curl-ios-device/lib/libcurl.a" \ -DFREETYPE_INCLUDE_DIR_freetype2:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/freetype-ios-universal/include/freetype" \ -DFREETYPE_INCLUDE_DIR_ft2build:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/freetype-ios-universal/include" \ -DFREETYPE_LIBRARY:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/freetype-ios-universal/lib/libFreeType_iphone_universal.a" \ -DTIFF_INCLUDE_DIR:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/tiff-ios-device/include" \ -DTIFF_LIBRARY:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/tiff-ios-device/lib/libtiff.a" \ -DGDAL_INCLUDE_DIR:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/gdal-ios-device/include" \ -DGDAL_LIBRARY:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/gdal-ios-device/lib/libgdal.a" \ -DDYNAMIC_OPENSCENEGRAPH:BOOL=OFF \ -DDYNAMIC_OPENTHREADS:BOOL=OFF
再检查:
CMake uses the CMAKE_OSX_SYSROOT variable to know where the iOS sdk is located. OSG will automatically set this to /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk If you use a different sdk or your sdk is installed in a different location change CMAKE_OSX_SYSROOT to point to the correct location You can also specify a different sdk number as the minimum requirement, this is set via the -miphoneos-version-min option in the CMAKE_CXX_FLAGS, by default this is set to 4.0. If using the CMake GUI you may need to tick 'Advanced' in order to see the CMAKE_CXX_FLAGS setting.确认:CMAKE_OSX_SYSROOT的路径为
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk,Xcode默认路径为MacOS.platform的开发路径,需要修改。(
/Applications/Xcode.app/Contents/Developer/Platforms,目录下有MacOS.platform、iPhoneOS.platform、iPhoneSimulator.platform,配置工程对应的平台)确认:CMAKE_CXX_FLAGS:中是否包含-miphoneos-version-min=4.0,如果包含-mmacos-version-min=10.8,需去除
CMake生成工程
cmake ./ -G Xcode -DOSG_BUILD_PLATFORM_IPHONE:BOOL=ON \ -DOSG_DIR:PATH="/Users/hogbox/Documents/osgearth-build/osg-ios" \ -DCURL_INCLUDE_DIR:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/curl-ios-device/include" \ -DCURL_LIBRARY:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/curl-ios-device/lib/libcurl.a" \ -DGDAL_INCLUDE_DIR:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/gdal-ios-device/include" \ -DGDAL_LIBRARY:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/gdal-ios-device/lib/libgdal.a" \ -DGEOS_INCLUDE_DIR:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/geos-ios-device/include/source/headers" \ -DGEOS_LIBRARY:PATH="/Users/hogbox/Documents/osgearth-build/3rdParty/geos-ios-device/lib/libGEOS_3.2.a" \ -DOSGEARTH_BUILD_APPLICATION_BUNDLES:BOOL=OFF \ -DDYNAMIC_OSGEARTH:BOOL=OFF \ -DOSGEARTH_USE_QT:BOOL=OFF根据以上配置内容,确认CMake配置,并生成osgearth ios工程文件。
跟踪代码,可发现此错误由于没有找到工程对应的平台TargetConditionals.h,只要将报错的Target的“Framework Search Paths",修改为:
只要将报错的Target的“Framework Search Paths",修改为:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks
由于当前编译的是iphoneos,所以需要将-mmacos-version-min宏删除
openscenegraph3.2.1/build/include路径找不到报错,在Target的“Header Search Paths"中添加此路径即可。
Architecture的版本取决于你使用的硬件,iphone5s使用armv7、armv7s,项目使用的是armv6、armv7。虚拟机编译使用的是i386
只要将报错的Target的“Framework Search Paths",修改为:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk/System/Library/Frameworks
从github下载代码,下载路径见前面的说明,工程下载后,只需要将osgearth/src/applications/osgearthView_IOS文件夹拷过来即可。
最好联机编译,之前编译的osg、osgearth都是联机编译的库。(虚拟机的还没试过)
配置osg、osgearth的头文件、库文件,系统framework。
编译到最后是,osgearthView_IOS工程需要拷贝osgearth目录下的tests、data、moon_1024....png,还有gdal_data(最好上gdal网站下载,再将data文件夹拷贝到xcode工程中)
今天设备被拿走,还没编译完,待编译完,再续。
ps:下午拿到设备,将osgearthView_IOS打到iPhone5上运行,闪退。