Hi, using find_package(glfw3) does not work on newer versions of installed library.
I have installed glfw3 on ubuntu yakkety:
apt-get install libglfw3-dev
dpkg --status libglfw3-dev
The installed version is 3.2.1-1.
Then, I have cmake file:
find_package(glfw3)
get_cmake_property(_variableNames VARIABLES)
foreach (_variableName ${_variableNames})
message(STATUS "${_variableName}=${${_variableName}}")
endforeach()
And running it like cmake . | grep -i glfw
gives (on yakkety):
-- CONFIG_FILES=/usr/lib/x86_64-linux-gnu/cmake/glfw3/glfw3Targets-none.cmake
-- GLFW3_DIR=GLFW3_DIR-NOTFOUND
-- _DIR=/usr/lib/x86_64-linux-gnu/cmake/glfw3
-- glfw3_CONFIG=/usr/lib/x86_64-linux-gnu/cmake/glfw3/glfw3Config.cmake
-- glfw3_CONSIDERED_CONFIGS=/usr/lib/x86_64-linux-gnu/cmake/glfw3/glfw3Config.cmake
-- glfw3_CONSIDERED_VERSIONS=3.2.1
-- glfw3_DIR=/usr/lib/x86_64-linux-gnu/cmake/glfw3
-- glfw3_FOUND=1
-- glfw3_VERSION=3.2.1
-- glfw3_VERSION_COUNT=3
-- glfw3_VERSION_MAJOR=3
-- glfw3_VERSION_MINOR=2
-- glfw3_VERSION_PATCH=1
-- glfw3_VERSION_TWEAK=0
-- glfw_DIR=glfw_DIR-NOTFOUND
Whereas on ubuntu xenial, it gives:
-- GLFW3_INCLUDE_DIR=/usr/include
-- GLFW3_LIBRARY=/usr/lib/x86_64-linux-gnu/libglfw.so
-- GLFW3_LIBRARY_DIR=/usr/lib/x86_64-linux-gnu
-- GLFW3_VERSION=3.1.2
-- glfw3_CONFIG=/usr/lib/x86_64-linux-gnu/cmake/glfw3/glfw3Config.cmake
-- glfw3_CONSIDERED_CONFIGS=/usr/lib/x86_64-linux-gnu/cmake/glfw3/glfw3Config.cmake
-- glfw3_CONSIDERED_VERSIONS=3.1.2
-- glfw3_DIR=/usr/lib/x86_64-linux-gnu/cmake/glfw3
-- glfw3_FOUND=1
-- glfw3_VERSION=3.1.2
-- glfw3_VERSION_COUNT=3
-- glfw3_VERSION_MAJOR=3
-- glfw3_VERSION_MINOR=1
-- glfw3_VERSION_PATCH=2
-- glfw3_VERSION_TWEAK=0
To summarize, the newer version is missing GLFW3_INCLUDE_DIR
and GLFW3_LIBRARY
.
GLFW 3.2 and later uses the CMake target export feature. The glfw
target you import with find_package
contains the necessary directories, link-time dependencies, etc.
Starting with 3.2 all you need to do is:
find_package(glfw3)
target_link_libraries(myapplicationname glfw)
The 3.2 documentation did a really poor job of explaining this. It has been somewhat improved for 3.3.
Thank you. I have made it work with both versions now.
Most helpful comment
GLFW 3.2 and later uses the CMake target export feature. The
glfw
target you import withfind_package
contains the necessary directories, link-time dependencies, etc.Starting with 3.2 all you need to do is: