[CMake] List all binaries associated with a target.

Klaim - Joël Lamotte mjklaim at gmail.com
Sun Mar 15 10:43:04 EDT 2015


On Sat, Mar 14, 2015 at 9:51 PM, Roman Bolshakov <roolebo at gmail.com> wrote:

> Here's an example function which addresses 1.
> It creates a string of generator expressions for direct and indirect
> dependencies of a target recursively.
> When all recursive invocations are done, it spits <target-name>-deps
> file in the CURRENT_BINARY_DIR which contains full paths of the
> dependencies:
>
> function(store_dependencies LIB)
>   if(NOT TARGET ${LIB})
>     message(FATAL_ERROR "You have to pass valid target")
>   endif()
>   # Do not add location for the top-most invocation
>   if (ARGV1)
>     set(ORIGINAL_LIB ${ARGV1})
>     set_property(TARGET ${ORIGINAL_LIB} APPEND_STRING PROPERTY
> DEPENDENCY_LIST "$<TARGET_FILE:${LIB}> ")
>   else()
>     set(ORIGINAL_LIB ${LIB})
>   endif()
>
>   # init dependency list with direct dependencies
>   get_property(DEPENDENCIES TARGET ${LIB} PROPERTY LINK_LIBRARIES)
>   # We're not intersted in interface link libraries of the top-most target
>   if (ARGV1)
>      get_property(INTERFACE_LINK_LIBRARIES TARGET ${LIB} PROPERTY
> INTERFACE_LINK_LIBRARIES)
>      list(APPEND DEPENDENCIES ${INTERFACE_LINK_LIBRARIES})
>   endif()
>
>   if (DEPENDENCIES)
>     list(REMOVE_DUPLICATES DEPENDENCIES)
>     # message (STATUS "${LIB} dependens on ${DEPENDENCIES}")
>   endif()
>
>   foreach(DEPENDENCY ${DEPENDENCIES})
>     store_dependencies(${DEPENDENCY} "${ORIGINAL_LIB}")
>   endforeach()
>
>   # Store list of gathered dependencies for the top-most call only
>   if (NOT ARGV1)
>     get_property(DEPENDENCY_LIST TARGET d PROPERTY DEPENDENCY_LIST)
>     file(GENERATE OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${LIB}-deps
> CONTENT "${DEPENDENCY_LIST}")
>   endif()
> endfunction()
>
>
Very interesting, thank you very much. I will try that.


> I'm not sure how to achieve 2. during CMake configuration phase though
> as all generator expression are expanded later during build generation
> phase. But you might copy the files during build phase. You can create
> custom commands which use content of the generated file.
>
>
Yes I was not clear but I was thinking about build time.
I got this part covered.


> I don't get what exactly you're trying to achieve in 3. In general I
> wouldn't encourage to copy binaries during build phase unless you have
> a very solid reason. FWIW there's install(TARGET) command for
> installation and packaging.
>
>
I'm not totally sure install() does exactly what I need.
My use case is that I need to debug each executable in an installed-like
context (with data), which imply that each time it is compiled it should be
installed too.
Actually 2 and 3 are the same, I just put the files in a specific place in
the
build directory so that it looks like installed, but I do this when the
binary is
built so that it's always up to date while debugging.
Now, I use post-build command (add_custom_command) to do this indeed
but I didn't find a way yet to trigger install() a specific binary on
post-build yet,
but I suppose I just missed it so far.


> Roman
>
> 2015-03-14 4:24 GMT+03:00 Klaim - Joël Lamotte <mjklaim at gmail.com>:
> > I am looking for a (hopefully simple) way to do the following:
> > 1. gather a list of paths of all the binaries associated with a target,
> >     that is all the linked dll/so and executable the target link or
> depend
> > on.
> > 2. copy these somewhere else.
> > 3. take into account the build modes so that the right binaries are
> copied
> > for
> >     each of the target build mode.
> >
> > I can't find a way to do 1 so far without manually specifying the
> > dependencies.
> > It looks like the generators expressions can't gather these info.
> > So is there a way to retrieve this list in current CMake features?
> > Did I miss something?
> >
> > Thanks for your time.
> >
> >
> >
> > --
> >
> > 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
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150315/8271fcb5/attachment-0001.html>


More information about the CMake mailing list