A general approach to Camacho-Sad-like index theorems