A very general Hamilton-Jacobi theorem