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

William A. Hoffman billlist at nycap . rr . com
Fri, 17 Oct 2003 16:20:17 -0400


OK, I think I have fixed the problem now.  /D and -D should work with
VS 7.   Try a cvs update and let me know.  Also, I have made it so
the -M flags should only be on the command line once.

Let me know if this fixes your problem.  We would like to get all this
in 1.8.2.


-Bill


At 03:27 PM 10/17/2003, Mathews, Rob wrote:
>Ok, so in the example below I've tried compiling using the /DUNICODE switch
>and I now get compile errors like this: 
>
>D:\Program Files\Microsoft Visual Studio .NET
>2003\Vc7\PlatformSDK\Include\WinNT.h(828) : error C2124: divide or mod by
>zero
>
>in system header files at places like this: 
>
>#if(_WIN32_WINNT > 0x0500)
>
>Clearly the "/D" switch switch is not only not understood by .NET, it
>generates the wrong #define!
>
>Rob.
>
>> -----Original Message-----
>> From: Mathews, Rob 
>> Sent: Friday, October 17, 2003 1:23 PM
>> To: Mathews, Rob; 'William A. Hoffman'; 'Kevin Wright';
>> 'cmake at public . kitware . com'
>> Cc: James, Ron
>> Subject: RE: [Cmake] Setting different compiler flags for Debug vs
>> Release builds
>> 
>> 
>> I just noticed that when I use the "/D_UNICODE" switch 
>> instead of the "-D_UNICODE" switch, my project changes like this: 
>> 
>> 67c67
>> <                               
>> PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS,R
>> ESOURCE_FEATURE,WIN32,i386,_WIN32_WINNT=0x0400,UNICODE,_UNICODE,"
>> ---
>> >                               
>> PreprocessorDefinitions="WIN32,NDEBUG,_WINDOWS,R
>> ESOURCE_FEATURE,WIN32,i386,_WIN32_WINNT=0x0400 /DUNICODE /D_UNICODE,"
>> 
>> Notice that .NET isn't really grokking switches of the form 
>> "/D" - it seems to prefer "-D" style switches. 
>> 
>> 
>> > -----Original Message-----
>> > From: Mathews, Rob 
>> > Sent: Friday, October 17, 2003 1:11 PM
>> > To: 'William A. Hoffman'; 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
>> > 
>> > 
>> > 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
>> > > 
>> > 
>>