0

I'm trying to get the exact commands that CMake invokes during the build process, specifically for clang tidy and cppcheck (using either Ninja or Makefiles).

As a result of my configuration, the compilation command for a given translation unit looks like this:

 /usr/bin/cmake -E __run_co_compile --launcher=/usr/bin/ccache --tidy="/usr/bin/clang-tidy;-extra-arg=-Wno-unknown-warning-option;-extra-arg=-std=gnu++20;--extra-arg-before=--driver-mode=g++" --cppcheck="/usr/bin/cppcheck;--template=gcc;--enable=style,performance,warning,portability;--inline-suppr;--suppress=internalAstError;--suppress=unmatchedSuppression;--inconclusive;--std=c++20" --source=/home/fred/code/cpp/me/cpp-template/lib/account/test/account_test.cpp -- /usr/bin/c++  -I/home/fred/code/cpp/me/cpp-template/build/_deps/catch2-src/src/catch2/.. -I/home/fred/code/cpp/me/cpp-template/build/_deps/catch2-build/generated-includes -I/home/fred/code/cpp/me/cpp-template/lib/account/include -m64 -g -std=gnu++20 -fdiagnostics-color=always --coverage -O0 -g -fsanitize=address,pointer-compare,pointer-subtract,undefined -Wall -Wextra -Wextra-semi -Wcast-align -Wdouble-promotion -Wduplicated-cond -Wduplicated-branches -Wformat=2 -Wimplicit-fallthrough -Wmisleading-indentation -Wlogical-op -Wnon-virtual-dtor -Wnull-dereference -Wold-style-cast -Wsuggest-override -Woverloaded-virtual -Wpedantic -Wshadow -Wno-sign-conversion -Wunused -Wuseless-cast -MD -MT lib/account/CMakeFiles/account_account_test.dir/test/account_test.cpp.o -MF lib/account/CMakeFiles/account_account_test.dir/test/account_test.cpp.o.d -o lib/account/CMakeFiles/account_account_test.dir/test/account_test.cpp.o -c /home/fred/code/cpp/me/cpp-template/lib/account/test/account_test.cpp

I'm getting some cppcheck errors, but I'd like to recover the exact way CMake invoked this. When I took the "CMake list" value for the arguments and pasted them together in the command line to manually run it, I was unable to reproduce the error.

How can I get CMake to output all of the exact commands it invokes during the build process (not the configure process; --trace-expand and friends are great for that, but those didn't seem to help much)?

Sam
  • 427
  • 3
  • 14
  • Are you looking for [compile_commands.json](https://cmake.org/cmake/help/latest/variable/CMAKE_EXPORT_COMPILE_COMMANDS.html)? – Yksisarvinen Aug 13 '23 at 20:07
  • No, I already looked through there and that only includes the compiler commands. What I'm looking for is the tooling commands that are invoked by cmake (e.g. when one sets `CMAKE_CXX_CPPCHECK`). – Sam Aug 13 '23 at 20:41
  • https://stackoverflow.com/questions/2670121/using-cmake-with-gnu-make-how-can-i-see-the-exact-commands ? – Yksisarvinen Aug 13 '23 at 21:54
  • This is a useful step, but it is one I already took (and how I got the `cmake` invocation in the question text). See my comment on Ben A's answer about this (it's similar). – Sam Aug 14 '23 at 04:39

2 Answers2

1

One can pass custom command to invoke clan-tidy via CMAKE_<LANG>_CLANG_TIDY.

So you can try something like

set(CMAKE_CXX_CLANG_TIDY "echo;--here")

option --here is added to easily find the output - there can be any custom line you prefer to grep over output

For cppcheck try CMAKE_<LANG>_CPPCHECK

vsh
  • 301
  • 2
  • 10
0

ninja -v or make VERBOSE=1 should do the trick.

Ben A.
  • 874
  • 7
  • 23
  • This doesn't quite work. I actually got that cmake invocation in my question text from running `ninja -v`. It seems like one of the cmake rules for building with cppcheck and clang tidy is to invoke itself (with that `-E __run_co_compile` option). I basically want the commands that *that* sub-invocation calls. – Sam Aug 14 '23 at 04:38