[CMake] Improvements on dependency lookup