Handle custom targets correctly.

If we want to add checks to a custom target, we need to both
run the checks PRE_BUILD (not PRE_LINK) and also filter out source
files which don't exist.