2020/8/23

cmake : find_package

CMakeList.txt 中可以檢查系統有沒有安裝 XXX package,是用 find_package( )

例如,在project 一開始.. run mkdir build && cd build && cmake .. 時...
CMake Error at /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:137 (message):
  Could NOT find Protobuf (missing: Protobuf_INCLUDE_DIR)
Call Stack (most recent call first):
  /usr/share/cmake-3.10/Modules/FindPackageHandleStandardArgs.cmake:378 (_FPHSA_FAILURE_MESSAGE)
  /usr/share/cmake-3.10/Modules/FindProtobuf.cmake:543 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
  cmake/ProtoBuf.cmake:4 (find_package)
  cmake/Dependencies.cmake:43 (include)
  CMakeLists.txt:49 (include)
最後列的就有點像是 call stack..

可以出find_package( ) search 的file 和途徑。
用的是 /usr/share/cmake-3.10/Modules/FindProtobuf.cmake

這個是 cmake package 的 default module search path.
如果有自己寫的 FindMypackage.cmake 的話,也可以放在自己的目錄,然後加入 module search path:
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake/Modules)

沒有留言:

張貼留言