Openmpi linked to gcc

How do I install openmpi such that it is linked to gcc-9 in mac osx mojave?

First, I installed gcc-9 in macosx using the following command:

brew install gcc

Then, I installed openmpi using:

brew install openmpi

However, this openmpi is now linked to clang, which I don’t want to use at all.
I tried exporting HOMEBREW_CC=gcc-9 and HOMEBREW_CXX=g+±9, but this did not quite work since the ompi_info, shows:
C compiler: clang
C++ compiler: clang++

Please help!

You could make a copy of the openmpi formula in your own tap where you make it depend on gcc. See for more information on that.