cmake: Fix build without thread support Only check for pthread.h if threads are enabled. Fixes #367.