Add before add_executable():
set(CMAKE_CXX_FLAGS -pthread) message(STATUS "CMAKE_CXX_FLAGS = ${CMAKE_CXX_FLAGS}")