[CMake] intercomponent link dependencies?

Ryan Pavlik rpavlik at iastate.edu
Thu Jan 7 20:24:19 EST 2010


On Thu, Jan 7, 2010 at 4:00 PM, Jed Brown <jed at 59a2.org> wrote:

> On Thu, 07 Jan 2010 15:54:33 -0600, Ryan Pavlik <rpavlik at iastate.edu>
> wrote:
> > If you use the _LIBRARIES variable, you don't need to even mess around
> > with the imported targets thing
>
> Dumping recursive dependencies in *_LIBRARIES causes overlinking, they
> should only be there when linking statically.
>
> Jed
>

So then actually should we all be doing imported targets in our find modules
then?  I didn't realize it: most of the ones I looked at that come with
cmake didn't use it, so I just worked around it - wrote a function that can
safely remove those dupes instead :)

Is there any drawback (besides slightly longer code) to doing the imported
targets route?

Here's that CleanLibraryList.cmake file:


# - A smarter replacement for list(REMOVE_DUPLICATES) for library lists
#
#  clean_library_list(<listvar> [<additional list items>...]) - where
#  WHATEVER_LIBRARIES is the name of a variable, such as a variable being
#  created in a Find script.
#
# Removes duplicates from the list then sorts while preserving "optimized",
# "debug", and "general" labeling
#
# Requires CMake 2.6 or newer (uses the 'function' command)
#
# Original Author:
# 2009-2010 Ryan Pavlik <rpavlik at iastate.edu> <abiryan at ryand.net>
# http://academic.cleardefinition.com
# Iowa State University HCI Graduate Program/VRAC

function(clean_library_list _var)
    # combine variable's current value with additional list items
    set(_work ${${_var}} ${ARGN})
    if(_work)
        # Turn each of optimized, debug, and general into flags
        # prefixed on their respective library (combining list items)
        string(REGEX REPLACE "optimized;" "1CLL%O%" _work "${_work}")
        string(REGEX REPLACE "debug;" "1CLL%D%" _work "${_work}")
        string(REGEX REPLACE "general;" "1CLL%G%" _work "${_work}")

        # clean up list
        list(REMOVE_DUPLICATES _work)
        list(SORT _work)

        # Split list items back out again: turn prefixes into the
        # library type flags.
        string(REGEX REPLACE "1CLL%G%" "general;" _work "${_work}")
        string(REGEX REPLACE "1CLL%D%" "debug;" _work "${_work}")
        string(REGEX REPLACE "1CLL%O%" "optimized;" _work "${_work}")

        # Return _work
        set(${_var} ${_work} PARENT_SCOPE)
    endif()
endfunction()


-- 
Ryan Pavlik
HCI Graduate Student
Virtual Reality Applications Center
Iowa State University

rpavlik at iastate.edu
http://academic.cleardefinition.com
Internal VRAC/HCI Site: http://tinyurl.com/rpavlik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20100107/c54f066f/attachment.htm>


More information about the CMake mailing list