调试查找 package() 错误

注意: 显示的 CMake 错误消息已包含非标准库/工具安装路径的修复。以下示例仅演示了更详细的 CMake find_package() 输出。

CMake 内部支持的包/模块

如果以下代码( 用你的模块替换 FindBoost模块 )

cmake_minimum_required(VERSION 2.8)
project(FindPackageTest)

find_package(Boost REQUIRED)

给出了一些错误

CMake Error at [...]/Modules/FindBoost.cmake:1753 (message):
  Unable to find the requested Boost libraries.

  Unable to find the Boost header files.  Please set BOOST_ROOT to the root
  directory containing Boost or BOOST_INCLUDEDIR to the directory containing
  Boost's headers.

而且你想知道它试图找到库的位置,你可以检查你的软件包是否有像 Boost 模块那样的 _DEBUG 选项来获得更详细的输出

$ cmake -D Boost_DEBUG=ON .. 

CMake 启用包/库

如果以下代码(将 Xyz 替换为你的库

cmake_minimum_required(VERSION 2.8)
project(FindPackageTest)

find_package(Xyz REQUIRED)

给出了一些错误

CMake Error at CMakeLists.txt:4 (find_package):
  By not providing "FindXyz.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "Xyz", but
  CMake did not find one.

  Could not find a package configuration file provided by "Xyz" with any of
  the following names:

    XyzConfig.cmake
    xyz-config.cmake

  Add the installation prefix of "Xyz" to CMAKE_PREFIX_PATH or set "Xyz_DIR"
  to a directory containing one of the above files.  If "Xyz" provides a
  separate development package or SDK, be sure it has been installed.

而且你想知道它在哪里找到了库,你可以使用未记录的 CMAKE_FIND_DEBUG_MODE 全局变量来获得更详细的输出

$ cmake -D CMAKE_FIND_DEBUG_MODE=ON ..