Makefiles: Fix CMAKE_EXPORT_COMPILE_COMMANDS crash with custom compile rule

Fixes: #21471
3 files changed