Do not cache the variables for libraries in extern
Fix some logic in searching for dependencies

Also add variables YARP_HAS_SYSTEM_XXX for each dependency