Use -pthread flag instead of -lpthread

The -pthread flag should be used for compiling with threads as it sets
flags for both the preprocessor and linker.

In cmake this is achieved with the set(THREADS_PREFER_PTHREAD_FLAG TRUE)
before find_package(Threads) and using the Threads::Threads import target.

Also added set(CMAKE_THREAD_PREFER_PTHREAD TRUE) as we only support
pthread on non windows platforms.
3 files changed