问题
A while ago I decided to learn and delve myself in Cmake and ran into some annoying issues.
Following some tutorials (involving opengl and glew), I built a basic application that ran fine on a windows emulated machine but at a specific moment, emulation wouldn't just do the trick anymore and I switched to Xcode and also Cmake.
So I set up a basic folder structure:
build
CMakeLists.txt
inc
lib
src
lib folder includes the folders:
glew
glfw
Which are unzipped straight from their original downloads (including a CMakeLists.txt file and all)
To include the libs I used these 2 lines in my root CMakeLists.txt but only with glew I got a "'gl' not found" error
ADD_SUBDIRECTORY(lib/glfw)
ADD_SUBDIRECTORY(lib/glew)
When building with cmake I got this output which I wasn't very happy about :(
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".
I assume there is something wrong with the CMakeLists.txt file in the GLEW folder. I can see specific actions for windows and linux but I can't see anything specified for osx systems.
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)
As long as I don't get this problem solved I can't continue with my development. I've been searching for similar issues for days but I can't find any definitive solution. Has anyone encountered a similar problem like this?
回答1:
Well, what fails is pkg-config
, trying to find the gl
package, i.e. a gl.pc
configuration file.
I have no idea where that one's supposed to be and there seems to be no documentation regarding it, as well as no reports of anyone ever even trying this.
I can only assume that the goal of this is to reference the OpenGL framework in /System/Library/Frameworks
, but, at least on my machine, there is no gl.pc
anywhere to be found.
Also, trying to build glew with
export CC='clang'
export CXX='clang++'
cd glew
cmake .
make
gives me the same error you get.
However, I was able to craft my own gl.pc
:
PACKAGE=GL
Name: OpenGL
Description: OpenGL
Version: 11.1.1
Cflags: -framework OpenGL -framework AGL
Libs: -Wl,-framework,OpenGL,-framework,AGL
(The AGL framework is part of the OpenGL framework.)
Putting this file in a location where pkg-config
would find it, I was able to actually build glew.
Since you are building your own cmake thingy, you might not want to put this file in /usr/share/pkgconfig
but rather have it somewhere in your project folder and set PKG_CONFIG_PATH
accordingly.
E.g. if you put gl.pc
in <your project>/pkgconfig
, add this to the top of your CMakeLists.txt:
set(ENV{PKG_CONFIG_PATH} ${CMAKE_SOURCE_DIR}/pkgconfig)
Again, I have no idea whether or not this is the way anything's supposed to be done, but it works (at least for me).
来源:https://stackoverflow.com/questions/29457534/cmake-on-osx-yosemite-10-10-3-glew-package-gl-not-found