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?
That's not how unset
works. In your example, unset(LIB C)
unsets both variables LIB
and C
. It does not remove the C
part from LIB
.
As all variables are internally strings in CMake, you should use string(REPLACE)
. In your case
string(REPLACE C "" LIBwithoutC LIB)
Replaces all occurrences of C
by an empty string and stores the result in LIBwithoutC
. You might want to fine-tune this to remove the extra semicolon.
There are at least three ways you probably already know:
run cmake-gui (or make edit_cache) to open the "cache editor", i.e. the GUI for cmake
the "Holzhammer" method: simply remove the complete cache or build directory and start again
and delete the entries you don't want there
open CMakeCache.txt in a text editor and edit it manually
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*.