如何知道 CMakeLists 的库变量名称?

How to know library variable names for CMakeLists?(如何知道 CMakeLists 的库变量名称?)

本文介绍了如何知道 CMakeLists 的库变量名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当使用 CMakeLists 编译 OpenGL 项目时,我有以下行来链接 glut 和 gl:

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})

我查找了如何将 glut 和 gl 与 CMake 联系起来,所以我发现我可以使用 ${OPENGL_gl_LIBRARY} 和 ${GLUT_LIBRARIES}.但是我怎么知道要使用的变量呢?我习惯于只执行 ${THELIBRARY_LIBRARES},但在 gl 的情况下,它更改为将gl"添加到变量名称中.如果不使用谷歌搜索(对于我想使用的任何库),我怎么知道呢?

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)?

推荐答案

那些变量是通过 find_package(XXX) 调用获得的.

Those variables are obtained via find_package(XXX) calls.

此类调用被重定向,依赖于库,要么到 FindXXX.cmake 脚本(随 CMake 提供或包含在使用它的项目中)或 XXXConfig.cmake 脚本(与库本身一起提供).

Such calls are redirected, depended from the library, either to FindXXX.cmake script (shipped with CMake or contained in the project which uses it) or to XXXConfig.cmake script (shipped with the library itself).

因此,要确定有意义的变量名称,您需要查阅适当的脚本.通常,脚本的接口(输入-输出变量)在脚本开头的注释中描述.

So, for determine meaningful variable's names you need to consult appropriate script. Usually, interface of the script (input-output variables) is described in comments at the beginning of the script.

CMake 附带的 FindXXX.cmake 脚本的文档可以在 关于模块的 CMake 文档页面.

Documentation for FindXXX.cmake scripts shipped with CMake may be read in CMake documentation pages about modules.

这篇关于如何知道 CMakeLists 的库变量名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本文标题为:如何知道 CMakeLists 的库变量名称?

基础教程推荐