[CMake] Always compile source file in debug

Belcourt, Kenneth kbelco at sandia.gov
Fri Sep 3 23:08:38 EDT 2010


On Sep 3, 2010, at 6:30 PM, Michael Hertling wrote:

> On 09/03/2010 04:13 PM, Belcourt, Kenneth wrote:
>>
>> On Sep 3, 2010, at 5:07 AM, Eric Noulard wrote:
>>>
>>> Curious to know, Why do you want to "some files" files to always be
>>> built debug
>>> in the first place?
>>
>> For example, certain Lapack routines like slamch and dlamch fail
>> outright if compiled O2 or higher (don't ask why we build from source
>> instead using an optimized library).  In our code base, we have
>> several routines that O3 generates bad code on so we can only  
>> optimize
>> to O2 or lower (it's a compiler bug that we could work around by
>> rewriting our code but we choose to optimize to a lower level
>> instead).  In other cases, when debugging a numerical problem in our
>> release code base, one of the simplest ways to find the problem is to
>> selectively recompile a single library at a time (and main) in debug
>> until the problem goes away.  This helps us narrow down the source of
>> the numerical differences.  These are all related to selectively
>> compiling something in, say release, while everything else is built
>> debug.  Or, as in my case, selectively building certain files or
>> libraries in debug with everything else in release.
>
> If your issue just boils down to a faulty optimization by GCC you will
> probably get along with the COMPILE_FLAGS source or target properties:
> CMake appends them to the compiler flags, and GCC assures that the  
> last
> one seen on the command line takes effect.
>
> Furthermore, in order to build with the highest possible optimization,
> you could look at the differences between, say, -O2 and -O3, and find
> out the particular switches that are causing a crash. Finally, enable/
> disable them specifically for the affected source files or targets via
> the COMPILE_FLAGS properties, so your projects can be built with,  
> e.g.,
> -O3 as a whole.

The problem is having to write boatloads of logic for de-optimization  
some files like this (Boost.Build syntax).

Disable optimization on a couple of platforms.

obj skit-formats
   : SPARSKIT1.1/FORMATS/formats.f
   : <toolset>darwin:<optimization>off
     <toolset>gcc:<optimization>off
   ;

whereas for other files, need to de-optimize on all platforms

obj slamch
   : SRC/slamch.f
   : <toolset>darwin:<optimization>off
     <toolset>gcc:<optimization>off
     <toolset>intel:<optimization>off
     <toolset>pathscale:<optimization>off
     <toolset>pgi:<optimization>off
     <toolset>sun:<optimization>off
     <toolset>vacpp:<optimization>off
   ;

and for other performance critical files

obj options1
   : options1.C
   : <toolset>pgi,<variant>debug:<debug-symbols>off
     <toolset>pgi,<variant>debug:<optimization>speed
   ;

and others to work around compiler version or platform specific failures

obj ug3dh8
   : ug3dh8.cpp
   : <toolset>intel,<toolset-version>10.1,<instruction- 
set>itanium:<optimization>off
   ;

So many different combinations to handle.  I'm just looking for as  
concise a syntax as possible (well actually initially just want  
something that works, which I now have thanks to your help).

-- Noel




More information about the CMake mailing list