Import Existing C++ Source Code into Visual Studio

后端 未结 7 659
傲寒
傲寒 2020-12-25 13:53

I am trying to import an existing c++ application\'s source into visual studio to take advantage of some specific MS tools. However, after searching online and playing with

7条回答
  •  情深已故
    2020-12-25 14:31

    I am not aware of any general solution under the constraints given - specifically having to create many projects from a source tree.

    The best option I see is actually creating the project files by some script.

    • Creating a single project manually (create empty project, then add the files),
    • Configure it as close as possible as desired (i.e. with precompiled headers, build configurations, etc.)
    • Use the .vcproj created as skeleton for the project files to be created

    A very simple method would file list, project name etc. with "strange tokens", and fill them in with your generator. If you want to be the good guy, you can of course use some XML handling library.


    Our experience: We actually don't store the .vcproj and .sln in the repository (git) anymore, but a python script that re-genrates them from the source tree, together with VS 2008 "property sheet templates" (or whatever they are called). This helps a lot making general adjustments.

    The project generation script contains information about all the projects specialties (e.g. do they use MFC/ATL, will it create DLL or an EXE, files to exclude).

    In addition, this script also contains dependencies, which feeds the actual build script.

    This works quite well, the problems are minor: python requried in build systems, not forgetting to re-gen the project files, me having to learn some python to make adjustments to some projects.


    @Michael Burr "How complex are the python scripts and whatever supporting 'templates' you might need?"

    I honestly can't tell, since I gave the task to another dev (who picked python). The original task was to provide a build script, as the VS2008 solution build was not good enough for our needs, and the old batch file didn't support parallelization. .vcproj generation was added later. As I understand his script generates the .vcproj and .sln files from scratch, but pulls in all the settings from separate property sheets.

    Pros:

    • Adding new configurations on the fly. Some of the projects already had six configurations, and planning for unicode support meant considering doubling them for a while. Some awkward tools still build as MBCS, so some libs do have 8 configs now. Configuring that from hand is a pain, now it just doesn't bother me anymore.

    • Global changes, e.g. moving around relative project paths, the folder for temp files and for final binaries until we found a solution we were happy with

    • Build Stability. Merging VC6 project files was a notable source of errors for various reasons, and VC9 project files didn't look better. Now things seem isolated better: compile/link settings in the property sheets, file handling in the script. Also, the script mostly lists variations from our default, ending up easier to read than a project file.

    Generally: I don't see a big benefit when your projects are already set up, they are rather stable, and you don't have real issues. However, when moving into the unknown (for us: mostly VC6 -> VC9 and Unicode builds), the flexibility reduced the risk of experiments greatly.

提交回复
热议问题