CMakeMacroFilterOut: Difference between revisions

From KitwarePublic
Jump to navigationJump to search
(Add explicit preformat markup)
(Remove leading space rectangles from preformatted blocks)
Line 6: Line 6:


<pre>
<pre>
list(REMOVE_ITEM <list> <value> [<value> ...])
list(REMOVE_ITEM <list> <value> [<value> ...])
 
SET(MYLIST this that and the other)
SET(MYLIST this that and the other)
# remove "this" and "that"
# remove "this" and "that"
LIST(REMOVE_ITEM MYLIST this)
LIST(REMOVE_ITEM MYLIST this)
LIST(REMOVE_ITEM MYLIST that)
LIST(REMOVE_ITEM MYLIST that)
</pre>
</pre>


-----
-----
<pre>
<pre>
    MACRO(FILTER_OUT FILTERS INPUTS OUTPUT)
MACRO(FILTER_OUT FILTERS INPUTS OUTPUT)
        # Mimicks Gnu Make's $(filter-out) which removes elements  
    # Mimicks Gnu Make's $(filter-out) which removes elements  
        # from a list that match the pattern.
    # from a list that match the pattern.
        # Arguments:
    # Arguments:
        #  FILTERS - list of patterns that need to be removed
    #  FILTERS - list of patterns that need to be removed
        #  INPUTS  - list of inputs that will be worked on
    #  INPUTS  - list of inputs that will be worked on
        #  OUTPUT  - the filtered list to be returned
    #  OUTPUT  - the filtered list to be returned
        #  
    #  
        # Example:  
    # Example:  
        #  SET(MYLIST this that and the other)
    #  SET(MYLIST this that and the other)
        #  SET(FILTS this that)
    #  SET(FILTS this that)
        #
    #
        #  FILTER_OUT("${FILTS}" "${MYLIST}" OUT)
    #  FILTER_OUT("${FILTS}" "${MYLIST}" OUT)
        #  MESSAGE("OUTPUT = ${OUT}")
    #  MESSAGE("OUTPUT = ${OUT}")
        #
    #
        # The output -  
    # The output -  
        #  OUTPUT = and;the;other
    #  OUTPUT = and;the;other
        #
    #
        SET(FOUT "")
    SET(FOUT "")
        FOREACH(INP ${INPUTS})
    FOREACH(INP ${INPUTS})
            SET(FILTERED 0)
        SET(FILTERED 0)
            FOREACH(FILT ${FILTERS})
        FOREACH(FILT ${FILTERS})
                IF(${FILTERED} EQUAL 0)
                    IF("${FILT}" STREQUAL "${INP}")
                        SET(FILTERED 1)
                    ENDIF("${FILT}" STREQUAL "${INP}")
                ENDIF(${FILTERED} EQUAL 0)
            ENDFOREACH(FILT ${FILTERS})
             IF(${FILTERED} EQUAL 0)
             IF(${FILTERED} EQUAL 0)
                 SET(FOUT ${FOUT} ${INP})
                 IF("${FILT}" STREQUAL "${INP}")
                    SET(FILTERED 1)
                ENDIF("${FILT}" STREQUAL "${INP}")
             ENDIF(${FILTERED} EQUAL 0)
             ENDIF(${FILTERED} EQUAL 0)
         ENDFOREACH(INP ${INPUTS})
         ENDFOREACH(FILT ${FILTERS})
        SET(${OUTPUT} ${FOUT})
        IF(${FILTERED} EQUAL 0)
    ENDMACRO(FILTER_OUT FILTERS INPUTS OUTPUT)
            SET(FOUT ${FOUT} ${INP})
        ENDIF(${FILTERED} EQUAL 0)
    ENDFOREACH(INP ${INPUTS})
    SET(${OUTPUT} ${FOUT})
ENDMACRO(FILTER_OUT FILTERS INPUTS OUTPUT)
</pre>
</pre>



Revision as of 21:04, 20 April 2018

Back

CAUTION: The contents of this page may be obsolete
120px-Old finnish stop sign.svg.png

NOTE: This macro is obsolete by built-in support in CMake for removing list elements with the LIST command:

list(REMOVE_ITEM <list> <value> [<value> ...])

SET(MYLIST this that and the other)
# remove "this" and "that"
LIST(REMOVE_ITEM MYLIST this)
LIST(REMOVE_ITEM MYLIST that)

MACRO(FILTER_OUT FILTERS INPUTS OUTPUT)
    # Mimicks Gnu Make's $(filter-out) which removes elements 
    # from a list that match the pattern.
    # Arguments:
    #  FILTERS - list of patterns that need to be removed
    #  INPUTS  - list of inputs that will be worked on
    #  OUTPUT  - the filtered list to be returned
    # 
    # Example: 
    #  SET(MYLIST this that and the other)
    #  SET(FILTS this that)
    #
    #  FILTER_OUT("${FILTS}" "${MYLIST}" OUT)
    #  MESSAGE("OUTPUT = ${OUT}")
    #
    # The output - 
    #   OUTPUT = and;the;other
    #
    SET(FOUT "")
    FOREACH(INP ${INPUTS})
        SET(FILTERED 0)
        FOREACH(FILT ${FILTERS})
            IF(${FILTERED} EQUAL 0)
                IF("${FILT}" STREQUAL "${INP}")
                    SET(FILTERED 1)
                ENDIF("${FILT}" STREQUAL "${INP}")
            ENDIF(${FILTERED} EQUAL 0)
        ENDFOREACH(FILT ${FILTERS})
        IF(${FILTERED} EQUAL 0)
            SET(FOUT ${FOUT} ${INP})
        ENDIF(${FILTERED} EQUAL 0)
    ENDFOREACH(INP ${INPUTS})
    SET(${OUTPUT} ${FOUT})
ENDMACRO(FILTER_OUT FILTERS INPUTS OUTPUT)

Back



CMake: [Welcome | Site Map]