[Cmake] uniqueing macro/remove double entries from vector

Iker Arizmendi iker at research.att.com
Fri Jun 11 23:44:14 EDT 2004


You may find the following macros useful. Instead of
creating lists using the usual:

     SET(SOME_LIST ${SOME_LIST} newVal)

use the following:

     LIST_APPEND_UNIQUE(SOME_LIST newVal)

which will only append newVal if it isn't already in
the list. I also use the LIST_PREPEND and LIST_APPEND
macros for regularity.

Regards,
Iker


# ===================================
# List handling macros
# ===================================

MACRO(LIST_PREPEND var value)
     SET(${var} ${value} ${${var}})
ENDMACRO(LIST_PREPEND)

MACRO(LIST_PREPEND_UNIQUE var value)
     SET(LIST_ADD_UNIQUE_FLAG 0)
     FOREACH(i ${${var}})
         IF ("${i}" MATCHES "${value}")
             SET(LIST_ADD_UNIQUE_FLAG 1)
         ENDIF("${i}" MATCHES "${value}")
     ENDFOREACH(i)
     IF(NOT LIST_ADD_UNIQUE_FLAG)
         SET(${var} ${value} ${${var}})
     ENDIF(NOT LIST_ADD_UNIQUE_FLAG)
ENDMACRO(LIST_PREPEND_UNIQUE)

MACRO(LIST_APPEND var value)
     SET(${var} ${${var}} ${value})
ENDMACRO(LIST_APPEND)

MACRO(LIST_APPEND_UNIQUE var value)
     SET(LIST_ADD_UNIQUE_FLAG 0)
     FOREACH(i ${${var}})
         IF ("${i}" MATCHES "${value}")
             SET(LIST_ADD_UNIQUE_FLAG 1)
         ENDIF("${i}" MATCHES "${value}")
     ENDFOREACH(i)
     IF(NOT LIST_ADD_UNIQUE_FLAG)
         SET(${var} ${${var}} ${value})
     ENDIF(NOT LIST_ADD_UNIQUE_FLAG)
ENDMACRO(LIST_APPEND_UNIQUE)


Jan Woetzel wrote:
> Hi,
> I want to remove my double entries from my collection of INC and LIB 
> directores to beautify my PackageConfig.cmake
> 
> Has anybody a "uniqueing" MACRO at hand (or a better solution) ?
> 
> E.g.
> /include/Foo
> /include/Bar
> /include/Foo
> 
> should become:
> /include/Foo
> /include/Bar
> 
> 
> Best regards,
> Jan.
> 
> 
> _______________________________________________
> Cmake mailing list
> Cmake at www.cmake.org
> http://www.cmake.org/mailman/listinfo/cmake
> 

-- 
Iker Arizmendi
AT&T Labs - Research
Speech and Image Processing Lab
e: iker at research.att.com
w: http://research.att.com




More information about the Cmake mailing list