[CMake] CHECK_C_COMPILER_FLAG macro not working for gcc's -fprofile-arcs flag

Mahendra Ladhe lml108 at yahoo.com
Thu Aug 14 11:00:33 EDT 2008


Hi,
  shown below is part of my CMakeLists.txt file

#To build the code for use with gcov, call cmake as below
#cmake -DGCOV=1 ..
IF (${GCOV})
    CHECK_C_COMPILER_FLAG (-fprofile-arcs FLAG_Gcov1)
    IF (FLAG_Gcov1)
      add_definitions (-fprofile-arcs)
    ELSE (FLAG_Gcov1)
      MESSAGE(FATAL_ERROR "Compiler does not support the -fprofile-arcs flag needed for using gcov")
    ENDIF (FLAG_Gcov1)
    CHECK_C_COMPILER_FLAG (-ftest-coverage FLAG_Gcov2)
    IF (FLAG_Gcov2)
      add_definitions (-ftest-coverage)
    ELSE (FLAG_Gcov2)
      MESSAGE(FATAL_ERROR "Compiler does not support the -ftest-coverage flag needed for using gcov")
    ENDIF (FLAG_Gcov2)
ENDIF (${GCOV})

I want to give user an option to compile the code for use with GCOV: the GNU code coverage tool. For this the code needs to be compiled with -fprofile-arcs and 
-ftest-coverage flags.

    When I invoke cmake as follows
cmake -DGCOV=1
I get the following error
CMake Error: Compiler does not support the -fprofile-arcs flag needed for using gcov

    Well, the gcc compiler on my Linux box does support -fprofile-arcs compilation flag.
The CMakeFiles/CMakeError.log shows the cause of error.

=========================================================================================
Performing C SOURCE FILE Test FLAG_Gcov1 failed with the following output:
/usr/bin/gmake -f CMakeFiles/cmTryCompileExec.dir/build.make CMakeFiles/cmTryCompileExec.dir/build
gmake[1]: Entering directory `/proj/magnum/mladhe/p4/L7/bld_x86/CMakeFiles/CMakeTmp'
/home/srgorti/freeware/usr/bin/cmake -E cmake_progress_report /proj/magnum/mladhe/p4/L7/bld_x86/CMakeFiles/CMakeTmp/CMakeFiles 1
Building C object CMakeFiles/cmTryCompileExec.dir/src.o
/usr/local/bin/gcc  -DFLAG_Gcov1   -fprofile-arcs -o CMakeFiles/cmTryCompileExec.dir/src.o   -c /proj/magnum/mladhe/p4/L7/bld_x86/CMakeFiles/CMakeTmp/src.c
Linking C executable cmTryCompileExec
/home/srgorti/freeware/usr/bin/cmake -P CMakeFiles/cmTryCompileExec.dir/cmake_clean_target.cmake
/usr/local/bin/gcc      -DFLAG_Gcov1  -fPIC "CMakeFiles/cmTryCompileExec.dir/src.o"   -o cmTryCompileExec -rdynamic 
CMakeFiles/cmTryCompileExec.dir/src.o(.text+0x43): In function `global constructors keyed to 0_main':
: undefined reference to `__gcov_init'
CMakeFiles/cmTryCompileExec.dir/src.o(.data+0x24): undefined reference to `__gcov_merge_add'
collect2: ld returned 1 exit status
gmake[1]: *** [cmTryCompileExec] Error 1
gmake[1]: Leaving directory `/proj/magnum/mladhe/p4/L7/bld_x86/CMakeFiles/CMakeTmp'
gmake: *** [cmTryCompileExec/fast] Error 2

Source file was:
int main() { return 0;}
=========================================================================================

So the reason is when source file is compiled with -fprofile-arcs, the cmake does not
supply the same flag while linking which the gcc needs as the object module has certain
gcov related code like functions gcov_init, gcov_merge_add etc.

Is there a workaround for this? I mean since gcc does support the -fprofile-arcs
compilation flag, how to make cmake believe this?

Thanking you,
Mahendra




      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.cmake.org/pipermail/cmake/attachments/20080814/9a427301/attachment-0001.htm>


More information about the CMake mailing list