[CMake] How can I add -gstabs to the compile item for Debug?

Bill Hoffman bill.hoffman at kitware.com
Thu Dec 18 15:51:27 EST 2008


Tyler wrote:
> On Thu, Dec 18, 2008 at 03:07:12PM -0500, Bill Hoffman wrote:
>> Tyler Roscoe wrote:
>>> On Fri, Dec 19, 2008 at 01:33:45AM +0800, Kermit Mei wrote:
>>>> c++ -Wall -gstabs(or -g)  main.cpp hello.cpp -o main
>>>>
>>>> How can I use cmake to do the same thing?
>>> Add your -g flag to CMAKE_CXX_FLAGS or I think you can use
>>> ADD_DEFINITIONS("-g").
>>>
>> It would be better to edit the CMAKE_CXX_FLAGS_DEBUG cache variable.
>>
>> add_definitions(-g) is bad for a several reasons...
>>
>> It will break for compilers that do not accept -g, it will add -g to 
>> release and optimized builds.
> 
> If the compiler doesn't support -g, how would using CMAKE_CXX_FLAGS_*
> help?
> 
> If one wanted -g in all configurations, is ADD_DEFINITIONS then an
> acceptable solution, or is there other badness there?
> 

Generally, add_definitions was intended for -D stuff, and not compiler 
flags.  Compiler flags were meant to go into the cache variables.

-Bill


More information about the CMake mailing list