我有一个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文件?
答案 0 :(得分:0)
只需按照给定的错误消息,即这必须有所帮助:
# CMakeLists.txt
list(APPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_LIST_DIR}/mainproject/cmake")
add_subdirectory(plugin)