Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I merge multiple lists of files together with CMake?

I have a project built with CMake that needs to copy some resources to the destination folder. Currently I use this code:

file(GLOB files "path/to/files/*") foreach(file ${files})     ADD_CUSTOM_COMMAND(         TARGET MyProject         POST_BUILD         COMMAND ${CMAKE_COMMAND} -E copy "${file}" "${CMAKE_BINARY_DIR}/Debug"     ) endforeach() 

Now I want to copy more files from a different folder. So we want to copy files from both path/to/files and path/to/files2 to the same place in the binary folder. One way would be to just duplicate the above code, but it seems unnecessary to duplicate the lengthy custom command.

Is there an easy way to use file (and possibly the list command as well) to concatenate two GLOB lists?

like image 909
Calvin Avatar asked Sep 23 '11 18:09

Calvin


1 Answers

The file (GLOB ...) command allows for specifying multiple globbing expressions:

file (GLOB files "path/to/files/*" "path/to/files2*") 

Alternatively, use the list (APPEND ...) sub-command to merge lists, e.g.:

file (GLOB files "path/to/files/*") file (GLOB files2 "path/to/files2*") list (APPEND files ${files2}) 
like image 145
sakra Avatar answered Sep 29 '22 21:09

sakra