CMake include()与find_package()的默认搜索路径 [英] default search paths for CMake include() vs. find_package()
问题描述
我在Debian机器上安装了VTK6,并将其所有CMake文件放置在
I have VTK6 installed on my Debian machine and it places all its CMake files under
$ ls /usr/lib/cmake/vtk-6.3/
[...]
VTKConfig.cmake
vtkModuleAPI.cmake
[...]
当我这样做
find_package(VTK)
在另一个项目中,一切正常.但是,
in another project, it all works out fine. However,
include(vtkModuleAPI)
产生错误
include could not find load file:
vtkModuleAPI
我一直给人的印象是 find_package()
和 include
共享相同的搜索路径,特别是 CMAKE_MODULE_PATH
.显然这是不正确的.
I had always been under the impression that find_package()
and include
share the same search paths, specifically CMAKE_MODULE_PATH
. Apparently that's not correct.
请注意
SET(CMAKE_MODULE_PATH "/usr/lib/cmake/vtk-6.3")
include(vtkModuleAPI)
起作用.
还请注意,我正在使用CMake 3.5,因此不再有 FindVTK.cmake
Also note that I'm using CMake 3.5, so there no longer is a FindVTK.cmake
as it used to be.
find_package()
和 include()
的默认搜索路径是什么?为什么找不到 vtkModuleAPI.cmake
?
What are the default search paths for find_package()
and include()
? Why is vtkModuleAPI.cmake
not found?
推荐答案
模块模式试图找到 Module mode tries to locate 配置模式尝试找到 Config mode tries to locate 命令 include 仅在 CMAKE_MODULE_PATH 和特殊的CMake模块目录. Command include searches modules only under directories in CMAKE_MODULE_PATH and special CMake module directory. 如您所见,在模块模式中的命令 As you can see, command 对于VTK,CMake附带了 In case of VTK, CMake has shipped 如果此调用找到文件 If this call locates file 如果您的 If your [从CMake-3.1开始, [Starting with CMake-3.1, 无论如何,目录 In any case, modules in directory 这篇关于CMake include()与find_package()的默认搜索路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! FindXXX.cmake
文件.在 CMAKE_MODULE_PATH 中列出的目录下以及在安装CMake的目录下搜索该文件.
FindXXX.cmake
file. The file is searched under directories listed in CMAKE_MODULE_PATH plus under directory where CMake is installed. XXXConfig.cmake
文件.在 CMAKE_PREFIX_PATH 和其他一些特定于系统的变量中列出的目录下搜索该文件.(完整算法请参见文档,该文章开头链接.)XXXConfig.cmake
file. The file is searched under directories listed in CMAKE_PREFIX_PATH and some other, system-specific variables. (Full algorithm see in the documentation, linked at the beginning of the post). include
和命令 find_package
使用相似的搜索路径.但是在您的情况下,只能在 find_package
的 config模式中搜索 VTKConfig.cmake
,该模式使用完全不同的搜索算法.include
and command find_package
in module mode uses similar search paths. But in your case, VTKConfig.cmake
can be searched only in config mode of find_package
, which uses completely different search algorithm. FindVTK.cmake
文件,该文件在您调用 find_package(VTK)
时使用.但是在内部,此脚本使用了 find_package(VTK QUIET NO_MODULE)
.FindVTK.cmake
file, which is used when you call find_package(VTK)
. But inside, this script uses find_package(VTK QUIET NO_MODULE)
./usr/lib/cmake/vtk-6.3/VTKConfig.cmake
,它将执行此脚本,并且该脚本包括 vtkModuleAPI.cmake
一个/usr/lib/cmake/vtk-6.3/VTKConfig.cmake
, it executes this script, and the script includes vtkModuleAPI.cmake
one. VTKConfig.cmake
不在CMake中,您可以通过将 VTK_DIR 变量设置为/usr/lib/cmake/vtk-6.3来提供帮助./
.VTKConfig.cmake
is not located by CMake, you may help it by setting VTK_DIR variable to /usr/lib/cmake/vtk-6.3/
. FindVTK.cmake
不再随CMake一起提供,因此 find_package(VTK)
立即尝试查找 VTKConfig.cmake
].FindVTK.cmake
is no longer shipped with CMake, so find_package(VTK)
immediately tries to locate VTKConfig.cmake
]./usr/lib/cmake/vtk-6.3/
中的模块不应直接包含:此目录为 private 用于VTK./usr/lib/cmake/vtk-6.3/
shouldn't be included directly: this directory is private for VTK.