使用cmake,如何将由external_project语句构建的对象文件链接到另一个库? [英] Using cmake, how to link an object file built by an external_project statement into another library?

查看:447
本文介绍了使用cmake,如何将由external_project语句构建的对象文件链接到另一个库?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我们的项目中,我们想要使用第三方库(A),它使用自动工具构建,并生成一个对象文件(B),我们需要一个我们的库(C)的@链接时间。 p>

  external_project(
A
...

set_source_files_properties A)
add_library(C ... A)
add_dependency(CB)

我有一个印象,这应该做的伎俩,但cmake命令失败,说明它在检查add_library期间找不到文件A.



任何修复或替代解决方案将非常感谢! (更改第三方库不是一个选项)
感谢!

解决方案

这里有几个问题:




  • external_project 应为 ExternalProject_Add

  • 源文件没有名为 DEPEND 的属性可用 - set_source_files_properties 命令在此无效。 (以下是源文件上的属性) / li>
  • add_library 期望传递源文件列表,而不是另一个CMake目标( A

  • add_dependency 应为 add_dependencies



除了那些4行,它是OK: - )



所以问题是你想包括对象文件 B在 add_library 调用中的,但是它不会在configure-time(当CMake被调用时) p>

我想你将要做如下事情:

  ExternalProject_Add(
A
...


set_source_files_properties(
$ {B} PROPERTIES
EXTERNAL_OBJECT TRUE#标识为对象文件
GENERATED TRUE#在配置时不需要文件存在


add_library(C ... $ {B})


In our project, we want to use a third-party library (A) which is built using autotools and which generates an object file (B) which we need @ link time of one of our libraries (C).

external_project(
    A
    ...
)
set_source_files_properties(B PROPERTIES DEPEND A)
add_library(C ... A)
add_dependency(C B)

I had the impression that this should do the trick, but the cmake command fails by stating that it cannot find file A during the check for add_library.

Any fixes or alternative solutions would be greatly appreciated! (changing the third-party library is not an option) thanks!

解决方案

There are a few issues here:

Apart from those 4 lines it's all OK :-)

So the issue is going to be that you want to include the object file B in the add_library call, but it's not going to be available at configure-time (when CMake is invoked), only at build time.

I think you're going to have to do something like:

ExternalProject_Add(
    A
    ...
)

set_source_files_properties(
    ${B} PROPERTIES
    EXTERNAL_OBJECT TRUE  # Identifies this as an object file
    GENERATED TRUE  # Avoids need for file to exist at configure-time
)

add_library(C ... ${B})

这篇关于使用cmake,如何将由external_project语句构建的对象文件链接到另一个库?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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