[CMake] Improvements in dependency lookup