[cmake-developers] [CMake 0015035]: Build time file copy_if_different

Mantis Bug Tracker mantis at public.kitware.com
Wed Jul 23 13:54:12 EDT 2014


The following issue has been SUBMITTED. 
====================================================================== 
http://www.cmake.org/Bug/view.php?id=15035 
====================================================================== 
Reported By:                Daniele E. Domenichelli
Assigned To:                
====================================================================== 
Project:                    CMake
Issue ID:                   15035
Category:                   CMake
Reproducibility:            have not tried
Severity:                   feature
Priority:                   normal
Status:                     new
====================================================================== 
Date Submitted:             2014-07-23 13:54 EDT
Last Modified:              2014-07-23 13:54 EDT
====================================================================== 
Summary:                    Build time file copy_if_different
Description: 
As a follow up to this thread[1], we agreed that in order to create a project
that other project can use both from the install and build tree, in some cases
it is a good idea to replicate the installation tree or part of it inside the
build directory, so that the relative paths are the same when the package is
used from the build tree or from the installation.

[1]http://thread.gmane.org/gmane.comp.programming.tools.cmake.devel/10492

file(COPY) copies the file is copied at CMake time, not a build time, and cmake
is not triggered when the original file is modified, and therefore the copy is
not performed at build time if the file is modified and the just runs make (or
"build" for visual studio and other IDEs). Also file(COPY) does not have an
option to copy the file only if the file(s) is(are) different and could trigger
an unnecessary rebuild.

execute_process(COMMAND "${CMAKE_COMMAND} -E copy_if_different") does not
trigger unnecessary builds, but it is still in the configure phase

configure_file(COPYONLY) still copies the file in the configure phase, but it
will trigger a cmake run if the original file was modified. Nonetheless it has a
few disadvantages:
 * It's less discoverable than file(COPY)
 * It can copy just one file at the time, therefore it is not easy to reproduce
an install tree
 * It triggers a cmake run, that will slow down the build
 * The files to configure might be the product of some build step and therefore
not available during the configure step.

At the moment (as far as I know) the only way to do it is to use
add_custom_command to execute some external CMake script that runs
"${CMAKE_COMMAND} -E copy_if_different", but this require a lot of work to
handle the file level and target level dependencies correctly.


It would be very useful to be able to copy files at build time only if
different, without triggering a cmake run, and with a syntax similar to the
install command.


I suggest to implement one of the following ideas:

* Have an option for the install(FILES/PROGRAMS/DIRECTORY) command that
reproduces the install tree in the binary directory, but at build time, and only
if the destination file is missing or is different from the source.

* Add some modes to the export() command, for example
export(FILES/PROGRAMS/DIRECTORY), with the same signature of
install(FILES/PROGRAMS/DIRECTORY), and that replicates the behaviour of this
command but at build time and in in the similar way as export(EXPORT) replicates
the behaviour of install(EXPORT)

====================================================================== 

Issue History 
Date Modified    Username       Field                    Change               
====================================================================== 
2014-07-23 13:54 Daniele E. DomenichelliNew Issue                               
    
======================================================================



More information about the cmake-developers mailing list