遇到的問題
find_package(lzb)出現錯誤如下:
CMake Warning at CMakeLists.txt:37 (find_package):
By not providing "Findlzb.cmake" in CMAKE_MODULE_PATH this project has
asked CMake to find a package configuration file provided by "lzb", but
CMake did not find one.
Could not find a package configuration file provided by "lzb" with any of
the following names:
lzbConfig.cmake
lzb-config.cmake
Add the installation prefix of "lzb" to CMAKE_PREFIX_PATH or set "lzb_DIR"
to a directory containing one of the above files. If "lzb" provides a
separate development package or SDK, be sure it has been installed.
兩種模式
Moudule模式:搜索CMAKE_MODULE_PATH指定路徑下的FindXXX.cmake文件。
Config模式:搜索指定路徑下的XXXConfig.cmake或者XXX-config.cmake文件。
優先級
cmake默認采用Moudle模式,如果失敗,會采用Config模式。
但是如果事前指定XXX_DIR,會優先搜索XXX_DIR下的Config文件;如果XXX_DIR下未找到相應文件,CMake會從Moudule模式重新開始尋找:
If <package>_DIR has been set to a directory not containing a configuration file CMake will ignore it and search from scratch
如果在Moudule模式下也未找到,那么進入Config模式,會在所謂的“其它目錄”里面尋找,這里我也沒仔細追尋“其它目錄”指的啥,具體可以看CMake文檔。
關於QUIET和REQUIRED選項
如果指定了QUIET選項,那么表示:就算未找到該包的配置文件,也不會報錯。
相反地,如果指定了REQUIRED選項:如果未找到文件,會報錯。
If the package configuration file cannot be found CMake will generate an error describing the problem unless the QUIET argument is specified. If REQUIRED is
specified and the package is not found a fatal error is generated and the configure step stops executing.
參考
https://zhuanlan.zhihu.com/p/50829542
https://www.jianshu.com/p/46e9b8a6cb6a
https://cmake.org/cmake/help/v3.10/command/find_package.html