title: Concatenate multiple files in add_custom_command
body: <p>We have applications that need to ship with an .xsd file that is composed of just several other .xsd files concatenated together. The source list for concatenation can be derived by walking all the library dependencies and examining a property on it. </p>
  
  <p>What I ended up with was a function that an application's CMakeLists.txt can just invoke, which will "do the right thing":</p>
  
  <pre><code>function(make_config_xsd)
      set(xsd_config ${CMAKE_CURRENT_BINARY_DIR}/config.xsd)
  
      # build up a list of config files that are going to be concatenated
      set(config_list ${appcommon_SOURCE_DIR}/config/common.xsd)
  
      # iterate over the library dependencies and pull out config_file properties
      get_target_property(libraries ${PROJECT_NAME} LINK_LIBRARIES)
      foreach(lib ${libraries})
          get_target_property(conf ${lib} config_file)
          if(conf)
              list(APPEND config_list ${conf})
          endif()
      endforeach()
  
      # finally, add the app specific one last
      list(APPEND config_list ${PROJECT_SOURCE_DIR}/config/config.xsd)
  
      add_custom_command(OUTPUT ${xsd_config}
          COMMAND echo \"&lt;?xml version=\\"1.0\\"?&gt;&lt;xs:schema xmlns:xs=\\"http://www.w3.org/2001/XMLSchema\\"&gt;\" &gt; ${xsd_config}
          COMMAND cat ${config_list} &gt;&gt; ${xsd_config}
          COMMAND echo \"&lt;/xs:schema&gt;\" &gt;&gt; ${xsd_config}
          DEPENDS "${config_list}")
  
      add_custom_target(generate-config DEPENDS ${xsd_config})
      add_dependencies(${PROJECT_NAME} generate-config)
  endfunction()
  </code></pre>
  
  <p>This <em>appears</em> to work. But I'm not sure if it is actually the "Right Way" to go about solving this problem, and having a fake <code>add_custom_target()</code> that just depends on the output from <code>add_custom_command()</code> just so that I can do <code>add_dependencies()</code> doesn't seem right either. Is there a more direct way to do a dependency on a generated file like this? </p>