Remove specific part of variable

2019-07-29 17:10发布

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?

标签: cmake
2条回答
女痞
2楼-- · 2019-07-29 17:28

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

查看更多
We Are One
3楼-- · 2019-07-29 17:43

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.

查看更多
登录 后发表回答