bilke / cmake-modules

Additional CMake functionality. Most of the modules are from Ryan Pavlik (https://github.com/rpavlik/cmake-modules)
Boost Software License 1.0
548 stars 213 forks source link

CodeCoverage and Ninja #50

Closed mdavis777 closed 3 years ago

mdavis777 commented 4 years ago

I am trying to use CodeCoverage.cmake with Ninja. On build I always get this error: ninja: warning: phony target 'do_coverage' names itself as an input; ignoring [-w phonycycle=warn] ninja: error: build.ninja:176: multiple rules generate do_coverage [-w dupbuild=err]

Here is the snip it I have from my cmake file

    # Code Coverage
    #
    if(ENABLE_COVERAGE)
        include(CodeCoverage)
        append_coverage_compiler_flags()

        setup_target_for_coverage_lcov(
            NAME do_coverage                          # New target name
            EXECUTABLE ctest                          # Executable in PROJECT_BINARY_DIR
            EXCLUDE ("/usr/include/*" "UnitTests/*")  # Ignore UnitTests and system libraries
        )
mdavis777 commented 4 years ago

I was able to fix that issue by changing

        BYPRODUCTS
            ${Coverage_NAME}.base
            ${Coverage_NAME}.capture
            ${Coverage_NAME}.total
            ${Coverage_NAME}.info
            ${Coverage_NAME}

to

        BYPRODUCTS
            ${Coverage_NAME}.base
            ${Coverage_NAME}.capture
            ${Coverage_NAME}.total
            ${Coverage_NAME}.info
            ${Coverage_NAME}/index.html

I then ran more issues.
1:

    if(${Coverage_BASE_DIRECTORY})
        get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
    else()
        set(BASEDIR ${PROJECT_SOURCE_DIR})
    endif()

Always uses the default no matter if BASE_DIRECTORY is set or not. Fixed with:

    if(DEFINED Coverage_BASE_DIRECTORY)
        get_filename_component(BASEDIR ${Coverage_BASE_DIRECTORY} ABSOLUTE)
    else()
        set(BASEDIR ${PROJECT_SOURCE_DIR})
    endif()

After that there is something ninja does with relative paths that makes it impossible to find the source. It bases some things relative to the PROJECT_BINARY_DIRECTORY and some relative to PROJECT_SOURCE_DIR. Still working that part out.