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
547 stars 214 forks source link

if(${Coverage_BASE_DIRECTORY}) evaluates wrongly #55

Open gvergine opened 3 years ago

gvergine commented 3 years ago

Hello,

I have a problem defining the BASE_DIRECTORY in CodeCoverage.cmake: https://github.com/bilke/cmake-modules/blob/0503702f2ef733aa8f6a0c2015db89b085c5ac57/CodeCoverage.cmake#L212

I think if(${Coverage_BASE_DIRECTORY}) evaluates wrongly, probably should be without the parenthesis.

Here I attache a small test:

project(Test)
cmake_minimum_required(VERSION 3.5)
function(f)
    set(options NO_DEMANGLE)
    set(oneValueArgs BASE_DIRECTORY NAME)
    set(multiValueArgs EXCLUDE EXECUTABLE EXECUTABLE_ARGS DEPENDENCIES LCOV_ARGS GENHTML_ARGS)
    cmake_parse_arguments(Coverage "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
    message("Coverage_BASE_DIRECTORY should be defined as ${Coverage_BASE_DIRECTORY}")
    if(${Coverage_BASE_DIRECTORY})
        message("but is defined as ${Coverage_BASE_DIRECTORY}")
    else()
        message("but is not defined")
    endif()
    if(Coverage_BASE_DIRECTORY)
        message("[with fix]: is defined as ${Coverage_BASE_DIRECTORY}")
    else()
        message("[with fix]: is not defined")
    endif()
endfunction()
f(BASE_DIRECTORY "TEST1")
f()

That on my machine (amd64, ubuntu 20.04, cmake 3.16) produces:

Coverage_BASE_DIRECTORY should be defined as TEST1
but is not defined
[with fix]: is defined as TEST1
Coverage_BASE_DIRECTORY should be defined as 
but is not defined
[with fix]: is not defined

I found this line because I'm using lcov, but probably same thing applies for gcov sections.

Cheers!