除錯查詢 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 ..