I try to configire my CMake project so it can accept dynamic source list. But for some reason I get empty list from file function. So I've tried to execute the same operation in 2 ways:
[1] static list (the unwanted way)
set(VARIANT_A "src/dir1/*.cpp src/dur2/*.cpp src/dir3/*.cpp")
file(GLOB SRC . ${VARIANT_A})
messages(${SRC})
here I get the file list I need.
[2] dynamic list (that what I want to do)
set(VARIANT_B "dir1 dir2 dir3")
string(REPLACE " " ";" DirList ${VARIANT_B})
set(Sources "")
foreach(Dir ${DirList})
set(Sources "src/${Source}/*cpp ${Sources}")
endforeach()
message(${Sources})
file(GLOB SRC . ${Sources})
messages(${SRC})
here I get the empty list for some reason despite the fact that message(${Sources})
prints out the same string as ${VARIANT_A}
does.
So what I do wrong?
To create a list you do like this
CMake Tutorial