Optimality Conditions for Rank-Constrained Matrix Optimization