views:

2998

answers:

5

Does anyone have experience using makefiles for Visual Studio C++ builds (under VS 2005) as opposed to using the project/solution setup. For us, the way that the project/solutions work is not intuitive and leads to configuruation explosion when you are trying to tweak builds with specific compile time flags.

Under Unix, it's pretty easy to set up a makefile that has its default options overridden by user settings (or other configuration setting). But doing these types of things seems difficult in Visual Studio.

By way of example, we have a project that needs to get build for 3 different platforms. Each platform might have several configurations (for example debug, release, and several others). One of my goals on a newly formed project is to have a solution that can have all platform build living together, which makes building and testing code changes easier since you aren't having to open 3 different solutions just to test your code. But visual studio will require 3 * (number of base configurations) configurations. i.e. PC Debug, X360 Debug, PS3 Debug, etc.

It seems like a makefile solution is much better here. Wrapped with some basic batchfiles or scripts, it would be easy to keep the configuration explotion to a minimum and only maintain a small set of files for all of the different builds that we have to do.

However, I have no experience with makefiles under visual studio and would like to know if others have experiences or issues that they can share.

Thanks.

(post edited to mention that these are C++ builds)

+2  A: 

Visual studio is being built on top of the MSBuild configurations files. You can consider *proj and *sln files as makefiles. They allow you to fully customize build process.

aku
A: 

You can use nant to build the projects individually thus replacing the solution and have 1 coding solution and no build solutions.

1 thing to keep in mind, is that the solution and csproj files from vs 2005 and up are msbuild scripts. So if you get acquainted with msbuild you might be able to wield the existing files, to make vs easier, and to make your deployment easier.

DevelopingChris
A: 

While it's technically possible, it's not a very friendly solution within Visual Studio. It will be fighting you the entire time.

I recommend you take a look at NAnt. It's a very robust build system where you can do basically anything you need to.

Our NAnt script does this on every build:

  1. Migrate the database to the latest version
  2. Generate C# entities off of the database
  3. Compile every project in our "master" solution
  4. Run all unit tests
  5. Run all integration tests

Additionally, our build server leverages this and adds 1 more task, which is generating Sandcastle documentation.

If you don't like XML, you might also take a look at Rake (ruby), Bake/BooBuildSystem (Boo), or Psake (PowerShell)

Ben Scheirman
+3  A: 

I've found some benefits to makefiles with large projects, mainly related to unifying the location of the project settings. It's somewhat easier to manage the list of source files, include paths, preprocessor defines and so on, if they're all in a makefile or other build config file. With multiple configurations, adding an include path means you need to make sure you update every config manually through Visual Studio's fiddly project properties, which can get pretty tedious as a project grows in size.

Projects which use a lot of custom build tools can be easier to manage too, such as if you need to compile pixel / vertex shaders, or code in other languages without native VS support.

You'll still need to have various different project configurations however, since you'll need to differentiate the invocation of the build tool for each config (e.g. passing in different command line options to make).

Immediate downsides that spring to mind:

  • Slower builds: VS isn't particularly quick at invoking external tools, or even working out whether it needs to build a project in the first place.
  • Awkward inter-project dependencies: It's fiddly to set up so that a dependee causes the base project to build, and fiddlier to make sure that they get built in the right order. I've had some success getting SCons to do this, but it's always a challenge to get working well.
  • Loss of some useful IDE features: Edit & Continue being the main one!

In short, you'll spend less time managing your project configurations, but more time coaxing Visual Studio to work properly with it.

Nik
As I said in other comment, MSVS is just a huge wrapper over MSBuild files. You can use these files directly without touching IDE. I encourage you to learn more on MSBuild
aku
A: 

We have a similar set up as the one you are describing. We support at least 3 different platforms, so the we found that using CMake to mange the different Visual Studio solutions. Set up can be a bit painful, but it pretty much boils down to reading the docs and a couple of tutorials. You should be able to do virtually everything you can do by going to the properties of the projects and the solution. Not sure if you can have all three platforms builds living together in the same solution, but you can use CruiseControl to take care of your builds, and running your testing scripts as often as needed.

axs6791