If you use -save-temps=obj
the temporary files are put in the same directory as the output files, so e.g.
gcc -save-temps=obj -o dir/foo.o foo.c
will create dir/foo.i
This is documented in the manual, obviously. All supported options are listed at https://gcc.gnu.org/onlinedocs/gcc/Option-Summary.html and that links to https://gcc.gnu.org/onlinedocs/gcc/Developer-Options.html for -save-temps
.