[CMake] Library target names and the ExternalProject_Add command

Cedric Doucet cedric.doucet at inria.fr
Mon Jan 25 05:22:05 EST 2016


Hello,

I use the ExternalProject_Add command to download and build a static library called 'foo.a'.
I build another library 'bar' which depends on 'foo.a'.

For the moment, I use the target_link_libraries command to create a link between foo and bar:

    target_link_libraries(bar ${FOO_INSTALL_DIR}/lib/foo.a)
However, this approach is not portable, especially if I want foo to be a shared library.
Indeed, the extension of such libraries is plateform dependent.

Therefore, I tried to replace the path to foo by its name 'foo' from the call to the ExternalProject_Add command:

    target_link_libraries(bar foo)
However, it does not work and I get the following error message:

    Target "foo" of type UTILITY may not be linked into another target.
    One may link only to STATIC or SHARED libraries, or to executables with the
    ENABLE_EXPORTS property set.

I guess I understand that foo has the wrong type UTILITY and it would work only if I had defined my target like this:
  
    add_library(foo blablabla)

However, I need to use the ExternalProject_Add command.

Is there a way to create a library target name 'foo' in this case?

Thank you!

Cédric

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20160125/cb5f9d63/attachment.html>


More information about the CMake mailing list