如何强制执行每行后写文件而不是最终创建文件的cmake?

发布于 2025-02-08 09:59:10 字数 1007 浏览 0 评论 0原文

我正在为拥有许多图书馆的大型项目撰写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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

亽野灬性zι浪 2025-02-15 09:59:10

只需删除您的find_library代码,然后与您需要的库链接:

target_link_libraries(thetarget a)

如果存在目标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:

target_link_libraries(thetarget a)

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 library liba.a from the standard ld.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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文