CMakeMacroMerge: Difference between revisions

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


<pre>
<pre>
set(FIRST_LIST  a b c d i j k l)
set(FIRST_LIST  a b c d i j k l)
set(SECOND_LIST e f g h m n o p)
set(SECOND_LIST e f g h m n o p)
set(COMPLETE_LIST ${FIRST_LIST} ${SECOND_LIST})
set(COMPLETE_LIST ${FIRST_LIST} ${SECOND_LIST})
list(SORT COMPLETE_LIST)
list(SORT COMPLETE_LIST)
# you can also remove duplicates
# you can also remove duplicates
list(REMOVE_DUPLICATES COMPLETE_LIST)
list(REMOVE_DUPLICATES COMPLETE_LIST)
</pre>
</pre>
----
----
Line 16: Line 16:


<pre>
<pre>
    # This macro merges elements in sorted lists ALIST and BLIST and stored the result in OUTPUT
# This macro merges elements in sorted lists ALIST and BLIST and stored the result in OUTPUT
    MACRO(MERGE ALIST BLIST OUTPUT)
MACRO(MERGE ALIST BLIST OUTPUT)
    SET(BTEMP ${BLIST})
SET(BTEMP ${BLIST})
    FOREACH(A ${ALIST})
FOREACH(A ${ALIST})
        SET(SORTED)
    SET(SORTED)
        SET(UNINSERTED 1)
    SET(UNINSERTED 1)
        FOREACH(B ${BTEMP})
    FOREACH(B ${BTEMP})
            IF(${UNINSERTED})
                IF(${A} STRLESS ${B})
                    SET(SORTED ${SORTED} ${A})
                    SET(UNINSERTED 0)
                ENDIF(${A} STRLESS ${B})
            ENDIF(${UNINSERTED})
            SET(SORTED ${SORTED} ${B})
        ENDFOREACH(B ${BLIST})
         IF(${UNINSERTED})
         IF(${UNINSERTED})
             SET(SORTED ${SORTED} ${A})
             IF(${A} STRLESS ${B})
                SET(SORTED ${SORTED} ${A})
                SET(UNINSERTED 0)
            ENDIF(${A} STRLESS ${B})
         ENDIF(${UNINSERTED})
         ENDIF(${UNINSERTED})
         SET(BTEMP ${SORTED})
         SET(SORTED ${SORTED} ${B})
    ENDFOREACH(A ${ALIST})
    ENDFOREACH(B ${BLIST})
    SET(${OUTPUT} ${BTEMP})
    IF(${UNINSERTED})
    ENDMACRO(MERGE ALIST BLIST OUTPUT)
        SET(SORTED ${SORTED} ${A})
   
    ENDIF(${UNINSERTED})
    # Here is an example that merges *.cpp files and *.h files into a single sorted list
    SET(BTEMP ${SORTED})
    # This would be easier if FILE(GLOB...) properly matches "*.{cpp,h}"
ENDFOREACH(A ${ALIST})
    FILE(GLOB ALGEBRAIC_SRCS Implicit/Algebraic/*.cpp)
SET(${OUTPUT} ${BTEMP})
    FILE(GLOB ALGEBRAIC_H Implicit/Algebraic/*.h)
ENDMACRO(MERGE ALIST BLIST OUTPUT)
    MERGE("${ALGEBRAIC_H}" "${ALGEBRAIC_SRCS}" ALGEBRAIC_SRCS)
 
# Here is an example that merges *.cpp files and *.h files into a single sorted list
# This would be easier if FILE(GLOB...) properly matches "*.{cpp,h}"
FILE(GLOB ALGEBRAIC_SRCS Implicit/Algebraic/*.cpp)
FILE(GLOB ALGEBRAIC_H Implicit/Algebraic/*.h)
MERGE("${ALGEBRAIC_H}" "${ALGEBRAIC_SRCS}" ALGEBRAIC_SRCS)
</pre>
</pre>



Revision as of 21:04, 20 April 2018

Back

NOTE: You can merge and sort lists using the SET() and LIST() command and no longer need this macro.

set(FIRST_LIST  a b c d i j k l)
set(SECOND_LIST e f g h m n o p)
set(COMPLETE_LIST ${FIRST_LIST} ${SECOND_LIST})
list(SORT COMPLETE_LIST)
# you can also remove duplicates
list(REMOVE_DUPLICATES COMPLETE_LIST)

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

# This macro merges elements in sorted lists ALIST and BLIST and stored the result in OUTPUT
MACRO(MERGE ALIST BLIST OUTPUT)
SET(BTEMP ${BLIST})
FOREACH(A ${ALIST})
    SET(SORTED)
    SET(UNINSERTED 1)
    FOREACH(B ${BTEMP})
        IF(${UNINSERTED})
            IF(${A} STRLESS ${B})
                SET(SORTED ${SORTED} ${A})
                SET(UNINSERTED 0)
            ENDIF(${A} STRLESS ${B})
        ENDIF(${UNINSERTED})
        SET(SORTED ${SORTED} ${B})
    ENDFOREACH(B ${BLIST})
    IF(${UNINSERTED})
        SET(SORTED ${SORTED} ${A})
    ENDIF(${UNINSERTED})
    SET(BTEMP ${SORTED})
ENDFOREACH(A ${ALIST})
SET(${OUTPUT} ${BTEMP})
ENDMACRO(MERGE ALIST BLIST OUTPUT)

# Here is an example that merges *.cpp files and *.h files into a single sorted list
# This would be easier if FILE(GLOB...) properly matches "*.{cpp,h}"
FILE(GLOB ALGEBRAIC_SRCS Implicit/Algebraic/*.cpp)
FILE(GLOB ALGEBRAIC_H Implicit/Algebraic/*.h)
MERGE("${ALGEBRAIC_H}" "${ALGEBRAIC_SRCS}" ALGEBRAIC_SRCS)

Back



CMake: [Welcome | Site Map]