Replacing values in CMake lists - Stack Overflow
stackoverflow.com › questions › 3307789Jul 22, 2010 · If you want to replace an item by value in the list, you can do like the following code: macro(replace_list_item LIST OLD_VALUE NEW_VALUE) list(FIND ${LIST} ${OLD_VALUE} OLD_VALUE_INDEX) if(OLD_VALUE_INDEX GREATER_EQUAL 0) list(REMOVE_AT ${LIST} ${OLD_VALUE_INDEX}) list(INSERT ${LIST} ${OLD_VALUE_INDEX} ${NEW_VALUE}) endif() endmacro()
CMake Lists - Jeremi Mucha
jeremimucha.com › 2021 › 03Mar 15, 2021 · Transform supports regular expressions so it is quite powerful. A super simple useless example follows. set(foobar 1 " 2A" 3 "4B " 5 6C) list(TRANSFORM foobar STRIP) # remove whitespace list(TRANSFORM foobar TOLOWER) # to lower case list(TRANSFORM foobar REPLACE "([0-9])([a-z])" "\\2\\1\\2" REGEX "[0-9][a-z]") This results in the following
cmake Tutorial => Strings and Lists
riptutorial.com › cmake › exampleExample. It's important to know how CMake distinguishes between lists and plain strings. When you write: set(VAR "a b c") you create a string with the value "a b c". But when you write this line without quotes: set(VAR a b c) You create a list of three items instead: "a", "b" and "c". Non-list variables are actually lists too (of a single element).
list — CMake 3.23.0-rc4 Documentation
cmake.org › cmake › helpA list in cmake is a ; separated group of strings. To create a list the set command can be used. For example, set (var a b c d e) creates a list with a;b;c;d;e, and set (var "a b c d e") creates a string or a list with one item in it. (Note macro arguments are not variables, and therefore cannot be used in LIST commands.)
string — CMake 3.23.0-rc3 Documentation
cmake.org › cmake › helpCMake language Escape Sequences such as \t, \r, , and \\ may be used to construct literal tabs, carriage returns, newlines, and backslashes (respectively) to pass in a regex. For example: The quoted argument "[\t\r ]" specifies a regex that matches any single whitespace character.
string
http://man.hubwiz.com › commandSearch and Replace string(FIND <string> <substring> <out-var> [. ... as many times as possible and store the matches in the output variable as a list.
Replace an item in a list with cmake (Example)
coderwall.com › p › p5v7vwFeb 25, 2016 · Replace an item in a list with cmake. #cmake. #fml. 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)
list — CMake 3.23.0-rc4 Documentation
https://cmake.org/cmake/help/latest/command/list.htmlNote. When specifying index values, if <element index> is 0 or greater, it is indexed from the beginning of the list, with 0 representing the first list element. If <element index> is -1 or lesser, it is indexed from the end of the list, with -1 representing the last list element. Be careful when counting with negative indices: they do not start from 0. -0 is equivalent to 0, the first list elem
[CMake] CMake is Converting lists to strings
cmake.org › pipermail › cmakeThe right way to use it to avoid list conversion is to expand the list inside quotes (to preserve list items separators): STRING (REPLACE "../" "" SIMPLE_LIST "${SIMPLE_LIST}") Without the quotes, all list elements are concatenated in the result string (see documentation). Another possibility is using LIST(TRANSFORM …):