Split cmake thread detection into core thread and thread_mpi.

This makes it possible to use core threading facilities
(mutex/cond-var/affinity, etc) on builds that don't use thread_mpi.

Change-Id: I0f0f43e86da642c4645fd7ac3c4796098cf9cd5e