Improve feature detection in configure.
Merge pull request #521 from SaberUK/master+configure-tests

Improve feature detection in configure.