我为我的CMAKE项目设置了以下设置:
add_executable(exeA ${SOURCES})
target_link_libraries(exeA PRIVATE libB)
libb
是A static 库在另一个项目中分别构建,并取决于共享 libraries LIBC
或 libd
提供等效的API,但以不同的方式实现并具有不同的性能配置文件。
在 exea
的构建中,我希望能够根据条件链接 libc
libd 。
从阅读,看来我可以使用 rpath
相关的cmake属性,但是我是否可以使用这些属性来设置现有静态库的rpath
不幸的是,没有简单而快速的方法来改变一个
现有可执行文件或共享库。
在Cmake中可以做类似的事情吗?
感谢任何解决此用例的建议。
I have the following setup for my CMake project:
add_executable(exeA ${SOURCES})
target_link_libraries(exeA PRIVATE libB)
libB
is a static library built separately in a different project and depends on shared libraries libC
OR libD
which provide equivalent API's but implemented differently and have different performance profiles.
In exeA
's build I want to be able to link against either of libC
or libD
depending on a condition.
From reading RPATH handling, it seems I could use RPATH
related CMake properties, however its unclear if I can use these properties to set the RPATH of an existing static library
Unfortunately there is no easy and fast way to change the RPATH of an
existing executable or shared library.
Is something like this possible to do in CMake?
Appreciate any recommendations to handle this use case.
发布评论
评论(1)
为
libb
和共享导入
共享导入 libclibd
libd libd libd libd libd libd libd 。将相关的一个放在Interface_link_libraries
libb
的属性中。构建EXEA
时,Cmake将正确设置RPATH。您可以使用类似虚拟文件进行测试:
如您所见,
rpath
已正确设置为包含libc.so
的目录。Create a
STATIC IMPORTED
library forlibB
andSHARED IMPORTED
libraries forlibC
andlibD
. Put the relevant one in theINTERFACE_LINK_LIBRARIES
property oflibB
. CMake will set the RPATH correctly whenexeA
is built.You can test this out with dummy files like so:
As you can see, the
RPATH
is set correctly to the directory containinglibC.so
.