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

Mathews, Rob rmathews at envoyww . com
Thu, 16 Oct 2003 18:10:38 -0400


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 ... 

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=""
/>

Most of the time this is not important - using the VCCLCompilerTool works
just as well. The exception is when you want to pass AdditionalOptions to
the MIDL compiler. In this case, CL will rejects the valid MIDL command-line
flags, which means that you can't set compile flags for IDL source files.

For us, we need to pass the "/no_robust" flag to the MIDL compiler,
otherwise the resulting binary won't run on NT. 

So, the following code change allows MIDL command-line flags to be passed to
the MIDL tool: 

In CMakeLists.txt, you'd say something like this: 

SET_SOURCE_FILES_PROPERTIES(pwinterfaces.idl PROPERTIES COMPILE_FLAGS
/no_robust)

And the diffs are: 

773a793,795
>               std::string aCompilerTool = "VCCLCompilerTool";
>               if(d.find(".idl") == d.size() - 4)
>                       aCompilerTool = "VCMIDLTool";
797c819
<                  << "\t\t\t\t\tName=\"VCCLCompilerTool\"\n";
---
>                                << "\t\t\t\t\tName=\""<<
aCompilerTool<<"\"\n";


As usual, I'm sure that you'll figure out someway to expose it ...

Regards,
Rob.

> -----Original Message-----
> From: William A. Hoffman [mailto:billlist at nycap . rr . com]
> Sent: Thursday, October 16, 2003 10:13 AM
> To: 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 have just checked in a change so that this will work.
> It is in CVS, can you give it a try and make sure it does
> what you want before we make 1.8.2?  
> 
> I have also changed it so that if you add /D_UNICODE to the cxx flags,
> it will do the right thing and change the mode.
> 
> Thanks.
> 
> -Bill
> 
> 
> At 12:29 PM 10/15/2003, Mathews, Rob wrote:
> >Unfortunately this doesn't work.
> >
> >SET(CMAKE_CXX_FLAGS_RELEASE "/MT" CACHE STRING 
> "runtime-library flags" FORCE
> >)
> >SET(CMAKE_CXX_FLAGS_DEBUG "/MTd"  CACHE STRING 
> "runtime-library flags" FORCE
> >)
> >SET(CMAKE_CXX_FLAGS_MINSIZEREL "/MT"  CACHE STRING 
> "runtime-library flags"
> >FORCE )
> >SET(CMAKE_CXX_FLAGS_RELWITHDEBINFO "/MTd"  CACHE STRING 
> "runtime-library
> >flags" FORCE )
> >
> >and variants thereof don't work either. I can see in the CMake source
> >generator where the CMAKE_CXX_blah_blah variables are 
> referenced - but the
> >compiler flags just doesn't appear in the resulting .VCPROJ file. 
> >
> >.NET 2003 target, CMake 1.8.1
> >
> >Rob.
> >
> >
> >> -----Original Message-----
> >> From: Mathews, Rob [mailto:rmathews at envoyww . com]
> >> Sent: Tuesday, October 14, 2003 6:27 PM
> >> To: 'Kevin Wright'; cmake at public . kitware . com
> >> Cc: James, Ron
> >> Subject: RE: [Cmake] Setting different compiler flags for Debug vs
> >> Release builds
> >> 
> >> 
> >> Thanks, that's what I needed to know!
> >> 
> >> Rob.
> >> 
> >> > -----Original Message-----
> >> > From: Kevin Wright [mailto:Kevin . Wright at ansys . com]
> >> > Sent: Tuesday, October 14, 2003 5:33 PM
> >> > To: cmake at public . kitware . com
> >> > Subject: RE: [Cmake] Setting different compiler flags 
> for Debug vs
> >> > Release builds
> >> > 
> >> > 
> >> > > How do you set different compiler flags for Debug vs 
> >> > Release builds? 
> >> > > 
> >> > > For example, I need to set the "/MTd" (use multithreaded 
> >> > > static debug C
> >> > > runtime library switch) for a debug build and "/MT" compiler 
> >> > > flag for a
> >> > > release build.
> >> > > 
> >> > > I've read through the documentation and examples, but 
> >> > CMAKE_CXX_FLAGS
> >> > > doesn't seem to support this and I can't find any other magic 
> >> > > variables. 
> >> > 
> >> > I don't know what version this started, but on 1.8 there are 
> >> > variables for
> >> > CMAKE_CXX_FLAGS_DEBUG CMAKE_CXX_FLAGS_RELEASE.  Are you using 
> >> > a different version?
> >> > 
> >> > Kevin.
> >> > _______________________________________________
> >> > Cmake mailing list
> >> > Cmake at www . cmake . org
> >> > http://www . cmake . org/mailman/listinfo/cmake
> >> > 
> >> _______________________________________________
> >> Cmake mailing list
> >> Cmake at www . cmake . org
> >> http://www . cmake . org/mailman/listinfo/cmake
> >> 
> >_______________________________________________
> >Cmake mailing list
> >Cmake at www . cmake . org
> >http://www . cmake . org/mailman/listinfo/cmake 
>