- inspired by a diff from yasuoka@, but rewritten to continue using cmake instead of switching to autoconf