You could use something similar to
which will not be defined when port4 does not exist
Unfortunately, this does not work,
as for instance for the mentioned device, CY8C2866LTI-067, port 3 does not exist (on the package),
but CYDEV_IO_PC_PRT3_BASE is defined,
I guess, you meant that when you wrote "CYDEV_PRT4_BASE"?
I did not find CYDEV_PRT1_BASE, for instance in my project with the mentioned device.
It seems that preprocessor definitions are done on a architecture level (e.g. PSoC 3),
reflecting the content of the "PSoC x Register TRM" without incorporating the limits of the chosen device.
I was checking a PSoC4-file, sorry, so the name I gave is different for PSoC 3/5.
Too bad that the generated files do not exclude non-existing ports. I would suggest to file a "MyCase" on this matter, probably there is a way to find out.