[CMake] PROPERTY for list of link libraries

Tom Kacvinsky tom.kacvinsky at vectorcast.com
Fri Jan 22 10:19:52 EST 2016


On Fri, Jan 22, 2016 at 9:23 AM, Tom Kacvinsky
<tom.kacvinsky at vectorcast.com> wrote:
> I have need for a cross platform methods of getting libraries linked
> into an executable.
>
> Say for instance, we have
>
> add_library(foo STATIC a.c)
> add_exceutable(bar b.c)
> target_link_libraries(bar foo)
>
> So I know for that bar has a dependency on foo.lib (on Windows) and
> libfoo.a on Linux.
>
> And so forth.  What I would like to do is after everything is set up,
> query the properties of bar
> and find the list of libraries linked into bar in such a fashion I get
> that platform's specific library name (instead of the library's target
> name).
>
> IS this possible?  I read the docs and didn't see a property for
> getting this list.  Did I miss something?  If so I plan on using
> either get_property of get_target_property.
>
> Thanks.

Answering my own question

get_property(libs TARGET a_target PROPERTY LINK_LIBRARIES)
foreach(lib ${libs})
  if(TARGET ${lib})
    get_property(path TARGET ${lib} PROPERTY LOCATION)
    message(STATUS ${path})
  else()
    message(STATUS ${lib})
  endif()
endforeach()


More information about the CMake mailing list