output of cmake command to a file

I’m trying to get the output of my compiler while building a project (with the command cmake --build build_dir --target all -- -j 3)
Because I want every target to be printed in a separate file, I can’t use simple piping mechanism.
Is there a way to tell the cmake to print its output to a file?
Something like a flag to output not just the .o files, but also the compiler stdout stream?

You might be able to do this by writing a custom compiler wrapper and setting it via CMAKE_<LANG>_COMPILER_LAUNCHER. This would give you full control over each compiler invocation.