Modify CMake script to build correctly on more platforms

These changes have been tested on Gentoo x86_64 and Debian armhf

Signed-off-by: Paul Jones <paul@pauljones.id.au>