file - CMake: creating COPY_IF_DIFFERENT macro with different behaviors -
file - CMake: creating COPY_IF_DIFFERENT macro with different behaviors -
there 2 possible behaviors differ bit each other. difference of particular involvement , investigate cause , possible pitfalls of help.
implementation:
macro(copy_if_different src_files src_dir dst_dir dst_file_targets) foreach(src_file ${src_files}) set(dst_file ${src_file}) # names of original , re-create same. # set(dst_file_target ${dst_dir}/${dst_file}) # <--- # set(dst_file_target ${src_file}) # <--- b add_custom_command( output ${dst_file_target} command ${cmake_command} args -e copy_if_different ${src_dir}/${src_file} ${dst_dir}/${dst_file} # main_dependency ${src_dir}/${src_file} # <--- c # depends ${src_dir}/${src_file} # <--- d ) set(dstfiletargets ${dstfiletargets} ${dst_file_target}) endforeach() set(${dst_file_targets} ${dstfiletargets}) set(custom_target ${argv4}) if(custom_target) add_custom_target(${custom_target} depends ${dstfiletargets}) endif() endmacro()
just in order clarify purpose of macro @ typical usage:
set(h_files header1.h header2.h ...) copy_if_different(${h_files} ${cmake_current_source_dir} ${my_awesome_include_dir} h_file_targets "myawesomeincludetarget")
basically, macro re-create listed files ${h_files} ${cmake_current_source_dir} ${my_awesome_include_dir}. homecoming list of targets each destination re-create in ${h_file_targets}.
note: if lastly parameter of macro nowadays (like in case above) macro automatically create custom target name provided lastly parameter ("myawesomeincludetarget") in order create real copying rules each target ${h_file_targets} in makefiles. otherwise, if lastly parameter absent 1 has manually create custom target ${h_file_targets} or attach ${h_file_targets} target add_executable(whatever ${sources_of_whatever} ${h_file_targets})
. can find more info on subtle detail here.
back on track. first of all, notice a, b, c , d in comments because need them farther discussion.
behavior #1 nowadays when uncomment , (either c or d or both):
if re-create not there yet (i. e. invoking first time), copying happens (of course); if edit original , re-create there already, copying happens (indeed); if edit copy, copying does not happen. it's unusual since utilize copy_if_different command. (*) however, suspect command not invoked in case because editing time stamp of re-create always higher of original results in dead target. if leave both original , re-create untouched, copying does not happen because of time stamps again.behavior #2 nowadays when uncomment b (neither c nor d not needed - whoa!):
if re-create not there yet (i. e. invoking first time), copying happens (of course);
if edit original , re-create there already, copying happens too;
if edit copy, copying happens too. , i'm particularly interested in because want behavior. however, in origin expected #1, seems impossible according argument marked (*) (btw comment on please). discovered #2 accidentally during experimenting, don't understand why work that? safe? there pitfalls it?
if leave both original , re-create untouched, copying does not happen copy_if_different command suggests (regardless of time stamps).
i understand post quite big, way convey subject :)
thanks in advance guys
file macros copy cmake
Comments
Post a Comment