The top moulding is made the same way as the base moulding. I ripped all the parts to finished width first, so every piece was already the right size before any mitres were cut. Then I cut a mitre on one end of two pieces, so they would meet to form a corner.
I took those two pieces to the top of the bookshelf, fitted the mitres together without glue and clamped...