来自parent die cmake文件夹的add_subdirectory中的CMake Find_Package

时间:2014-09-21 18:32:25

标签: cmake

我有一个CMake结构:

  • mainproject/
  • mainproject/cmake/FindMyPackage.cmake
  • mainproject/CMakeLists.txt
  • plugin/
  • plugin/CMakeLists.txt

并在上面的CMakeLists.txt中呼叫

add_subdirectory(${LOOP_SUBDIR}/${subdir} examples/${subdir})

plugin/CMakeLists.txt子目录添加到上面定义的目录之外。

在第二个CMakeLists.txt中,我致电FindPackage(MyPackage REQUIRED)

给出错误信息:

CMake Error at [...]/plugin/CMakeLists.txt:9 (find_package):
  By not providing "FindMyPackage.cmake" in CMAKE_MODULE_PATH this project has
  asked CMake to find a package configuration file provided by "MyPackage", but
  CMake did not find one.

有没有办法让它使用mainproject文件夹中的cmake文件?

1 个答案:

答案 0 :(得分:0)

只需按照给定的错误消息,即这必须有所帮助:

# CMakeLists.txt
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/mainproject/cmake")
add_subdirectory(plugin)