0

In CLion when I attempt to build a project using CMake with a pre-bundled GLEW dependency using the following CMake, I get the following error: "Could NOT find GLEW (missing: GLEW_LIBRARIES) (found version "2.0.0")" even though the target is set to the dependencies folder.

I already solved this issue by replacing the FindGLEW module in the CMake installation Modules folder. It seems that the new version of that Module is unable to use the bundled GLEW. I replaced it with an older version of FindGLEW and it works, but I'd still like to know why it failed to work with the new module.

The dependencies look like this: ./dependencies/ which contains the include and lib for GLEW

The CMake file is as follows.

cmake_minimum_required(VERSION 3.1)
project(proj1 CXX)

#
# CONFIGURATION
#

# Basic CMake settings
set(CMAKE_INSTALL_PREFIX ${CMAKE_CURRENT_SOURCE_DIR}/_install)
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${CMAKE_SOURCE_DIR}/cmake)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(VS_DEBUGGER_WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/data)
set(GLEW_USE_STATIC_LIBS TRUE)

# Use add_resources function to convert .glsl to a .cpp files which will be compiled into a separate static library
include(add_resources)

#
# DEPENDENCIES
#

# Set up external dependencies for Windows users
if (MINGW)
  set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${CMAKE_SOURCE_DIR}/dependencies/include/")
  set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${CMAKE_SOURCE_DIR}/dependencies/lib/mingw")
elseif (MSVC)
  set(CMAKE_INCLUDE_PATH ${CMAKE_INCLUDE_PATH} "${CMAKE_SOURCE_DIR}/dependencies/include/")
  set(CMAKE_LIBRARY_PATH ${CMAKE_LIBRARY_PATH} "${CMAKE_SOURCE_DIR}/dependencies/lib/vc2015")
  set(USE_STRICT_COMPILE_WARNINGS OFF CACHE BOOL "" FORCE)
endif ()

# Warnings for Debug mode
option(USE_STRICT_COMPILE_WARNINGS "Use strict compilation warnings in debug mode." ON)
# These compile flags should apply for GCC and Clang compilers
set(STRICT_COMPILE_FLAGS "-Wpedantic -Wall -Wno-c++98-compat -Wextra -Wconversion -Wsign-compare -Wuninitialized -Wno-unused-parameter")
if (USE_STRICT_COMPILE_WARNINGS)
  set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} ${STRICT_COMPILE_FLAGS}")
endif ()

# Find required packages
find_package(GLFW3 REQUIRED)
find_package(GLEW REQUIRED)
find_package(GLM REQUIRED)
find_package(OpenGL REQUIRED)

# Optional packages
find_package(OpenMP)
if(OPENMP_FOUND)
  list(APPEND CMAKE_CXX_FLAGS ${OpenMP_CXX_FLAGS})
endif()

# Set default installation destination
if (NOT CMAKE_INSTALL_PREFIX)
  set(CMAKE_INSTALL_PREFIX "../_install")
endif ()

#
# Shaders / Materials
#

set(proj1_SHADER_SRC
        shader/color_vert.glsl shader/color_frag.glsl
        shader/convolution_vert.glsl shader/convolution_frag.glsl
        shader/diffuse_vert.glsl shader/diffuse_frag.glsl
        shader/texture_vert.glsl shader/texture_frag.glsl
        )
add_resources(shaders ${proj1_SHADER_SRC})

# proj1 library
add_library(proj1 STATIC
        proj1/mesh.cpp
        proj1/tiny_obj_loader.cpp
        proj1/shader.cpp
        proj1/image.cpp
        proj1/image_bmp.cpp
        proj1/image_raw.cpp
        proj1/texture.cpp
        proj1/window.cpp
        )

# Make sure GLM uses radians and GLEW is a static library
target_compile_definitions(proj1 PUBLIC -DGLM_FORCE_RADIANS -DGLEW_STATIC)

# Link to GLFW, GLEW and OpenGL
target_link_libraries(proj1 PUBLIC ${GLFW_LIBRARIES} GLEW::GLEW ${OPENGL_LIBRARIES})
# Pass on include directories
target_include_directories(proj1 PUBLIC
        proj1
        ${GLFW_INCLUDE_DIRS}
        ${GLEW_INCLUDE_DIRS}
        ${GLM_INCLUDE_DIRS}
        ${OPENGL_INCLUDE_DIRS}
        ${CMAKE_SOURCE_DIR}
        ${CMAKE_CURRENT_BINARY_DIR})

#
# TARGETS
#

add_executable(raw3_raytrace src/raw3_raytrace/raw3_raytrace.cpp)
target_link_libraries(raw3_raytrace proj1 ${OpenMP_libomp_LIBRARY})
install(TARGETS raw3_raytrace DESTINATION .)

#
# INSTALLATION
#
file(COPY "data/" DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
install(DIRECTORY data/ DESTINATION .)

Just to re-iterate, replacing the FindGLEW module in CMake with an older one makes it work.

I already tried suggestions in the following thread, including those made in the comments CMake can't find GLEW

Jack Avante
  • 1,405
  • 1
  • 15
  • 32
  • If you want us to help you with using `FindGLEW.cmake` module in current form, then you need to provide more information about your attempts and actual layout of GLEW package on your machine. E.g. what is **absolute path** to the `glew` library (a library is a file with name like `glew.a` or `glew.dll.a`) you **expect** to find? Does your code include all attempts, or you have tried more? Have you tried to remove setting of `GLEW_USE_STATIC_LIBS` variable? My **guess** is that you have only a **dynamic** library, so it cannot find a static one. (Older FindGLEW just finds a dynamic one). – Tsyvarev Sep 22 '20 at 18:34
  • The layout is dependencies/include/GL/glew.h for the lib it's dependencies/lib/mingw/libglew32.a. My code above doesn't include the attempts, just the original CMake. I did try moving the dll directly under lib outside of mingw. It simply starts working when I replace FindGlew with an older one in the CMake modules folder. Also, removing GLEW_USE_STATIC_LIBS doesn't fix it. – Jack Avante Sep 22 '20 at 19:32
  • 1
    Well, newest [FindGLEW.cmake](https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/FindGLEW.cmake) expects a shared **library** to [have](https://gitlab.kitware.com/cmake/cmake/blob/master/Modules/FindGLEW.cmake#L140) names `GLEW`, `glew` or `glew32` and a **static** library to have names `GLEW`, `glew` or `glew32s`. As you can see, your static library `libglew32.a` has a name of shared library, so the script cannot find it. Compare with [older script](https://gitlab.kitware.com/cmake/cmake/-/blob/v3.5.2/Modules/FindGLEW.cmake) which just searches names `GLEW`,`glew32`,`glew`,`glew32s`. – Tsyvarev Sep 22 '20 at 21:51
  • I tried refactoring the name to be glew32s.a, glew32s alone and glew32s.dll (just cause why not) and unfortunately I got the same error message. I tried GLEW and glew as well. – Jack Avante Sep 23 '20 at 09:01
  • UPDATE: Suddenly started working after renaming to glew32s.lib – Jack Avante Sep 23 '20 at 09:07

0 Answers0