[Cmake] Setting different compiler flags for Debug vs Release builds

Mathews, Rob rmathews at envoyww . com
Fri, 17 Oct 2003 13:10:41 -0400


I gave it a whirl: 

/D_UNICODE switch: 

This works as advertised. It would be nice if it also understood
"-D_UNICODE".

/MT* switch: 

I put this in my CMakeLists.txt file: 

SET(CMAKE_CXX_FLAGS "/w /Zm1000 /GX /GR /wd4018" )
SET(CMAKE_CXX_FLAGS_RELEASE "/MT"  )
SET(CMAKE_CXX_FLAGS_DEBUG "/MTd"  )
SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MT" )
SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd")

and it produces the correct RuntimeLibrary tag values. However, it also
leaves
the /MT switch on the AdditionalOptions line, which it really shouldn't.
Probably harmless, but the complete solution should also remove any options
which are mapped as tags from the AdditionalOptions value, lest it cause
confusion to users of the .NET solution or weird behaviour.

Thanks,
Rob.

> -----Original Message-----
> From: William A. Hoffman [mailto:billlist at nycap . rr . com]
> Sent: Friday, October 17, 2003 12:06 PM
> To: Mathews, Rob; Mathews, Rob; Mathews, Rob; 'Kevin Wright';
> cmake at public . kitware . com
> Cc: James, Ron
> Subject: RE: [Cmake] Setting different compiler flags for Debug vs
> Release builds
> 
> 
> At 06:10 PM 10/16/2003, Mathews, Rob wrote:
> >Thanks, I'd be happy to give it a whirl.
> >
> >But, how to you use it to set a different runtime library? 
> It turns out to
> >be pretty important to be able to set the RuntimeLibrary tag 
> in the .vcproj
> >file ... 
> 
> You set the run time library with the /M* flags in the 
> CMAKE_CXX_FLAGS.
> 
> Here is the mapping to the runtime flags:
>   if(flags.find("MTd") != flags.npos)
>     {
>     runtime = 1;
>     }
>   else if (flags.find("MDd") != flags.npos)
>     {
>     runtime = 3;
>     }
>   else if (flags.find("MLd") != flags.npos)
>     {
>     runtime = 5;
>     }
>   else if (flags.find("MT") != flags.npos)
>     {
>     runtime = 0;
>     }
>   else if (flags.find("MD") != flags.npos)
>     {
>     runtime = 2;
>     }
>   else if (flags.find("ML") != flags.npos)
>     {
>     runtime = 4;
>     }
> 
> This way the same CMakeLists.txt file should work for visual 
> studio 7 and 6.
> 
> 
> >While we are here, there is a problem with .IDL files as well. Cmake
> >generates this for .IDL files: 
> > <Tool
> >        Name="VCCLCompilerTool"
> >        AdditionalOptions=" /TP "
> >/>
> >
> >It should generate: 
> ><Tool
> >        Name="VCMIDLTool"
> >        AdditionalOptions=""
> >/>
> 
> I will look at this problem as well.
> 
> 
> -Bill
>