Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

When using CMakeLists to compile an OpenGL project, I have the following line to link glut and gl:

target_link_libraries(my_exe ${OPENGL_gl_LIBRARY} ${GLUT_LIBRARIES})

I looked up how to link glut and gl with CMake so I saw that I could use ${OPENGL_gl_LIBRARY} and ${GLUT_LIBRARIES}. But how would I know the variables to use otherwise? I am used to just doing ${THELIBRARY_LIBRARES}, but in the case of gl, it changed to adding that "gl" into the variable name. How would I know that without googling it (for any library I want to use)?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
222 views
Welcome To Ask or Share your Answers For Others

1 Answer

Besides consulting the find module's documentation, you could also use CMake's VARIABLES property to give you the variables that were defined by your find_package() call.

For an example the following code:

cmake_minimum_required(VERSION 3.2)

project(FindPackageVars)

get_directory_property(_vars_before VARIABLES)
find_package(OpenGL)
get_directory_property(_vars VARIABLES)

list(REMOVE_ITEM _vars _vars_before ${_vars_before})
foreach(_var IN LISTS _vars)
    message(STATUS "${_var} = ${${_var}}")
endforeach()

Outputs on my machine:

-- Found OpenGL: /usr/lib/x86_64-linux-gnu/libGL.so
-- FIND_PACKAGE_MESSAGE_DETAILS_OpenGL = [/usr/lib/x86_64-linux-gnu/libGL.so][/usr/include][v()]
-- OPENGL_FOUND = TRUE
-- OPENGL_GLU_FOUND = YES
-- OPENGL_INCLUDE_DIR = /usr/include
-- OPENGL_INCLUDE_PATH = /usr/include
-- OPENGL_LIBRARIES = /usr/lib/x86_64-linux-gnu/libGLU.so;/usr/lib/x86_64-linux-gnu/libGL.so
-- OPENGL_LIBRARY = /usr/lib/x86_64-linux-gnu/libGLU.so;/usr/lib/x86_64-linux-gnu/libGL.so
-- OPENGL_XMESA_FOUND = NO
-- OPENGL_gl_LIBRARY = /usr/lib/x86_64-linux-gnu/libGL.so
-- OPENGL_glu_LIBRARY = /usr/lib/x86_64-linux-gnu/libGLU.so
-- OPENGL_xmesa_INCLUDE_DIR = OPENGL_xmesa_INCLUDE_DIR-NOTFOUND

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...