Copy the logic in the Avogadro application

This needs to be here to work with AvogadroLibs 0.6.0, but we should
probably move it to the config file as it really depends on how the
libraries were built.

Change-Id: I5d93c79bde853615e2c22c19518b6002d8b71e3e