5

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?

2 Answers 2

6

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.

Sign up to request clarification or add additional context in comments.

1 Comment

After trying several times, I found string(REPLACE "C;" "" LIBwithoutC "${LIB}") works. Using "${LIB}" can treat these variable as string. cmake.org/pipermail/cmake/2016-January/062594.html
-2

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*.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.