I recently needed to attach molding across the sides of some bookcases. Because the sides were solid wood, I had to allow for some seasonal movement. I used a table-mounted router with a keyhole bit and cut slots in the back of the molding, as shown above. I installed round-head screws and adjusted their height to fit snugly in the slots. Then I installed the trim and slid it forward to its final position and glued the front edge. This is a good way to make any cross-grain attachment.
The important note here is that only the end is glued. That way, the screws are free to slide in the slots as the solid side expands and contracts.