Revert "Revert "Optimize the CM builds""

This reverts commit 01a61843642f409d2afdd3f79a88a71f3e0ec766.