[CMake] [VS gen] Multiple configurations code

Michael Wild themiwi at gmail.com
Mon Jul 26 16:42:45 EDT 2010


On 26. Jul, 2010, at 22:24 , Olaf van der Spek wrote:

> On Mon, Jul 26, 2010 at 10:12 PM, David Cole <david.cole at kitware.com> wrote:
>>> Is there a problem with multiple configures / build trees?
>> 
>> No, not at all. We do this all the time. But again, I thought from your
>> questions that you were trying to do it all in one build tree.
> 
> I'm not familiar with the term build tree.
> 
> Let's describe what I'd like:
> I've got a single CMakeLists.txt for a lib named "xbt". I've got xbt.h
> and xbt.cpp. I'm using VS (2010).
> With a few simple commands, I should be able to build and package all
> possible configurations of this lib.
> In the ideal case, this would be cmake ., nmake ... or similar.
> 
> It should not be necessary to modify CMakeLists or to have multiple
> copies of the source.
> 
> Olaf

A build tree is the top-level directory containing your generated project files. E.g I have the following directories:

$HOME/Projects/ParaView              <- this is the source tree
$HOME/Projects/ParaView-build-dbg64  <- this is a 64-bit debug build tree
$HOME/Projects/ParaView-build-rel64  <- this is a 64-bit release build tree
$HOME/Projects/ParaView-build-dbg32  <- ...you get the picture...
$HOME/Projects/ParaView-build-rel32

The first directory is the one containing all the sources. The other ones are various build trees for different configurations. Sometimes I have more, sometimes less. I have build trees linking against Qt4-Carbon and others linking against Qt4-Cocoa (this is on Mac OS X). So it would be entirely impossible for CMake to handle all these cases in one single build tree for me, after all I'm not just using different configurations and architectures, but also different libraries. It's not just a CMake problem, most IDE's wouldn't be able to do this.

However, as you see, there's only one single source copy, and I never have to change the CMakeLists.txt file.

Now, to your "few simple commands", running CMake in a directory to create a build tree for a specific combination of compile-flags, architecture and libraries (and possibly other options) is a one-liner on the command line. Pretty simple if you ask me. You just have to get over the first hurdles, and invest some time. It will repay tenfold.

Michael


More information about the CMake mailing list