Fix cmake errors when attempting to get target properties on libs.

We should check first if the relevant library is a target or
a path to a library before getting the EXTERNAL_PROJECT and
IMPORTED_LOCATION properties.