You will basically need everything. I got a '91 M5 engine/drivetrain swapped into my '93 525i and I basically needed everything. From the whole wiring loom, computer, mounts/stands, even the old brackets like the ones for the ancillaries and air filter box were rewelded into my car and painted. I had difficulties with the A/C, where the M5 has a separate module for it and the 525i doesn't. So direct wiring through the hundreds of wires from the compressor to the switch. The tachometer wouldn't even work well(would fluctuate)because of the signal variability through the wiring. SO I had to use my old one while the speedo works. My power steering pump had to be custom mounted and belted. The swap can be done, but you have to think extensively about all the little things. Here are some I can think of:
-is the engine compartment high enough
-A/C
-Compatibility with the gauge cluster
-Power steering
-The computers' fitment and compatibility (e.g. what would happen with the Dynamic Stability Control as it also controls some of the engine input)
-torque braking components(even the e39 540i has some different suspension components changed for the M5, like rear control arms. The M5 has some beefier suspension borrowed from the e38 7-series and the e39 wagon)
-would the oil pan fit over the front sub-frame
-Possibly need dual exhaust system

Mark J