For finite-horizon LQ, you basically apply dynamic programming (back backpropagation) to find the optimal control policy. See Chapter 11 of the book: Digital Control System Analysis & Design 4th Edition.
For the infinite-horizon counterpart, it reduces to the H2 optimization problem where you can use LMI or algebraic Ricatti equation to solve the optimal steady-state control gain.