[英]How does cmake find a package?
I am trying to understand how cmake finds packages, using the FindXXX.cmake
file. 我试图了解cmake如何使用FindXXX.cmake
文件查找软件包。 As an example, the library OpenNI has the file FindOpenNI.cmake
defined here: https://github.com/PointCloudLibrary/pcl/blob/master/cmake/Modules/FindOpenNI.cmake 例如,库OpenNI的文件FindOpenNI.cmake
在此处定义: https : //github.com/PointCloudLibrary/pcl/blob/master/cmake/Modules/FindOpenNI.cmake
Now, at the bottom of that file, there is the following: 现在,在该文件的底部,有以下内容:
if(OPENNI_FOUND)
# Add the include directories
set(OPENNI_INCLUDE_DIRS ${OPENNI_INCLUDE_DIR})
message(STATUS "OpenNI found (include: ${OPENNI_INCLUDE_DIRS}, lib: ${OPENNI_LIBRARY})")
endif(OPENNI_FOUND)
What I do not understand is where the variable OPENNI_FOUND
is defined, because this is the first point in the file that it is mentioned. 我不明白的是变量OPENNI_FOUND
的定义位置,因为这是文件中提到的第一点。
I would have thought that this file itself is used to find OpenNI, by searching the directories as dictated in the file's contents. 我以为该文件本身就是通过搜索文件内容中指定的目录来查找OpenNI的。 However, it seems that OPENNI_FOUND
must have been declared before. 但是,似乎必须先声明OPENNI_FOUND
。 Therefore, it is confusing to me: FindOpenNI.cmake
is being used to find OpenNI, but during that process, it has been given the variable OPENNI_FOUND
, which itself tells cmake whether OpenNI has been found. 因此,这使我感到困惑:使用FindOpenNI.cmake
来查找OpenNI,但是在此过程中,给它分配了变量OPENNI_FOUND
,它本身告诉cmake是否已找到OpenNI。
So how is cmake actually finding OpenNI? 那么,cmake如何真正找到OpenNI? Using this file? 使用这个文件? Or some other way? 还是其他方式?
Thanks :) 谢谢 :)
Yes, CMake uses file you mentioned to find OpenNI. 是的,CMake使用您提到的文件来查找OpenNI。 The OPENNI_FOUND
variable is set by find_package_handle_standard_args()
function. OPENNI_FOUND
变量由find_package_handle_standard_args()
函数设置。 It is where the all magic is done, see the documentation for it . 这是万事俱备的地方,请参阅文档 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.