OSX Yosemite上的Cmake 10.10.3 - GLEW:找不到包“gl”

时间:2015-04-05 13:00:40

标签: c++ macos cmake glew yosemite

不久前,我决定在Cmake学习和钻研自己,并遇到一些烦人的问题。

在一些教程(包括opengl和glew)之后,我构建了一个在Windows模拟机器上运行良好的基本应用程序,但在特定时刻,仿真不再只是做这个技巧而且我切换到Xcode也是cmake的。

所以我设置了一个基本的文件夹结构:

build
CMakeLists.txt
inc
lib
src

lib文件夹包含文件夹:

glew
glfw

直接从原始下载中解压缩(包括CMakeLists.txt文件和所有文件)

要包含libs,我在我的根CMakeLists.txt中使用了这两行,但只有glew我得到了一个"' gl'找不到"错误

ADD_SUBDIRECTORY(lib/glfw)
ADD_SUBDIRECTORY(lib/glew)

使用cmake构建时,我得到了这个输出,我并不高兴:(

Could NOT find Doxygen (missing:  DOXYGEN_EXECUTABLE) 
Using Cocoa for window creation
Using NSGL for context creation
Building GLFW only for the native architecture
checking for module 'gl'
  package 'gl' not found
CMake Error at /Applications/CMake.app/Contents/share/cmake-3.2/Modules/FindPkgConfig.cmake:340 (message):
  A required package was not found
Call Stack (most recent call first):
  /Applications/CMake.app/Contents/share/cmake-3.2/Modules/FindPkgConfig.cmake:502 (_pkg_check_modules_internal)
  lib/glew/CMakeLists.txt:26 (pkg_check_modules)


Configuring incomplete, errors occurred!
See also "/Users/Makkura/Dropbox/PROGRAMMING/CPLUSPLUS_SANDBOX/CMAKE/SPARKY/build/Xcode/CMakeFiles/CMakeOutput.log".

我认为GLEW文件夹中的CMakeLists.txt文件有问题。我可以看到windows和linux的具体操作,但我看不到为osx系统指定的任何内容。

project(GLEW)
cmake_minimum_required(VERSION 2.4)

if(COMMAND cmake_policy)
    cmake_policy(SET CMP0003 NEW)
endif(COMMAND cmake_policy)

set(GLEW_VERSION "1.11.0")

set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/lib)
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)

if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
    set(GLEW_LIB_NAME glew32)
