FindThreads: -pthread is still needed even if -lpthread is not required for glibc 2.34
Since glibc 2.34, libpthread becomes builtin and -lpthread is no longer required. Currently, if CMake finds linking with -lpthread is unnecessary, it doesn't add the -pthread flag. But afaik, glibc 2.34 hasn't specifically state -pthread is not required. In fact, some architectures still need the -pthread flag for defining necessary macros ( or even linking with libatomic as in riscv ).
I think -pthread flag should be kept in some cases even if linking with libpthread is not needed.
I currently have to use this as a workaround
set(THREADS_PREFER_PTHREAD_FLAG TRUE)
find_package(Threads REQUIRED)
if(CMAKE_USE_PTHREADS_INIT)
target_link_libraries(Threads::Threads INTERFACE -pthread)
endif()
Edited by Alex Fan