Broes De Cat
Broes De Cat

Reputation: 554

Using cmake, how to link an object file built by an external_project statement into another library?

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!

Upvotes: 5

Views: 5991

Answers (1)

Fraser
Fraser

Reputation: 78300

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})

Upvotes: 4

Related Questions