else(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
    set(GLEW_LIB_NAME GLEW)
    set(DLL_PREFIX lib)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Windows")

#
# All platforms need OpenGL
#

include(FindPkgConfig)
pkg_check_modules( OpenGL REQUIRED gl )

#
# Linux needs X11
#

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    find_package(X11 REQUIRED)
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

set(CMAKE_C_FLAGS "${CFLAGS} ${CMAKE_C_FLAGS} -DGLEW_BUILD -DGLEW_NO_GLU -O2 -Wall -W" )

include_directories( ${PROJECT_SOURCE_DIR}/include )

add_library(GLEW_static STATIC src/glew.c )
add_library(GLEW_shared SHARED src/glew.c )
set_target_properties(GLEW_static PROPERTIES OUTPUT_NAME ${GLEW_LIB_NAME} PREFIX lib)
set_target_properties(GLEW_shared PROPERTIES OUTPUT_NAME ${GLEW_LIB_NAME} PREFIX "${DLL_PREFIX}")
target_link_libraries(GLEW_shared ${OpenGL_LDFLAGS})

add_library(GLEW_MX_static STATIC src/glew.c )
add_library(GLEW_MX_shared SHARED src/glew.c )
set_target_properties(GLEW_MX_static PROPERTIES OUTPUT_NAME ${GLEW_LIB_NAME}mx COMPILE_FLAGS "-DGLEW_MX" PREFIX lib)
set_target_properties(GLEW_MX_shared PROPERTIES OUTPUT_NAME ${GLEW_LIB_NAME}mx COMPILE_FLAGS "-DGLEW_MX" PREFIX "${DLL_PREFIX}")
target_link_libraries(GLEW_MX_shared ${OpenGL_LDFLAGS})

add_executable(glewinfo src/glewinfo.c)
target_link_libraries(glewinfo GLEW_shared ${OpenGL_LDFLAGS})

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    target_link_libraries(glewinfo ${X11_LIBRARIES})
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

add_executable(visualinfo src/visualinfo.c)
target_link_libraries(visualinfo GLEW_shared ${OpenGL_LDFLAGS})

if(${CMAKE_SYSTEM_NAME} MATCHES "Linux")
    target_link_libraries(visualinfo ${X11_LIBRARIES})
endif(${CMAKE_SYSTEM_NAME} MATCHES "Linux")

install(
    TARGETS
        GLEW_static
        GLEW_shared
        GLEW_MX_static
        GLEW_MX_shared
        glewinfo
        visualinfo
    RUNTIME DESTINATION bin
    LIBRARY DESTINATION lib
    ARCHIVE DESTINATION lib
)

install(CODE "execute_process( COMMAND bash -x -c \"sed -e 's%@prefix@%${CMAKE_INSTALL_PREFIX}%g' -e 's%@exec_prefix@%\\\${prefix}%g' -e 's%@libdir@%\\\${prefix}/lib%g' -e 's%@includedir@%\\\${prefix}/include%g' -e 's/\@version\@/${GLEW_VERSION}/g' -e 's/\@cflags\@//g' -e 's/\@libname\@/${GLEW_LIB_NAME}/g' -e 's|@requireslib@|glu|g' < ${CMAKE_SOURCE_DIR}/glew.pc.in > ${CMAKE_BINARY_DIR}/glew.pc\" )" )
install(CODE "execute_process( COMMAND bash -x -c \"sed -e 's%@prefix@%${CMAKE_INSTALL_PREFIX}%g' -e 's%@exec_prefix@%\\\${prefix}%g' -e 's%@libdir@%\\\${prefix}/lib%g' -e 's%@includedir@%\\\${prefix}/include%g' -e 's/\@version\@/${GLEW_VERSION}/g' -e 's/\@cflags\@/-DGLEW_MX/g' -e 's/\@libname\@/${GLEW_LIB_NAME}mx/g' -e 's|@requireslib@|glu|g' < ${CMAKE_SOURCE_DIR}/glew.pc.in > ${CMAKE_BINARY_DIR}/glewmx.pc\" )" )

install(FILES ${CMAKE_BINARY_DIR}/glew.pc ${CMAKE_BINARY_DIR}/glewmx.pc DESTINATION lib/pkgconfig)

只要我没有解决这个问题,我就无法继续我的发展。我好几天都在寻找类似的问题,但我找不到任何明确的解决方案。有没有人遇到类似这样的问题?

1 个答案:

答案 0 :(得分:4)

嗯,失败的是pkg-config,试图找到gl包,即gl.pc配置文件。
我不知道那个应该在哪里,似乎没有关于它的文件,也没有任何人甚至没有尝试过这样的报道。
我只能假设这个目标是在/System/Library/Frameworks中引用OpenGL框架,但是,至少在我的机器上,找不到任何gl.pc。 另外,尝试使用

构建glew
export CC='clang'
export CXX='clang++'
cd glew
cmake .
make

给了我同样的错误。

然而,我能够制作自己的gl.pc

PACKAGE=GL

Name: OpenGL
Description: OpenGL
Version: 11.1.1
Cflags: -framework OpenGL -framework AGL
Libs: -Wl,-framework,OpenGL,-framework,AGL

(AGL框架是OpenGL框架的一部分。)
将此文件放在pkg-config可以找到它的位置,我实际上可以构建glew。

由于您正在构建自己的cmake thingy,您可能不希望将此文件放在/usr/share/pkgconfig中,而是将其放在项目文件夹中的某个位置并相应地设置PKG_CONFIG_PATH
例如。如果您将gl.pc放入<your project>/pkgconfig,请将其添加到您的CMakeLists.txt顶部:

set(ENV{PKG_CONFIG_PATH} ${CMAKE_SOURCE_DIR}/pkgconfig)

同样,我不知道这是不是应该做的事情,但是它起作用(至少对我而言)。