[CMake] Copy files to build folder

David Cole david.cole at kitware.com
Tue Jan 17 08:21:42 EST 2012


You could instead have a custom command that operates against a file
that contains an explicit list of the pattern files, and then just
edit that file when you add or remove a pattern. Then your custom
command would depend on that file, and it would re-run when that file
changes, and there's no need for CMake to re-run.

If you want to use file GLOB at CMake time, then you have to re-run
CMake manually when you add or remove a file. There's no way around
that, because we are not going to monitor your hard drive for
arbitrary file changes on a continuous basis...


HTH,
David


On Tue, Jan 17, 2012 at 8:07 AM, Tim Hutton <tim.hutton at gmail.com> wrote:
> Thanks Andreas, but that leaves us with having to edit the
> CMakeLists.txt every time we add a pattern file. There must be a
> better way?
>
> On 17 January 2012 13:02, Andreas Pakulat <apaku at gmx.de> wrote:
>> On 17.01.12 12:54:28, Tim Hutton wrote:
>>> 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?
>>
>> Don't use GLOB, but list all files individually in a variable and
>> iterate over that. CMake is not executed when doing a make call and no
>> cmake-related file has changed and hence the above code is not re-run on
>> each make call.
>>
>> Andreas
>>
>> --
>>
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>>
>> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>>
>> Follow this link to subscribe/unsubscribe:
>> http://www.cmake.org/mailman/listinfo/cmake
>
>
>
> --
> Tim Hutton - http://www.sq3.org.uk - http://profiles.google.com/tim.hutton/
> --
>
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at: http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake


More information about the CMake mailing list