ACTION_IF (MOD_IS_INSTALLED ~setup-gavin.tp2~ ~1~) BEGIN // compile Gavin romance crossmod ENDwould work here. I think it's safe to assume that an NPC mod will enforce dependency among its own components, so if you check for the component that adds the dialogue you are patching, it should work in all cases (if not, it is the fault of the other mod and the mistake of the player who skipped the core of the mod in question). BWS also usually enforces dependency rules of later components that rely on a main component.
Of course if another mod with which you want to apply cross-mod changes its structure on a new version, you will have a compatibility problem. I don't think that is very common, but to prevent the possibility of errors like that halting installation of the rest of your mod, you can use WeiDU's ACTION_TRY or PATCH_TRY (scroll to the bottom of the linked section, as the upper part covers MATCH, while TRY is discussed below).