如何强制执行每行后写文件而不是最终创建文件的cmake?
我正在为拥有许多图书馆的大型项目撰写Cmakelist。此cmakelist用add_subdirectory附加了这些小型项目,例如:
add_subdirectory(a)
add_subdirectory(b)
每个子目录都有多个静态库。 b
目录的库取决于a
目录的库。我实现了用于查找Bellow之类的库的功能:
if (TARGET ${FINDING_NAME})
get_target_property(BINARY_DIR ${FINDING_NAME} BINARY_DIR}
find_library(FINDING_LIBRARY_PATH
NAMES ${LIBRARY_NAME}
HINTS ${BINARY_DIR})
list(APPEND ${DEPENDENCIES_LIST} ${FINDING_LIBRARY_PATH})
else()
find_library(FINDING_LIBRARY_PATH
NAMES ${LIBRARY_NAME})
list(APPEND ${DEPENDENCIES_LIST} ${FINDING_LIBRARY_PATH})
endif()
不幸的是,当第一次执行CMAKE时,所有依赖项都在/usr/usr/local/lib
或/usr/lib/lib
中找到。我希望找到例如project_dir/repares/a /...
,但是当我第二次执行cmake时,依赖项会在project> project_dir/reparter/repares/a/...中找到。
。
我认为cmake在最后一个中生成.a
文件,但我需要在中间的这些.a
(当调用add_library()
)。
您有解决这个问题的想法吗?
I'm writing a CMakeList for big projects with many libraries. this CMakeList appends these small projects with add_subdirectory like:
add_subdirectory(a)
add_subdirectory(b)
Each subdirectory has multiple static libraries. libraries of b
directories depend on libraries of a
directories. I implementing the function for finding libraries like bellow:
if (TARGET ${FINDING_NAME})
get_target_property(BINARY_DIR ${FINDING_NAME} BINARY_DIR}
find_library(FINDING_LIBRARY_PATH
NAMES ${LIBRARY_NAME}
HINTS ${BINARY_DIR})
list(APPEND ${DEPENDENCIES_LIST} ${FINDING_LIBRARY_PATH})
else()
find_library(FINDING_LIBRARY_PATH
NAMES ${LIBRARY_NAME})
list(APPEND ${DEPENDENCIES_LIST} ${FINDING_LIBRARY_PATH})
endif()
unfortunately, When executing the Cmake for the first time all Dependencies find in /usr/local/lib
or /usr/lib
. I expect to find for example project_dir/Release/a/...
but when I execute the Cmake for the second time, the Dependencies are found in project_dir/Release/a/...
.
I think Cmake generates the .a
file at the last but I need these .a
at the middle(when calling add_library()
).
Do you have an idea to solve this problem?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只需删除您的
find_library
代码,然后与您需要的库链接:如果存在目标
a
,则目标将用于链接。如果将库安装到
/usr/local/lib
和/usr/lib
,则-la
将使编译器找到库<代码> liba.a 来自标准ld.so.conf
搜索路径。如果未安装库且目标不存在,则Linker将通知您缺少的库。
find_library
用于从非常具体的路径搜索库,如果您在编译器标准搜索路径中搜索库(并且您没有处理案例,则无需使用它当找不到图书馆时)。 Linker用于查找库,无需使用CMAKE。Just remove your
find_library
code and link with the libraries you need to:If the target
a
exists, the target will be used for linking.If the library is installed to
/usr/local/lib
and/usr/lib
, then-la
will make the compiler find the libraryliba.a
from the standardld.so.conf
search paths.If the library is not installed and the target does not exist, linker will inform you of a missing library.
find_library
is for searching a library from a very specific path, no need to use it if you are searching for a library in compiler standard search paths (and you are not handling cases when the library is not found). Linker is for finding libraries, no need to use CMake for it.