Kitty is sending you major signs, in the only way he knows how to get your attention. Like a greeting card with poop in it.
There are cats that just shouldn't be around dogs. Even the friendliest of dogs.

Kitty needs to be confined to one small, safe area. Bed + bath?
His spraying and defecating behavior need to be resolved there before he can be given a larger territory, especially where the dog is nearby.

Once you can get him stable and not spraying, try the baby gates. Sounds like this kitty never should have direct access to the dog. My guess is he's not feeling safe. I think he can learn to relax, if he knows the dog cannot get him (not that the dog would- but in the cat's mind he could)

I hope your kitty finds some solace.

Good luck.