see our faq, the 7th and 8th items are about that error
however, I will say our release packages for the latest version only works with .NET 4.5.
It might still be possible to make a 4.0 build from source code, if you have a build machine that has only only 4.0 on it.
problem is 4.5 replaces 4.0 so on my machine if I try to build for 4.0 it builds but it really builds against 4.5 instead of 4.0. So I think you need a machine where 4.0 is installed but 4.5 has not been installed.
to compile it for 4.0 you have to use the net40.sln but you also have to replace web.config file contents with contents from web.net40.config in Web, Features.UI and WebStore projects