I've got the following commands. They work quite well. The last
parameter is the target for which the copying is needed. The
copy_directory has a guard against copying CVS metadata.

MACRO(COPY_FILE_IF_CHANGED in_file out_file target)
    IF(${in_file} IS_NEWER_THAN ${out_file})    
    #    message("COpying file: ${in_file} to: ${out_file}")
        ADD_CUSTOM_COMMAND (
                TARGET     ${target}
                POST_BUILD
                COMMAND    ${CMAKE_COMMAND}
                ARGS       -E copy ${in_file} ${out_file}
        )
        ENDIF(${in_file} IS_NEWER_THAN ${out_file})
ENDMACRO(COPY_FILE_IF_CHANGED)

MACRO(COPY_FILE_INTO_DIRECTORY_IF_CHANGED in_file out_dir target)
        GET_FILENAME_COMPONENT(file_name ${in_file} NAME)
        COPY_FILE_IF_CHANGED(${in_file} ${out_dir}/${file_name}
${target})      
ENDMACRO(COPY_FILE_INTO_DIRECTORY_IF_CHANGED)

#Copies all the files from in_file_list into the out_dir. 
# sub-trees are ignored (files are stored in same out_dir)
MACRO(COPY_FILES_INTO_DIRECTORY_IF_CHANGED in_file_list out_dir target)
    FOREACH(in_file ${in_file_list})
                COPY_FILE_INTO_DIRECTORY_IF_CHANGED(${in_file}
${out_dir} ${target})
        ENDFOREACH(in_file)     
ENDMACRO(COPY_FILES_INTO_DIRECTORY_IF_CHANGED)

#Copy all files and directories in in_dir to out_dir. 
# Subtrees remain intact.
MACRO(COPY_DIRECTORY_IF_CHANGED in_dir out_dir target)
    #message("Copying directory ${in_dir}")
    FILE(GLOB_RECURSE in_file_list ${in_dir}/*)
        FOREACH(in_file ${in_file_list})
            if(NOT ${in_file} MATCHES ".*/CVS.*")
                STRING(REGEX REPLACE ${in_dir} ${out_dir} out_file
${in_file})
                COPY_FILE_IF_CHANGED(${in_file} ${out_file} ${target})
        endif(NOT ${in_file} MATCHES ".*/CVS.*")
        ENDFOREACH(in_file)     
ENDMACRO(COPY_DIRECTORY_IF_CHANGED)


-----Original Message-----
From: [email protected] [mailto:[email protected]] On Behalf
Of Werner Smekal
Sent: 19 March 2009 08:07
To: Dancefire
Cc: [email protected]
Subject: Re: [CMake] How to copy files to the directory of executable
file.

Hi,

On 19.03.2009, at 02:28, Dancefire wrote:

> Hi,
>
> I'm working on a simple gtkmm program. I use CMake for the makefile  
> generator. I use GtkBuilder to create the window form, so I need a  
> non-executable file, "window.xml", locate at the same directory of  
> executable file which just build.
>
> The directory structure is simple, every files on the top directory.  
> During build, I do following:
>
> mkdir build
> cd build
> cmake ..
> make
>
> The problem is how can I copy ../window.xml to the "build" directory?

use "cmake -E copy", e.g.

   add_custom_command(
     OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/sfstubs.f
     COMMAND ${CMAKE_COMMAND}
     -E copy ${CMAKE_CURRENT_SOURCE_DIR}/sfstubs.fm4 $ 
{CMAKE_CURRENT_BINARY_DIR}/sfstubs.f
     DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/sfstubs.fm4
   )


Regards,
Werner


>
> _______________________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html
>
> Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ
>
> Follow this link to subscribe/unsubscribe:
> http://www.cmake.org/mailman/listinfo/cmake

--
Dr. Werner Smekal
Institut fuer Allgemeine Physik
Technische Universitaet Wien
Wiedner Hauptstr 8-10
A-1040 Wien
Austria

email: [email protected]
web: http://www.iap.tuwien.ac.at/~smekal
phone: +43-(0)1-58801-13463 (office), +43-(0)1-58801-13469 (laboratory)
fax: +43-(0)1-58801-13499

_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at:
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

-------------------------------------------------------------
This e-mail is intended exclusively for the addressee. If you
are not the addressee you must not read, copy, use or
disclose the e-mail nor the content; please notify us
immediately [by clicking 'Reply'] and delete this e-mail.
_______________________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html

Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ

Follow this link to subscribe/unsubscribe:
http://www.cmake.org/mailman/listinfo/cmake

Reply via email to