Search code examples
cmakestatic-linkingdynamic-linkingglew

Not able to link GLEW to a project using CMake


May someone recommend me, how could I link my project to the GLEW via cmake.

For instance, I did well for the GLFW, according to its documentation:

...
set(GLFW_BUILD_DOCS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_TESTS OFF CACHE BOOL "" FORCE)
set(GLFW_BUILD_EXAMPLES OFF CACHE BOOL "" FORCE)

add_subdirectory(${CMAKE_SOURCE_DIR}/application/dependencies/GLFW)
...
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_MAIN})
target_link_libraries(${PROJECT_NAME} glfw)

I haven't found the good documentation by GLEW. I also would note I've installed this version of the GLEW, where CMakeLists.txt located in the root directory. I've tried different options, however the project not capable to find the glwe lib.

My best attempt looks like:

add_subdirectory(${CMAKE_SOURCE_DIR}/application/dependencies/GLEW)
...
add_executable(${PROJECT_NAME} ${${PROJECT_NAME}_MAIN})
target_include_directories(${PROJECT_NAME} PRIVATE ${CMAKE_SOURCE_DIR}/application/dependencies/GLEW/include)
target_link_libraries(${PROJECT_NAME} glfw GLEW)

But, it seems foolish. I mean if I properly comprehend, glew's CMake generates static/dynamic lib, and at the next step I link one to the project. However, it's still not able to detect glew lib.


Solution

  • There is no CMake target called GLEW in the linked project. The library targets are called libglew_static and libglew_shared. You should be using the library targets as defined in the glew project CMakeLists.txt.