使用CMake链接GLEW [英] Linking against GLEW with CMake
问题描述
我的项目依赖于GLEW,是用CMake构建的,所以我从这里找到FindGLEW.cmake http://code.google.com/p/nvidia-texture-tools/source/browse/trunk/cmake/FindGLEW.cmake?r= 96 并在我的CMakeLists.txt中写入 find_package(GLEW REQUIRED)
。问题是,我在一个集群PC上工作的几个版本的GLEW可用。一个版本存储在 / usr / lib
中,这不是最新的。最新版本存储在 / opt / local / lib64
中。这是我想链接的版本。所以我添加了GLEW_LIBRARY路径下FindGLEW.cmake的路径。问题是makefile总是链接到旧的版本,但我需要最新的版本(1.7)使用像 GL_PATCHES
, GL_PATCH_PARAMETERS
等。我可以一些如何强制CMake使用较新的版本,就像这是FindBoost.cmake的情况。一个解决方案是擦除旧的,但这不是一个选择。我也改变了GLEW_LIBRARY列表中的路径的顺序,但是没有成功。
在我的旧Makefile我只是写了 LDDFLAGS = -L / opt / local / lib64 -lGLEW
所以路径是绝对清楚的,但现在与CMake我想使用查找功能,但希望更喜欢一个特定的版本。
<我使用这个链接静态链接到在特定位置的自定义编译GLEW库:
> #GLEW libraries
add_library(glew_static STATIC IMPORTED)
set_target_properties(glew_static PROPERTIES
IMPORTED_LOCATION /home/ryan/DevLibrary/glew-1.9.0/lib/libGLEW。 a)
target_link_libraries(smolder glew_static)
>
find_package(GLEW REQUIRED)
您也可以使用共享库,只需从add_library中删除STATIC关键字。
My project depends on GLEW and is built with CMake, so i took the FindGLEW.cmake from here http://code.google.com/p/nvidia-texture-tools/source/browse/trunk/cmake/FindGLEW.cmake?r=96 and wrote find_package(GLEW REQUIRED)
in my CMakeLists.txt. Problem is that i am working on a cluster PC were several versions of GLEW are available. One version is stored in /usr/lib
which is not the latest. the latest version is stored in /opt/local/lib64
. this is the version i want to link against. so i added the path to the FindGLEW.cmake under the GLEW_LIBRARY paths. the problem is that the makefile always links against the older version, but i need the newest version (1.7) for using stuff like GL_PATCHES
, GL_PATCH_PARAMETERS
and so on. can i some how force CMake to use the newer version like it is the case with FindBoost.cmake. one solution is to erase the older one's but this is not an option. i also changed the order of the paths in the GLEW_LIBRARY list, but without success.
in my old Makefile i just wrote LDDFLAGS = -L/opt/local/lib64 -lGLEW
so the path is absolutely clear, but now with CMake i want to use the find feature, but want to prefer a specific version.
I use this to link statically to a custom compiled GLEW lib at a specific location:
#GLEW libraries
add_library(glew_static STATIC IMPORTED)
set_target_properties(glew_static PROPERTIES
IMPORTED_LOCATION /home/ryan/DevLibrary/glew-1.9.0/lib/libGLEW.a)
target_link_libraries(smolder glew_static)
With this in place you can remove
find_package(GLEW REQUIRED)
You can use this with shared libraries as well, simply remove the STATIC keyword from add_library.
这篇关于使用CMake链接GLEW的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!