[CMake] Library target names and the ExternalProject_Add command

Nicholas Braden nicholas11braden at gmail.com
Mon Jan 25 20:13:26 EST 2016


ExternalProject makes no assumptions about what is being built. It
could just be a collection of executables, or maybe nothing is built
at all. It is up to the project being built to provide facilities for
accessing its targets in a platform-independent way. For example, the
external project can install an export file that you can include to
get the imported targets. Or, it could have a traditional
FindXXX.cmake script that you can use. Either way, ExternalProject
doesn't know about any of that - it just downloads and builds stuff.

Alternatively, you could include the external library as part of your
project and use add_subdirectory to just build it with the rest of
your project, thus giving you direct access to the targets you want.

On Mon, Jan 25, 2016 at 4:22 AM, Cedric Doucet <cedric.doucet at inria.fr> wrote:
>
> 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
>
>
> --
>
> Powered by www.kitware.com
>
> Please keep messages on-topic and check the CMake FAQ at:
> http://www.cmake.org/Wiki/CMake_FAQ
>
> Kitware offers various services to support the CMake community. For more
> information on each offering, please visit:
>
> CMake Support: http://cmake.org/cmake/help/support.html
> CMake Consulting: http://cmake.org/cmake/help/consulting.html
> CMake Training Courses: http://cmake.org/cmake/help/training.html
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Follow this link to subscribe/unsubscribe:
> http://public.kitware.com/mailman/listinfo/cmake


More information about the CMake mailing list