Improve CMake library determination