5

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!

Broes De Cat
  • 536
  • 5
  • 14

1 Answers1

4

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})
Fraser
  • 74,704
  • 20
  • 238
  • 215
  • Thanks a lot, perfect answer! (I did not intend to write effective cmake code, but maybe that would have been clearer ;) ) – Broes De Cat Mar 15 '13 at 07:54
  • @RaulLuna In the original question, the OP has mentioned that there's an object file which he's called "B" - I'm assuming it's defined as a variable earlier in the CMakeLists.txt – Fraser Jul 29 '17 at 22:26