Hello. I needed to replace a value in a CMake list, however there does not seem to be any support for this list operation.
I've come up with this code:
macro (LIST_REPLACE LIST INDEX NEWVALUE)
list (REMOVE_AT ${LIST} ${INDEX})
list (LENGTH ${LIST} __length)
# Cannot insert at the end
if (${__length} EQUAL ${INDEX})
list (APPEND ${LIST} ${NEWVALUE})
else (${__length} EQUAL ${INDEX})
list (INSERT ${LIST} ${INDEX} ${NEWVALUE})
endif (${__length} EQUAL ${INDEX})
endmacro (LIST_REPLACE)
# Example
set (fubar A;B;C)
LIST_REPLACE (fubar 2 "X")
message (STATUS ${fubar})
Do you have any better idea how to achieve that?