[CMake] How to manipulate each string in a list?

Michael Wild themiwi at gmail.com
Thu Mar 25 04:32:29 EDT 2010


Hi Jin

On 25. Mar, 2010, at 9:06 , Jin Huang wrote:

> Dear all,
> 
> I am a newbie of cmake, and have googled some times for this question.  I'm sorry if it's a naive question.
> 
> The typical operation is to make replacement on each string in a list.  In GNU Make, I can use the following code for such tasks:
> 
> HEADER = $(patsubst %.cpp, %.h, $(SRC))
> HEADER_WITH_DIR = $(patsubst %, include/%, $(HEADER))

In GNU Make you probably should do this with $(addprefix include/, $(HEADER))

> 
> Now I can only use foreach iteration to construct a new list in CMake.  Is there any simple command to do this?
> 
> Best regards,
> 
> Jin

set(SRC hello.cpp bla.cpp blu.cpp)

string(REGEX REPLACE "\\.cpp(;|$)" ".h\\1" HEADER "${SRC}")
string(REGEX REPLACE "([^;]+)(;|$)" "include/\\1\\2" HEADER_WITH_DIR "${HEADER}")

message("HEADER = ${HEADER}")
message("HEADER_WITH_DIR = ${HEADER_WITH_DIR}")


HTH

Michael


More information about the CMake mailing list