1# - A smarter replacement for list(REMOVE_DUPLICATES) for library lists 2# 3# Note that, in the case of cyclic link dependencies, you _do_ actually need 4# a library in a list multiple times. So, only use this function when you know 5# that the dependency graph is acyclic. 6# 7# clean_library_list(<listvar> [<additional list items>...]) - where 8# listvar is the name of a destination variable, and also possibly a source, and 9# it is followed by any number (including 0) of additional libraries to append 10# to the list before processing. 11# 12# Removes duplicates from the list, leaving only the last instance, while 13# preserving the meaning of the "optimized", "debug", and "general" labeling. 14# (Libraries listed as general are listed in the result instead as optimized and 15# debug) 16# 17# Requires CMake 2.6 or newer (uses the 'function' command) 18# 19# Original Author: 20# 2009-2010 Ryan Pavlik <rpavlik@iastate.edu> <abiryan@ryand.net> 21# http://academic.cleardefinition.com 22# Iowa State University HCI Graduate Program/VRAC 23# 24# Copyright Iowa State University 2009-2010. 25# Distributed under the Boost Software License, Version 1.0. 26# (See accompanying file LICENSE_1_0.txt or copy at 27# http://www.boost.org/LICENSE_1_0.txt) 28 29if(__clean_library_list) 30 return() 31endif() 32set(__clean_library_list YES) 33 34function(clean_library_list _var) 35 # combine variable's current value with additional list items 36 set(_work ${${_var}} ${ARGN}) 37 if(_work) 38 # Turn each of optimized, debug, and general into flags 39 # prefixed on their respective library (combining list items) 40 string(REGEX REPLACE "optimized;" "1CLL%O%" _work "${_work}") 41 string(REGEX REPLACE "debug;" "1CLL%D%" _work "${_work}") 42 string(REGEX REPLACE "general;" "1CLL%G%" _work "${_work}") 43 44 # Any library that doesn't have a prefix is general, and a general 45 # library is both debug and optimized so stdize it 46 set(_std) 47 foreach(_lib ${_work}) 48 if(NOT "${_lib}" MATCHES "^1CLL%.%") 49 list(APPEND _std "1CLL%D%${_lib}" "1CLL%O%${_lib}") 50 elseif("${_lib}" MATCHES "^1CLL%G%") 51 string(REPLACE "1CLL%G%" "" _justlib "${_lib}") 52 list(APPEND _std "1CLL%D%${_justlib}" "1CLL%O%${_justlib}") 53 else() 54 list(APPEND _std "${_lib}") 55 endif() 56 endforeach() 57 58 # REMOVE_DUPLICATES leaves the first - so we reverse before and after 59 # to keep the last, instead 60 list(REVERSE _std) 61 list(REMOVE_DUPLICATES _std) 62 list(REVERSE _std) 63 64 # Split list items back out again: turn prefixes into the 65 # library type flags. 66 string(REGEX REPLACE "1CLL%D%" "debug;" _std "${_std}") 67 string(REGEX REPLACE "1CLL%O%" "optimized;" _std "${_std}") 68 69 # Return _std 70 set(${_var} ${_std} PARENT_SCOPE) 71 endif() 72endfunction() 73