[CMake] CMake copy files when they change to build dir

Eric Jonas jonas at MIT.EDU
Fri Aug 7 10:33:36 EDT 2009


> 
> There is a FAQ entry about this that ought to work. Why don't you post
> what you have so we can see where you're going wrong?
> 
> Also you can use cmake -E copy_if_different as the command part. It is
> platform-independent, unlike cp.

Tyler, thanks for the quick response -- after quite a bit of frustrated
head-hitting-desk action, I came up with: 


set(test_PYFILES
  test_basics.py
)
 
 
foreach(pyfile ${test_PYFILES})
  ADD_CUSTOM_COMMAND(OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${pyfile}"
    COMMAND cmake -E copy "${CMAKE_CURRENT_SOURCE_DIR}/${pyfile}"
    "${CMAKE_CURRENT_BINARY_DIR}/${pyfile}"
    DEPENDS   "${CMAKE_CURRENT_SOURCE_DIR}/${pyfile}"
    )
   list(APPEND pyfile_dest "${CMAKE_CURRENT_BINARY_DIR}/${pyfile}")
 
endforeach(pyfile)
ADD_CUSTOM_TARGET(silly ALL DEPENDS ${pyfile_dest})

I was reading the FAQs too quickly, and missing the line 

"""This tells CMake how to build the file but does not actually add a
rule to the build system. Another target must require it. One may create
a custom target explicitly for this rule:

ADD_CUSTOM_TARGET(driver ALL DEPENDS someoutput.txt)
"""

Regardless, things are working now, yay! Thanks again,
			...Eric



 




More information about the CMake mailing list