cmake:弄清楚哪些库是链接到的二进制目标 [英] cmake: figuring out which libraries is a binary target linked against

查看:126
本文介绍了cmake:弄清楚哪些库是链接到的二进制目标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望在CMake中实现一个功能,该功能将允许通过 make install-TARGET 命令安装单个二进制文件/目标。使用自定义目标非常简单。但是,当目标二进制文件与项目的其他库动态链接时( BUILD_SHARED_LIBS = ON ),我还需要安装可接受的库。有什么办法可以查询库列表吗?

I wand to implement in CMake a functionality that would enable the installation of a single binary/target through a make install-TARGET command. This is fairly straightforward to do with a custom target. However, when the target binary in question is linked dynamically against other libs of the project (BUILD_SHARED_LIBS=ON), I need to install the receptive libs as well. Is there any way to somehow query the list of libraries?

我查看了目标属性,但没有发现任何相关内容。

I've looked at the target properties, but haven't found anything relevant.

有关如何获取库列表和/或其他实现上述功能的方法的提示将非常感激!

Tips on how to get the list of libs and/or other ways to implement the above described functionality would be very much appreciated!

示例: < br>
假设项目 MyProj 有一个CMake目标 myprog,该目标生成二进制 myprog 。我想使用 make install-myprog 仅安装 该二进制文件。但是 myprog 链接到 libmy1.so ,后者链接到 libmy2.so ,均属于 MyProj
我需要一种机制来确定我需要同时安装 libmy1.so libmy2.so 沿着 myprog

Example:
Let's assume that there the project MyProj has a CMake target "myprog" which generates the binary myprog. I want to install only this binary with make install-myprog. However myprog links against libmy1.so and the latter links against libmy2.so, both part of MyProj. I need a mechanism to figure out that I need to install both libmy1.so and libmy2.so along myprog.

推荐答案

最优雅的解决方案如下。必须使用安装命令将每个安装目标分配给一个组件。例如,在问题中,可能是这样的:

The most elegant solution seems to be the following. One has to use the CMake COMPONENT parameter of the install command to assign each install target to a component. For example in the question this would be something like this:

install(TARGETS myprog DESTINATION ${BIN_DEST_DIR} COMPONENT myprog),

以及类似的共享库

install(TARGETS my1 my2 DESTINATION ${LIB_DEST_DIR} COMPONENT my-libs).

现在,调用 myprog 的安装以及 mylib1 mylib2 ,必须创建使用 cmake_install的自定义目标。 cmake 定位在构建树中:

Now, to invoke the installation of myprog as well as mylib1 and mylib2 a custom target has to be created that uses the cmake_install.cmake locate in the build tree:

add_custom_target(install-myprog
   COMMAND ${CMAKE_COMMAND} -DCOMPONENT=my-libs -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
   COMMAND ${CMAKE_COMMAND} -DCOMPONENT=myprog -P ${CMAKE_BINARY_DIR}/cmake_install.cmake
   COMMENT "Installing myprog").

这篇关于cmake:弄清楚哪些库是链接到的二进制目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