[CMake] Always compile source file in debug
Belcourt, Kenneth
kbelco at sandia.gov
Fri Sep 3 10:13:22 EDT 2010
On Sep 3, 2010, at 5:07 AM, Eric Noulard wrote:
> 2010/9/3 Belcourt, Kenneth <kbelco at sandia.gov>:
>> Apologies if this has been answered before. In an effort to ensure
>> cross-platform consistent results, I need to force some (C++ and
>> Fortran)
>> source files to always be built debug. Is there any easy syntax to
>> do this?
>>
>> I build our libraries like this.
>>
>> SET(SRCS
>> ${EXEC_DIR}/AfterStep.f90
>> ${EXEC_DIR}/ArgCF_Connect.f90
>> ${EXEC_DIR}/ArgCF_Solve.f90
>> ...
>> )
>>
>> ADD_LIBRARY(exec ${SRCS})
>
> You may set some specific flags on specific sources using something
> like
>
> set_source_files_properties(file1.f90 file2.f90
> PROPERTIES
> COMPILE_FLAGS ${CMAKE_FORTRAN_FLAGS_DEBUG})
>
> but as far as I understand this does not replace default compile
> flags but add
> extra flags for those particular source files...
>
> Now if your "to be compiled with debug options" files may be
> contained in
> separate libraries, may be you can create a sub-project which
> contains those
> and enforce thsi subproject to be "CMAKE_BUILD_TYPE=Debug".
>
>
> 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.
Thanks for the help.
-- Noel
More information about the CMake
mailing list