Rebase and squashing all commits in JoakimSoderberg's cmake_patch branch to master to make it easier for review.

Library built OK on debian. But lots of check fails, see https://gist.github.com/rogerz/5108316

IMHO, all cmake files should be put under cmake directory. But I'm not an expert on it.