[CMake] option for gcov coverage and overriding optimization flag

Zaak Beekman zbeekman at gmail.com
Fri Jun 12 13:46:04 EDT 2015


I’m having trouble determining the right way to enforce `-O0` optimization
level when the user selects a boolean cache entry to  enable code coverage
with gcov. I tried something like:

if ( ENABLE_CODE_COVERAGE )
      set ( CMAKE_Fortran_FLAGS “${CMAKE_Fortran_FLAGS} -fprofile-arcs
-ftest-coverage -O0” )

but the issue is that the CMAKE_Fortran_FLAGS_<RELEASE|DEBUG|…> flags get
appended to the compiler flags so gfortran gets passed something like:

`gfortran -fprofile-arcs -ftest-coverage -O0 … -O3 …`

and since the `-O3` the right-most optimization option it takes precedent
over `-O0`.

What is the correct way to either ensure that `-O0` comes after `-O3` when
the user selects ENABLE_CODE_COVERAGE=TRUE or remove `-O3` entirely? Note
that CMAKE_Fortran_FLAGS_<…> are all (advanced) cache variables, and I
would like to let advanced users have the option to re-enable optimization
here should they so choose…
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/cmake/attachments/20150612/27a35795/attachment.html>


More information about the CMake mailing list