C++ CMake将依赖项添加到目录中的内部库

C++ CMake将依赖项添加到目录中的内部库,c++,cmake,C++,Cmake,我有以下项目结构: │ CMakeLists.txt ├───lib │ │ CMakeLists.txt │ ├───lib_a │ │ CMakeLists.txt │ ├───lib_b │ │ CMakeLists.txt │ └───lib_c │ CMakeLists.txt └───src │ CMakeLists.txt └───app ├───controller

我有以下项目结构:

│   CMakeLists.txt
├───lib
│   │   CMakeLists.txt
│   ├───lib_a
│   │       CMakeLists.txt
│   ├───lib_b
│   │       CMakeLists.txt
│   └───lib_c
│           CMakeLists.txt
└───src
    │   CMakeLists.txt
    └───app
        ├───controller
        |        CMakeLists.txt
        └───endorser
                 CMakeLists.txt
这些库位于
lib
目录中<代码>库b针对
库a
的链接和
库c
针对
库b
的链接。CMake可以毫无问题地识别库之间的目标。例如,在
lib/lib_c/CMakeLists.txt
文件中使用这些行可以很好地工作:

target_link_libraries(lib_c lib_a lib_b)

但是,尝试在
src/app/controller
中执行相同操作失败,出现以下错误:

[cmake] CMake Error at src/app/controller/CMakeLists.txt:15 (find_package):
[cmake]   By not providing "Findlib_c.cmake" in CMAKE_MODULE_PATH this project has
[cmake]   asked CMake to find a package configuration file provided by "lib_c", but
[cmake]   CMake did not find one.
[cmake] 
[cmake]   Could not find a package configuration file provided by "lib_c" with any of
[cmake]   the following names:
[cmake] 
[cmake]     lib_cConfig.cmake
[cmake]     lib_c-config.cmake
这就是我如何搜索
lib_c

# Check for dependencies
find_package(lib_c REQUIRED)
...
# link against it
target_link_libraries(controller lib_c)
我如何导出
lib_c
而不必安装它,这样
src/app
就可以链接到它

无论如何,非叶目录的CMakeLists.txt仅包含
add_子目录
调用:

# lib/CMakeLists.txt
cmake_minimum_required(VERSION 3.1.0)
add_subdirectory(lib_a)
add_subdirectory(lib_b)
add_subdirectory(lib_c)

“但是在
src/app
中尝试同样的操作失败。”-你说的“失败”是什么意思?你有错误信息吗?还是怎样请添加有关该问题的更多详细信息。请投诉它找不到
lib_c
,我应该提供
find-lib_c.CMake
或similar@Tsyvarev我刚刚添加了更多的细节。如果没有“find”或“Config”脚本,
find\u package()
是不可能工作的。可能是,您的库“
CMakeLists.txt
execute
find\u package
有条件地执行?”?或者他们执行
find_-package
时没有必需的选项(可能还有QUITE选项),因此
find_-package
失败不会阻止
CMakeLists.txt
继续。如果执行了
find_package
,则CMake配置日志(CMake的输出)始终有一行描述其结果。请在配置库项目时显示这些行。那么,问题帖子中所述的问题是否已解决(或者根本不是问题)?如果问题仍然存在,请更新问题帖子,并将评论中的信息纳入其中。