使用 OpenGL ES 2.0 和 cmake 生成 iOS 静态库

Posted

技术标签:

【中文标题】使用 OpenGL ES 2.0 和 cmake 生成 iOS 静态库【英文标题】:Generate iOS static library using OpenGL ES 2.0 with cmake 【发布时间】:2014-09-22 23:49:01 【问题描述】:

我正在为多平台渲染器(至少现在是 ios/Mac)编写构建工具链。该项目有一个核心库(每个平台目标都将使用该库),应将其编译为静态库 (.a),以便在其他平台相关项目中使用(如在 xcode 项目或 eclipse 中)用于进一步的android开发)。

此静态库依赖于 OpenGL ES 2.0 (iOS) 或 OpenGL for Mac。所以我有以下文件以包含正确的标题:

#ifdef PLATFORM_IOS
#include <OpenGLES/ES2/gl.h>
#include <OpenGLES/ES2/glext.h>
#endif

#ifdef PLATFORM_OSX
#include <OpenGL/gl.h>
#include <GLFW/glfw3.h>
#endif

事实是它在 Mac 平台上完美运行,cmake 正确找到了 OpenGL 头文件,但对于 iOS,它没有找到 OpenGLES;即使使用我编写的 FindOpenGLES.cmake 模块,我也无法找到这些头文件,这似乎是合乎逻辑的,因为我什至在 /usr/include 中都找不到它们。

【问题讨论】:

尝试定位 OpenGLES 和 ES2 目录。如果它们存在,您可以使用 include_directories() 获取确切位置。 是的,这就是我想要做的,但我不知道它们在哪里,我跑了一个 find /usr -name "*GLES*",但这里似乎什么都没有。 1.运行定位命令。 2.或者试试 find / -name "*GLES*" -type f -print 他们一定在某处 【参考方案1】:

你可能需要设置CMAKE_SYSTEM_FRAMEWORK_PATH,以下是我iOS自带的工具链文件

  set (IOS_SDK_ROOT "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS10.2.sdk")

  # Set the sysroot default to the most recent SDK
  set (CMAKE_OSX_SYSROOT $IOS_SDK_ROOT CACHE PATH "Sysroot used for iOS support")

  # set the architecture for iOS - this env var sets armv6,armv7 and appears to be XCode's standard. The other found is ARCHS_UNIVERSAL_IPHONE_OS but that is armv7 only
  set (CMAKE_OSX_ARCHITECTURES "$IOS_ARCH" CACHE string "Build architecture for iOS")

  # set up the default search directories for frameworks
  set (CMAKE_SYSTEM_FRAMEWORK_PATH $IOS_SDK_ROOT/Developer/Library/Frameworks)

【讨论】:

以上是关于使用 OpenGL ES 2.0 和 cmake 生成 iOS 静态库的主要内容,如果未能解决你的问题,请参考以下文章