Compile times depend on your hardware, and can easily take longer than 40 minutes. The only solution that I’ve heard of is to buy a better computer. More CPU cores being the critical thing that can help here.
I just reduced a complete rebuild of all engine source from about 8 hours to about an hour and a half by upgrading from a i7-4790 to an i7-10700.
The best solutions involve throwing more hardware at the problem, unfortunately – SSD will cut some hours off the build times from a spinning disk, and bigger CPUs will cut a lot more off.
Otherwise, try to avoid rebuilding the entire thing whenever possible. Once you have it built once, unless you make changes to the engine, you shouldn’t have to rebuild the whole kit.