[CMake] Add_custom_target copying files

Leopold Palomo Avellaneda leo at alaxarxa.net
Mon Feb 16 10:19:29 EST 2009


A Dilluns 16 Febrer 2009, Michael Jackson va escriure:
> Not sure, it should work.
>
> Try changing POST_BUILD to PRE_BUILD and see what happens.
>
> also try printing the variable ${${inputPo}}
>
> message(STATUS "${inputPo}: ${${inputPo}}")
> message(STATUS "inputPo: ${inputPo}")


Well,

first of all thanks for all. After looking and testing a lot i have found a 
functional solution. See above:

Conceptually the main problem have been that I cannot have several custom 
target with the same name in the same directory. So, I was doing a bad 
implementation of your solution. The solution that I have found have been 
create a custom target for every file that I would like to copy and add them 
to the target as dependency.

So, by now it's working. 

Best regards,

Leo

-----------------------------------------------------------------8<
macro (GETTEXT_UPDATE_LANG_PO dirOUTpo inputPo)

   #message (STATUS "Calling the macro to copy files to ${dirOUTpo}\n")
   foreach ( _file ${${inputPo}} )
    get_filename_component(_fdest ${_file} NAME)
    get_filename_component(target ${_file} NAME_WE)
    set(dest ${dirOUTpo}/${_fdest})
    #message (STATUS "Copying ${_file} to ${dest} \n")

    add_custom_target(${target}
      ${CMAKE_COMMAND} -E copy_if_different
      ${_file} ${dest})
      
      add_dependencies(update_lang_po ${target})
     endforeach(_file ${${inputPo}}) 

endmacro (GETTEXT_UPDATE_LANG_PO dirOUTpo inputPo)


>
> On Feb 15, 2009, at 3:48 PM, Leopold Palomo Avellaneda wrote:
> > A Diumenge 15 Febrer 2009, Michael Jackson va escriure:
> >> Here is a code snippet from a project that I use that copies some
> >> files to the build directory.
> >
> > Thanks,
> >
> > but my modified version doesn't work and I don't know what's
> > happen ....
> >
> >
> > macro (GETTEXT_UPDATE_LANG_PO dirOUTpo inputPo )
> >
> >   #message (STATUS "Calling the macro to copy files to ${dirOUTpo}\n")
> >   foreach ( _file ${${inputPo}} )
> >    get_filename_component(_fdest ${_file} NAME)
> >    set(dest ${dirOUTpo}/${_fdest})
> >    message (STATUS "Copying ${_file} to ${dest} \n")
> >    add_custom_command (
> >      TARGET     update_lang_po
> >      POST_BUILD
> >      COMMAND    ${CMAKE_COMMAND}
> >      ARGS       -E copy_if_different
> >      ${_file} ${dest})
> >      #copy_if_different
> >   endforeach(_file ${${inputPo}})
> > endmacro (GETTEXT_UPDATE_LANG_PO dirOUTpo inputPo)
> >
> > I call this macro with a inputPo, a list of files and dirOUTpo a var
> > with a
> > value.
> >
> > The message status shows the correct values, but no copy is done.
> > Any idea?
> >
> > I simple execute make update_lang_po, but nothing is copied ...
> >
> > Thanks in advance,
> >
> > Leo
> >
> >> #-- Copy all the HDF5 files from the test directory into the build
> >> directory
> >> SET (HDF5_REFERENCE_TEST_FILES
> >>   tnullspace.h5
> >>   family_v1.7_00003.h5
> >>   family_v1.7_00001.h5
> >>   mergemsg.h5
> >>   tbogus.h5
> >>   tbad_msg_count.h5
> >>   group_new.h5
> >>   deflate.h5
> >>   noencoder.h5
> >>   family_v1.7_00000.h5
> >>   le_extlink1.h5
> >>   tmtimeo.h5
> >>   tmtimen.h5
> >>   fill_old.h5
> >>   tlayouto.h5
> >>   family_v1.7_00002.h5
> >>   th5s.h5
> >>   tarrold.h5
> >> )
> >>
> >> FOREACH ( h5_file ${HDF5_REFERENCE_TEST_FILES} )
> >>    SET (dest "${PROJECT_BINARY_DIR}/${h5_file}")
> >>    MESSAGE(STATUS " Copying ${dest}")
> >>    ADD_CUSTOM_COMMAND (
> >>      TARGET     ${HDF5_TEST_LIB_NAME}
> >>      POST_BUILD
> >>      COMMAND    ${CMAKE_COMMAND}
> >>      ARGS       -E copy_if_different ${HDF5_TEST_SOURCE_DIR}/$
> >> {h5_file} ${dest}
> >>      )
> >>
> >> ENDFOREACH ( h5_file ${HDF5_REFERENCE_TEST_FILES} )
> >>
> >> _________________________________________________________
> >> Mike Jackson                  mike.jackson at bluequartz.net
> >> BlueQuartz Software                    www.bluequartz.net
> >> Principal Software Engineer                  Dayton, Ohio
> >>
> >> On Feb 15, 2009, at 9:28 AM, Leopold Palomo Avellaneda wrote:
> >>> Hi,
> >>>
> >>> I would like to create a custom target that copy "several" files
> >>> (one, two or
> >>> n files, but at least one) to a directory. I know how to do it with
> >>> one file:
> >>>
> >>> add_custom_target(my_copy_target
> >>> ${CMAKE_COMMAND} -E copy ${_inputfile} ${dirOUT}/)
> >>>
> >>> but, I really don't know how to do it with a list of files.
> >>>
> >>> Someone could help me?
> >>>
> >>> Regards,
> >>>
> >>> Leo
> >>>
> >>>
> >>> _______________________________________________
> >>> 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




More information about the CMake mailing list