简体   繁体   English

CMake:如何设置VTK_DIR?

[英]CMake: how to set VTK_DIR?

This is one part of my CMakeLists.txt 这是我的CMakeLists.txt一部分

set (VTK_DIR "/usr/include/vtk-5.8")

find_package(VTK REQUIRED)
include(${VTK_USE_FILE})
IF(VTK_FOUND)
  message("found VTK. Version:" ${VTK_VERSION}. VTK_DIR: ${VTK_DIR})
ELSE(VTK_FOUND)
  MESSAGE(FATAL_ERROR
    "Cannot build the executable without VTK. Please set the                                                                                                   
VTK_DIR")
ENDIF(VTK_FOUND)

cmake . tells me: 告诉我:

found VTK. 发现了VTK。 Version:6.0.0.VTK_DIR:/usr/local/lib/cmake/vtk-6.0 版本:6.0.0.VTK_DIR:/usr/local/lib/cmake/vtk-6.0

Giving the VTK_DIR in the command line does not help either: 在命令行中提供VTK_DIR也无济于事:

cmake -DVTK_DIR:PATH=/usr/include/vtk-5.8 .

Still cmake looks in /usr/local/lib/cmake/vtk-6.0 for VTK. 仍然cmake在/usr/local/lib/cmake/vtk-6.0查找VTK。

What is wrong here? 这有什么不对?

VTK_DIR is a cache variable, which keeps its state across CMake invocations. VTK_DIR是一个缓存变量,它在CMake调用中保持其状态。 You can set it from the command line, or via one of the CMake GUI interfaces. 您可以从命令行或通过其中一个CMake GUI界面进行设置。

Or, if you're certain you want to force it from your CMake file itself, you can use this syntax: 或者,如果您确定要从CMake文件本身强制它,则可以使用以下语法:

SET(VTK_DIR "/usr/include/vtk-5.8" CACHE PATH "VTK directory override" FORCE)

You should call find_package with the NO_MODULE option, 你应该使用NO_MODULE选项调用find_package,

find_package(VTK REQUIRED NO_MODULE)

This will force CMake to skip the find module, which hasn't been required for a number of releases. 这将迫使CMake跳过查找模块,这对于许多版本来说并不是必需的。 You also need to point CMake at the location of the VTKConfig.cmake file, not the C++ headers. 您还需要将CMake指向VTKConfig.cmake文件的位置,而不是C ++标头。 Setting CMAKE_PREFIX_PATH to /usr/local would have CMake check /usr/local before any other path for example. 例如,将CMAKE_PREFIX_PATH设置为/ usr / local将在任何其他路径之前进行CMake检查/ usr / local。 If your VTKConfig.cmake is installed in the /usr prefix, then the config file is likely in /usr/lib/cmake/vtk-5.8, and the VTK_DIR should be set to that too. 如果你的VTKConfig.cmake安装在/ usr前缀中,那么配置文件可能在/usr/lib/cmake/vtk-5.8中,VTK_DIR也应该设置为。

What you need is VTK install subdirectory with VTKConfig.cmake . 你需要的是带VTKConfig.cmake VTK 安装子目录 Alternatively, build directory might work as well. 或者, 构建目录也可以工作。

As suggested by Peter, try: 正如彼得所建议的那样,试试:

SET(VTK_DIR "/usr/include/vtk-5.8/XXX" CACHE PATH "VTK directory override" FORCE)

and point it to the folder where you have VTKConfig.cmake . 并将其指向您拥有VTKConfig.cmake的文件夹。

YOu could install cmake-qt-gui - there you can easily enter the required paths using a GUI. 你可以安装cmake-qt-gui - 你可以使用GUI轻松输入所需的路径。 If it doesn't use the path you entered, it means this is not the path it wants (see above). 如果它不使用您输入的路径,则表示这不是它想要的路径(参见上文)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM