parameters: (target_name, copies, extra_deps, path_to_gyp, output)
docstring: Write CMake for the 'copies' in the target.
  
    Args:
      target_name: the name of the CMake target being generated.
      actions: the Gyp 'actions' dict for this target.
      extra_deps: [<cmake_taget>] to append with generated targets.
      path_to_gyp: relative path from CMakeLists.txt being generated to
          the Gyp file in which the target being generated is defined.
docstring_summary: Write CMake for the 'copies' in the target.
docstring_tokens: Write CMake for the copies in the target .
function: def WriteCopies(target_name, copies, extra_deps, path_to_gyp, output):
    """Write CMake for the 'copies' in the target.
  
    Args:
      target_name: the name of the CMake target being generated.
      actions: the Gyp 'actions' dict for this target.
      extra_deps: [<cmake_taget>] to append with generated targets.
      path_to_gyp: relative path from CMakeLists.txt being generated to
          the Gyp file in which the target being generated is defined.
    """
    copy_name = target_name + '__copies'
  
    # CMake gets upset with custom targets with OUTPUT which specify no output.
    have_copies = any(copy['files'] for copy in copies)
    if not have_copies:
      output.write('add_custom_target(')
      output.write(copy_name)
      output.write(')\n')
      extra_deps.append(copy_name)
      return
  
    class Copy(object):
      def __init__(self, ext, command):
        self.cmake_inputs = []
        self.cmake_outputs = []
        self.gyp_inputs = []
        self.gyp_outputs = []
        self.ext = ext
        self.inputs_name = None
        self.outputs_name = None
        self.command = command
  
    file_copy = Copy('', 'copy')
    dir_copy = Copy('_dirs', 'copy_directory')
  
    for copy in copies:
      files = copy['files']
      destination = copy['destination']
      for src in files:
        path = os.path.normpath(src)
        basename = os.path.split(path)[1]
        dst = os.path.join(destination, basename)
  
        copy = file_copy if os.path.basename(src) else dir_copy
  
        copy.cmake_inputs.append(NormjoinPathForceCMakeSource(path_to_gyp, src))
        copy.cmake_outputs.append(NormjoinPathForceCMakeSource(path_to_gyp, dst))
        copy.gyp_inputs.append(src)
        copy.gyp_outputs.append(dst)
  
    for copy in (file_copy, dir_copy):
      if copy.cmake_inputs:
        copy.inputs_name = copy_name + '__input' + copy.ext
        SetVariableList(output, copy.inputs_name, copy.cmake_inputs)
  
        copy.outputs_name = copy_name + '__output' + copy.ext
        SetVariableList(output, copy.outputs_name, copy.cmake_outputs)
  
    # add_custom_command
    output.write('add_custom_command(\n')
  
    output.write('OUTPUT')
    for copy in (file_copy, dir_copy):
      if copy.outputs_name:
        WriteVariable(output, copy.outputs_name, ' ')
    output.write('\n')
  
    for copy in (file_copy, dir_copy):
      for src, dst in zip(copy.gyp_inputs, copy.gyp_outputs):
        # 'cmake -E copy src dst' will create the 'dst' directory if needed.
        output.write('COMMAND ${CMAKE_COMMAND} -E %s ' % copy.command)
        output.write(src)
        output.write(' ')
        output.write(dst)
        output.write("\n")
  
    output.write('DEPENDS')
    for copy in (file_copy, dir_copy):
      if copy.inputs_name:
        WriteVariable(output, copy.inputs_name, ' ')
    output.write('\n')
  
    output.write('WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/')
    output.write(path_to_gyp)
    output.write('\n')
  
    output.write('COMMENT Copying for ')
    output.write(target_name)
    output.write('\n')
  
    output.write('VERBATIM\n')
    output.write(')\n')
  
    # add_custom_target
    output.write('add_custom_target(')
    output.write(copy_name)
    output.write('\n  DEPENDS')
    for copy in (file_copy, dir_copy):
      if copy.outputs_name:
        WriteVariable(output, copy.outputs_name, ' ')
    output.write('\n  SOURCES')
    if file_copy.inputs_name:
      WriteVariable(output, file_copy.inputs_name, ' ')
    output.write('\n)\n')
  
    extra_deps.append(copy_name)
