Elasticity theory of pseudomorphic heterostructures grown on substrates of arbitrary thickness