CTest with clang+llvm-cov fails with "Cannot find file" when AUTOMOC is used
I've run into an issue which appears when using the AUTOMOC feature and when trying to do coverage with CTest and clang/llvm-cov.
I've cut it down to this minimal test case: strange-ctest-problem.tar
estan@edison:~$ tar xf strange-ctest-problem.tar
estan@edison:~$ cd strange-ctest-problem
Running CTestScriptGood.cmake
works fine:
estan@edison:~/strange-ctest-problem$ ctest -S CTestScriptGood.cmake
Each . represents 1024 bytes of output
. Size of output: 0K
Each symbol represents 1024 bytes of output.
'!' represents an error and '*' a warning.
. Size of output: 0K
estan@edison:~/strange-ctest-problem$ echo $?
0
estan@edison:~/strange-ctest-problem$
But running CTestScriptBad.cmake
fails like this:
estan@edison:~/strange-ctest-problem$ ctest -S CTestScriptBad.cmake
Each . represents 1024 bytes of output
. Size of output: 0K
Each symbol represents 1024 bytes of output.
'!' represents an error and '*' a warning.
. Size of output: 0K
Cannot find file: /home/estan/strange-ctest-problem-build/Testing/strange-ctest-problem/mytest.h
estan@edison:~/strange-ctest-problem$ echo $?
255
estan@edison:~/strange-ctest-problem$
That path seems strange to me, why is it looking for source files in the Testing dir in the build dir?
The difference between CTestScriptGood.cmake
and CTestScriptBad.cmake
is:
--- CTestScriptGood.cmake 2019-11-30 08:58:53.729531100 +0100
+++ CTestScriptBad.cmake 2019-11-30 08:58:53.729531100 +0100
@@ -2,12 +2,15 @@
set(CTEST_BINARY_DIRECTORY ${CTEST_SCRIPT_DIRECTORY}/../strange-ctest-problem-build)
set(CTEST_CMAKE_GENERATOR "Unix Makefiles")
-set(CTEST_COVERAGE_COMMAND "gcov")
+set(CTEST_COVERAGE_COMMAND "llvm-cov-8")
+set(CTEST_COVERAGE_EXTRA_FLAGS "gcov")
list(APPEND CTEST_CUSTOM_COVERAGE_EXCLUDE ".*/moc_.*")
set(CONFIGURE_OPTIONS
"-DCMAKE_BUILD_TYPE=Debug"
+ "-DCMAKE_CXX_COMPILER=clang++-8"
+ "-DCMAKE_C_COMPILER=clang-8"
"-DCMAKE_CXX_FLAGS=-g -O0 --coverage"
"-DCMAKE_C_FLAGS=-g -O0 --coverage"
"-DCMAKE_EXE_LINKER_FLAGS=--coverage"
So the only difference is that gcc/gcov
is used in the former, and clang/llvm-cov
in the latter.
Another thing which "solves" the problem is to remove the use of AUTOMOC
.
Versions used:
estan@edison:~/strange-ctest-problem$ cmake --version
cmake version 3.16.0
CMake suite maintained and supported by Kitware (kitware.com/cmake).
estan@edison:~/strange-ctest-problem$ gcc --version
gcc (Ubuntu 7.4.0-1ubuntu1~18.04.1) 7.4.0
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
estan@edison:~/strange-ctest-problem$ clang-8 --version
clang version 8.0.0-3~ubuntu18.04.1 (tags/RELEASE_800/final)
Target: x86_64-pc-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
estan@edison:~/strange-ctest-problem$ llvm-cov-8 --version
LLVM (http://llvm.org/):
LLVM version 8.0.0
Optimized build.
Default target: x86_64-pc-linux-gnu
Host CPU: skylake
estan@edison:~/strange-ctest-problem$
Here is the log from ctest -VV -S CTestScriptBad.cmake
: CTestScriptBad.cmake.log