[CMake] Make clean in VS can't delete read only files
Michael Hertling
mhertling at online.de
Tue Nov 9 21:45:12 EST 2010
On 11/10/2010 01:17 AM, James Bigler wrote:
> I have a build rule that copies files from the source tree to the build
> tree:
>
> foreach( script ${scripts} )
> set( src "${CMAKE_CURRENT_SOURCE_DIR}/${script}" )
> set( dest "${CMAKE_RUNTIME_OUTPUT_DIRECTORY}/${script}" )
> list( APPEND dest_files "${dest}" )
> add_custom_command(
> OUTPUT "${dest}"
> COMMAND ${CMAKE_COMMAND} -E copy "${src}" "${dest}"
> MAIN_DEPENDENCY "${src}"
> COMMENT "Copying ${src} to ${dest}"
> VERBATIM
> )
> endforeach()
>
> add_custom_target( copy_scripts
> ALL
> DEPENDS ${dest_files}
> )
>
> This then runs commands such as this:
> "C:\Program Files (x86)\Programming\CMake 2.6\bin\cmake.exe" -E copy
> C:/code/rtsdk/rtmain/tests/Regression/scripts/correctness.rb
> C:/code/rtsdk/rtmain/build-32-vs9-c32/bin/correctness.rb
>
> The problem I'm having is that when I go and do a make clean, I get errors
> that the destination files are read only. This isn't unexpected as the
> source files are read only, but how do I work around this file permission
> issue in a portable way?
>
> I don't want to use configure file, because I want the files to be copied at
> build time and not configure time.
Instead of "cmake -E copy" or CONFIGURE_FILE() which both preserve file
permissions, you might use FILE(COPY ... NO_SOURCE_PERMISSIONS) in a
CMake script triggered by your custom command, e.g.:
ADD_CUSTOM_COMMMAND(
OUTPUT ...
COMMAND ${CMAKE_COMMAND} -DSRC=... -DDSTDIR=... -P .../copy.cmake
MAIN_DEPENDENCY ...
COMMENT "Copying ... to ..."
VERBATIM
)
The copy.cmake script may look just like:
FILE(COPY ${SRC} DESTINATION ${DSTDIR} NO_SOURCE_PERMISSIONS)
Note that you must provide a destination directory instead of a full
path, so use GET_FILENAME_COMPONENT() and FILE(RENAME ...) to adapt.
Regards,
Michael
More information about the CMake
mailing list