[CMake] Build different targets depending on build configuration

Mike Jackson mike.jackson at imts.us
Mon Aug 18 10:03:35 EDT 2008


My experiences in line..

On Aug 18, 2008, at 8:38 AM, Steven Dwyer wrote:

> I'm looking at moving from scons to cmake, but after reading  
> through the documentation and mailing lists, I'm not sure if it  
> will handle everything that I want to do.  In particular:
>
> I want to build three different configurations:  Debug, Release, Test
>
> The input to the three configurations is mostly the same (some  
> differences in compiler switches, etc.).  However, the output is  
> different for the test configuration.
>
> The test configuration should build with the following "rules".
>
> 1.  The test configuration should always link in an additional  
> library that contains its own 'main' function.

Yes this is possible. You would simple list the library as an  
additional argument to the "target_link_libraries(...)" command. This  
is common if you use the Boost testing framework as boost supplies  
its own "main" function.


> 2.  If the Debug/Release configurations build an executable, the  
> test configuration should also build an executable and run it after  
> it is built.

I use the Boost unit testing framework and what I do is add "testing"  
targets that build my unit tests (optionally) every time I compile.  
After the compile I run "make test" and all the units tests are  
executed.

> 3.  If the Debug/Release configurations build a library, the test  
> configuration should build an executable and run it after it is built.

Same idea as #2. There are some pointers in the CMake wiki about  
setting all this up but just keep asking questions here as you will  
find the cmake community very willing to help.

>
> Is it possible to do this with cmake, and if so are there any  
> pointers on how to set it up?

Take a look at <http://titanium.imts.us/viewvc/Task_7/MXADataModel/>  
for my own project that uses some of these ideas. You can also take a  
look at <http://titanium.imts.us/viewvc/Task_7/hdf5-166/> where I  
tweaked the HDF5 build system that was included with ParaView to add  
the necessary testing code.
>
> I'm using the Microsoft Visual Studio 2005 generator and am running  
> on the Windows platform.
>
> Thanks very much,
> Steven
>

-- 
Mike Jackson   Senior Research Engineer
Innovative Management & Technology Services



More information about the CMake mailing list