why do GLEW and GLFW have inconsistent usage?

(I’ve used CMake before, this is my first time writing a CMakeLists.txt. Sorry for any cluelessness.)

I wanted to build some code using the OpenGL library, which in modern times is provided through two libraries: GLEW and GLFW. I installed them on my macOS laptop using Homebrew. The good news is that it all worked in a simple and elegant fashion:

cmake_minimum_required(VERSION 3.10)
add_executable(Project main.cpp)
find_package(GLFW3 REQUIRED)
find_package(GLEW REQUIRED)
target_link_libraries(Project glfw GLEW::glew)

The bad news was that it took a lot of tries to get there, with many visits to cmake.org and stackoverflow, and many much longer versions of the CMakeLists.txt file. Eventually I found this approach. It worked for me to say “glfw” but not “GLFW::glfw” in that call to target_link_libraries(). The latter (GLFW::glfw) seemed more consistent, and was given in examples in several of the SO answers.

I am fine with whatever it take to make it work, but is this the way it is suppose to work?


Find modules have added (if at all) imported targets at different times. Some may have appeared before PkgName:: became “the norm”. Or the contributor didn’t use it (because upstream might not use namespaces either). Find modules should document the variables and targets they create in their docs though. If that’s inaccurate, we can certainly fix that. A namespaced target can also be added to FindGLFW3 as well.

Thanks. The lack of a namespace qualifier seemed odd. I wanted to mention it in case that level of oddness constituted a bug. Sounds like no. However Ben’s answer reminded me that I had tried to look at that doc but got this:

> cmake --help-module FindGLFW3
Argument "FindGLFW3" to --help-module is not a CMake module.