views:

32

answers:

1

Hello, all. I was wondering if there's a way to add Autogenerated files to a VC++ 2008 build. It seems like it's a fairly trivial thing to do if you write your own makefile, but I'd prefer to let visual studio construct a makefile from the project (like it does normally), but also tell it to say "include all .cpp's and .h's that are in the 'autogenerated' folder". Then I would probably generate all those files in a Pre Build Event.

Thanks for any help!

A: 

It's been my experience that VS2008 projects will not automatically add files to the project to build. If you are auto-generating the files, then I would suggest approach that Qt uses may work for you.

For each of the files that are going to be auto-generated, they will automatically add -

  1. A custom compiler tool command in the properties for the source file. You can add custom compiler/build commands to any source file. I would recommend you manually add a command string for the source file and look at generated XML in the project.
  2. For the generated file, they then add the generated file into the build list. For this, it will look like below. Your have to create/maintain a <Filter></Filter> section in the project. See VS Project Layout for format & sample. I would note that each <file></file> is listed individually in the <files></files> section.

    <Files>
    <Filter
        Name="Source Files"
        Filter="cpp;cxx;c;def"
        UniqueIdentifier="{4FC737F1-C7A5-4376-A066-2A32D752A2FF}"
        >
        <File
            RelativePath=".\buildimages.cpp"
            >
        </File>
        <File
            RelativePath=".\main.cpp"
            >
        </File>
    

It really isn't very simple, but if you build simple "script"/program, you can automate most of the work to update the project file before you do the build. Once you output the updated project file, VS will automatically detect the change and ask you to reload the project.

photo_tom
Ok, I didn't know that you could dynamically alter the project file during a pre-build event and have the build reflect it. I'll definitely look into this. Thanks!
Rick Nelson