[CMake] How to copy directory as part of custom target, filtering out .svn dirs?

Michael Hertling mhertling at online.de
Tue Jun 22 14:11:14 EDT 2010


On 06/21/2010 10:34 PM, Rick Gould wrote:
> I'm looking to install a directory as part of a custom target, but
> exclude all the Subversion .svn directories.
> 
> Both of the the following work, but run as part of the "make install"
> target, which I don't want:
> 
>    install( DIRECTORY ${source_dir}
>       DESTINATION ${destination_dir}
>       PATTERN .svn EXCLUDE
>    )

Maybe, you can use INSTALL()'s COMPONENT feature in junction with a
custom target invoking "cmake_install.cmake" for the installation:

install( DIRECTORY ${source_dir}
   DESTINATION ${destination_dir}
   COMPONENT myinstall
   PATTERN .svn EXCLUDE
)

add_custom_target(myinstall
    COMMAND ${CMAKE_COMMAND}
    -D COMPONENT=myinstall
    -P cmake_install.cmake
)

So, after cmaking, "make myinstall" should do the job, but regrettably,
it's also triggered by "install"; if you don't want that you have to
abandon the general install target as a whole and provide custom
install targets solely.

>    file( COPY ${source_dir}
>       DESTINATION ${destination_dir}
>       PATTERN .svn EXCLUDE
>    )

AFAIK, FILE(COPY ...) isn't run at installation time but during
configuration, so you could possibly use it for your purpose:

file(WRITE ${CMAKE_BINARY_DIR}/myinstall.cmake
"file( COPY ${source_dir}
    DESTINATION ${destination_dir}
    PATTERN .svn EXCLUDE
)")

add_custom_target(myinstall
    COMMAND ${CMAKE_COMMAND} -P myinstall.cmake
)

I.e., provide a CMake script with the desired FILE(COPY ...) command or
even generate it at configuration time, and let it be triggered by a
custom target via CMake's "-P" option; this would be my favourite
since it isn't connected to the install target.

'hope that helps.

Regards,

Michael


More information about the CMake mailing list