Last Updated: February 25, 2016
·
2.908K
· typpo

Replace an item in a list with cmake

To replace string in a list of strings:

list(FIND ${MYLIST} "foo bar search string" ${find_idx})                                    
if(find_idx GREATER -1)                                                    
  LIST_REPLACE(MYLIST ${find_idx} "my replace string")                   
endif()                      

depends on this macro:

macro(LIST_REPLACE LIST INDEX NEWVALUE)
    list(INSERT ${LIST} ${INDEX} ${NEWVALUE})
    MATH(EXPR __INDEX "${INDEX} + 1")
    list (REMOVE_AT ${LIST} ${__INDEX})
endmacro(LIST_REPLACE)