I want to remove specific libraries from a CMake variable.
Suppose LIB
contains the value of the variables "A;B;C",
I know use set
to add the comtent of another variable "D" like this
set(LIB ${LIB};D)
However I tried to remove "C" from LIB
like following
unset(LIB C)
This code does not work. Does anyone know good way to do this?
There are at least three ways you probably already know:
There's another way to do which you maybe did not know yet. Additionally to "-D" (define variable) cmake has also "-U" (undefine variable), which you can use to remove entries from the cache. It goes like that: $ cmake -U*QT*.
That's not how
unset
works. In your example,unset(LIB C)
unsets both variablesLIB
andC
. It does not remove theC
part fromLIB
.As all variables are internally strings in CMake, you should use
string(REPLACE)
. In your caseReplaces all occurrences of
C
by an empty string and stores the result inLIBwithoutC
. You might want to fine-tune this to remove the extra semicolon.