[CMake] Copy files to build folder

Tim Hutton tim.hutton at gmail.com
Tue Jan 17 07:54:28 EST 2012


We've got this section in our CMakeLists.txt:

#--------------------------copy pattern files to build
folder---------------------------------

file( GLOB_RECURSE pattern_files RELATIVE
"${CMAKE_CURRENT_SOURCE_DIR}/" "patterns/*.vti" )
foreach( pattern_file ${pattern_files} )
  add_custom_command(
    OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${pattern_file}"
    COMMAND cmake -E copy
"${CMAKE_CURRENT_SOURCE_DIR}/${pattern_file}"
"${CMAKE_CURRENT_BINARY_DIR}/${pattern_file}"
    DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/${pattern_file}"
  )
  list( APPEND pattern_files_dest "${pattern_file}" )
endforeach( pattern_file )

add_custom_target( CopyPatterns ALL DEPENDS ${pattern_files_dest} )

#-----------------------------------------------------------------------------------------------

The idea is to copy all the *.vti files in the "patterns" folder (and
subfolders) into the build folder, so our program can load them. This
works fine when running CMake for the first time. However, if we add a
new pattern file it doesn't get picked up, even after make clean. (It
works if we edit the CMakeLists.txt, or delete everything in the build
folder.) Is there a way to make this work every time?

Thanks,

Tim

-- 
Tim Hutton - http://www.sq3.org.uk - http://profiles.google.com/tim.hutton/


More information about the CMake mailing list