Linking GLEW with CMake

Typical CMake scripts like FindGLEW will define variables that specify the paths and files that your project needs. If the script can’t automatically identify the correct paths (usually because of nonstandard install location, which is fine), then it leaves these variables up to you to fill in.

With command line CMake, you use the -D flag to define and set the value of a given variable. Other CMake interfaces, like CMake-gui or an IDE integration, give you this ability some other way.

However you do it, you can also modify the cache directly (CMakeCache.txt) and see what CMake is using in there or just clear the cache altogether. You’ll have to rerun CMake for it to pick up your changes.

When it comes to linking, that’s when you need to tell CMake which libs to link. Use the link_libraries command with what the automated script gives you.

find_package(GLEW REQUIRED)
include_directories(${GLEW_INCLUDE_DIRS})
link_libraries(${GLEW_LIBRARIES})

Leave a Comment