title: SCons: how to add cpp files to source list
body: <p>In SCons, I have a pre-build step that generates an unknown number of files.  Once these files are generated, I need to be able to add the cpp files to my source list.  I am an absolute beginner at SCons, and I'm not sure what is the correct path to take.  What is the best method for doing this?</p>
  
  <p><strong>Original:</strong>
  The basic/original build steps are as follows:  </p>
  
  <pre><code>fpmFile = Dir('#').Dir('src').entry_abspath("FabricKINECT.fpm.json")
  # The next step generates a bunch of source files
  cppHeader = env.Command(
    [env.File(target + '.h')],
    klSources,
    [[kl2edkBin, fpmFile, "-o", hdir, "-c", cppdir]]
    )
  env.Depends(cppSources, cppHeader)
  
  # We pass in the supplied filelist to the build command
  # however, this list does not include the cpp files generated above
  # Currently I am hard-coding the generated files into
  # the cppSources list, but I want to add them in dynamically
  return env.SharedLibrary(
    '-'.join([target, buildOS, buildArch]),
    cppSources
    )
  </code></pre>
  
  <p><strong>What I've Tried</strong>
  I've tried several different angles:</p>
  
  <p><a href="http://www.scons.org/wiki/DynamicSourceGenerator" rel="nofollow noreferrer">http://www.scons.org/wiki/DynamicSourceGenerator</a>, but from what I could figure out, this creates seperate build targets for each file, whereas I want them all to be included in my library build</p>
  
  <p>Using an emitter: <a href="https://stackoverflow.com/questions/13953964/scons-to-generate-variable-number-of-targets">SCons to generate variable number of targets</a>, but I can't seem to get the dependency worked out - my scanner runs before anything else, no matter how I assign dependencies</p>
  
  <p>I tried making another Command to gather a list of files - </p>
  
  <pre><code>def gatherGenCpp(target, source, env):
    allFiles = Glob('generated/cpp/*.cpp')
    # clear dummy target
    del target[:]
    for f in allFiles:
      target.append(f)
  
  genSources = env.Command(['#dummy-file'], cppdir, gatherGenCpp)
  env.Depends(genSources, cppSources)
  
  allSources = genSources + cppSources
  return env.SharedLibrary(
    '-'.join([target, buildOS, buildArch]),
    allSources
    )
  </code></pre>
  
  <p>This however fails with </p>
  
  <blockquote>
    <p>fatal error LNK1181: cannot open input file 'dummy-file.obj'</p>
  </blockquote>
  
  <p>I guess its because even though I clean the dummy-file entry out of the targets of the command, this happens after its registered with build system (and the expected targets are made.</p>
  
  <p>all this to say - how would you implement the following:</p>
  
  <ul>
  <li>A command generates a bunch of CPP files</li>
  <li>These files are added to a passed in list of files</li>
  <li>We build a dll out of this list of cpp files.</li>
  </ul>
  
  <p>Any suggestions?</p>