0

I'm trying to create a cmake (3.22) function that creates a target called cppclean for the target that I provide in the arguments

function (cppclean target)
    if(${STATIC_CODE_ANALYSIS})
        find_program(CPP_CLEAN cppclean)
        if(CPP_CLEAN)
            add_custom_target(cppclean
                COMMAND ${CPP_CLEAN} "--include-path $<JOIN:$<TARGET_PROPERTY:${target},INCLUDE_DIRECTORIES>, --include-path >" $<TARGET_PROPERTY:${target},SOURCE_DIR>
                VERBATIM
                COMMAND_EXPAND_LISTS
            )
        else()
            message("Cannot find cppclean")
        endif()
    endif()
endfunction()

However I doesn't work with the error:

No such file or directory: '--include-path ... --include-path ... --include-path ...'

When I look at the make file that is created I indeed see the quotes around the expanded generator expression which is probably wrong.

If I remove the quotes around the generator expression it gives a different error:

cannot create /home/foo/src: Is a directory

And the make file shows that the JOIN expression is not expanded.

How to fix this?

Frank
  • 2,446
  • 7
  • 33
  • 67
  • 1
    Yes you have to remove the quotes around the generator expression. Otherwise it's handled as one argument which is wrong. Did you already tried to reverse the arguments, e.g. `COMMAND ${CPP_CLEAN} $ --include-path $, --include-path >` ? According to the man pages for cppclean (https://linuxcommandlibrary.com/man/cppclean) the project source directory should be the only or the first argument. – vre Jan 06 '22 at 15:32
  • If I remove the quotes the join is not expanded, irrelevant of the order. Also the git page (https://github.com/myint/cppclean) says usage is: `cppclean --include-path=directory1 --include-path=directory2 ` – Frank Jan 06 '22 at 15:58
  • 1
    Rereading the docs: what happens if you change your generator expression to `"--include-path $,;--include-path >"`? – vre Jan 06 '22 at 16:20
  • Then I get multiple error: `No such file or directory: '--include-path ../include1' No such file or directory: '--include-path ../include2'` The make file now has quotes around every `--include-dirs ...` – Frank Jan 06 '22 at 16:31
  • Whats the working directory you are trying to run your cppclean command in? You may need to specify that with the `WORKING_DIRECTORY` property in the custom target. – vre Jan 06 '22 at 16:35
  • I notice that without the `verbatim` the quotes are not in the make file and the expression is expanded. However then it joins with backslashes which cause problems \ --include-path\. The working directory does not seem to matter. – Frank Jan 06 '22 at 16:55
  • 1
    Ok I got it to work using https://stackoverflow.com/questions/65450808/cmake-remove-escape-character-from-generator-expresion. If you take out the generator expression it seems to work. – Frank Jan 06 '22 at 17:03

0 Answers0