[CMake] howto re-run file(COPY signature ?
Michael Hertling
mhertling at online.de
Wed Nov 24 04:55:45 EST 2010
On 11/24/2010 04:44 AM, Dominique Belhachemi wrote:
> Hello,
>
> I am using the following command in my CMakeLists.txt file to copy a
> directory with all sub-directories from the source tree to a directory
> in the binary tree.
>
> file(COPY ${SRCDIR}
> DESTINATION ${CMAKE_BINARY_DIR}/${DSTDIR}/
> PATTERN .svn EXCLUDE
> )
>
> After adding this line to CMakeLists.txt and typing 'make' the command
> is working like expected. But after adding a new file to ${SRCDIR} and
> typing 'make' again, the new file doesn't get copied. I have to do a
> 'touch CMakeLists.txt' first.
>
> Is there a way to enforce the execution?
You might outsource the FILE(COPY ...) command to a CMake script which
is invoked by a custom target, e.g. as in the following CMakeLists.txt:
CMAKE_MINIMUM_REQUIRED(VERSION 2.8 FATAL_ERROR)
PROJECT(COPYTREE NONE)
ADD_CUSTOM_TARGET(copytree ALL
${CMAKE_COMMAND}
-DSRC=${CMAKE_SOURCE_DIR}
-DDST=/tmp/${PROJECT_NAME}
-P ${CMAKE_SOURCE_DIR}/copytree.cmake
)
The ${CMAKE_SOURCE_DIR}/copytree.cmake script simply looks like:
FILE(COPY ${SRC} DESTINATION ${DST} PATTERN .svn EXCLUDE)
Because FILE(COPY ...) copies files and directories only if they are new
or have been touched you can probably afford the script's execution each
time you build; use ADD_DEPENDENCIES() to ensure that the script runs at
the right time.
Regards,
Michael
More information about the CMake
mailing list