function_tokens: def WriteCopies ( target_name , copies , extra_deps , path_to_gyp , output ) : copy_name = target_name + '__copies' # CMake gets upset with custom targets with OUTPUT which specify no output. have_copies = any ( copy [ 'files' ] for copy in copies ) if not have_copies : output . write ( 'add_custom_target(' ) output . write ( copy_name ) output . write ( ')\n' ) extra_deps . append ( copy_name ) return class Copy ( object ) : def __init__ ( self , ext , command ) : self . cmake_inputs = [ ] self . cmake_outputs = [ ] self . gyp_inputs = [ ] self . gyp_outputs = [ ] self . ext = ext self . inputs_name = None self . outputs_name = None self . command = command file_copy = Copy ( '' , 'copy' ) dir_copy = Copy ( '_dirs' , 'copy_directory' ) for copy in copies : files = copy [ 'files' ] destination = copy [ 'destination' ] for src in files : path = os . path . normpath ( src ) basename = os . path . split ( path ) [ 1 ] dst = os . path . join ( destination , basename ) copy = file_copy if os . path . basename ( src ) else dir_copy copy . cmake_inputs . append ( NormjoinPathForceCMakeSource ( path_to_gyp , src ) ) copy . cmake_outputs . append ( NormjoinPathForceCMakeSource ( path_to_gyp , dst ) ) copy . gyp_inputs . append ( src ) copy . gyp_outputs . append ( dst ) for copy in ( file_copy , dir_copy ) : if copy . cmake_inputs : copy . inputs_name = copy_name + '__input' + copy . ext SetVariableList ( output , copy . inputs_name , copy . cmake_inputs ) copy . outputs_name = copy_name + '__output' + copy . ext SetVariableList ( output , copy . outputs_name , copy . cmake_outputs ) # add_custom_command output . write ( 'add_custom_command(\n' ) output . write ( 'OUTPUT' ) for copy in ( file_copy , dir_copy ) : if copy . outputs_name : WriteVariable ( output , copy . outputs_name , ' ' ) output . write ( '\n' ) for copy in ( file_copy , dir_copy ) : for src , dst in zip ( copy . gyp_inputs , copy . gyp_outputs ) : # 'cmake -E copy src dst' will create the 'dst' directory if needed. output . write ( 'COMMAND ${CMAKE_COMMAND} -E %s ' % copy . command ) output . write ( src ) output . write ( ' ' ) output . write ( dst ) output . write ( "\n" ) output . write ( 'DEPENDS' ) for copy in ( file_copy , dir_copy ) : if copy . inputs_name : WriteVariable ( output , copy . inputs_name , ' ' ) output . write ( '\n' ) output . write ( 'WORKING_DIRECTORY ${CMAKE_CURRENT_LIST_DIR}/' ) output . write ( path_to_gyp ) output . write ( '\n' ) output . write ( 'COMMENT Copying for ' ) output . write ( target_name ) output . write ( '\n' ) output . write ( 'VERBATIM\n' ) output . write ( ')\n' ) # add_custom_target output . write ( 'add_custom_target(' ) output . write ( copy_name ) output . write ( '\n  DEPENDS' ) for copy in ( file_copy , dir_copy ) : if copy . outputs_name : WriteVariable ( output , copy . outputs_name , ' ' ) output . write ( '\n  SOURCES' ) if file_copy . inputs_name : WriteVariable ( output , file_copy . inputs_name , ' ' ) output . write ( '\n)\n' ) extra_deps . append ( copy_name )