google / benchmark

A microbenchmark support library
Apache License 2.0
8.69k stars 1.59k forks source link

Update CMake threads library detection #1602

Closed mosullivan93 closed 1 year ago

mosullivan93 commented 1 year ago

When glibc < 2.34, -lpthread or -pthread needs to be present in order for this project to be linked successfully. CMake provides the @CMAKE_THREAD_LIBS_INIT@ variable that will expand to the necessary flag. This will typically expand to -lpthreads, but users can override this behaviour if they wish by setting the THREADS_PREFER_PTHREAD_FLAG variable to TRUE/ON/etc.

This patch ensures the thread library is always present in the linker options and restores the default behaviour.

mosullivan93 commented 1 year ago

@LebedevRI @dmah42 I'm happy to close this PR. I've learned that if using pkg-config on its own you need to include the --static flag to resolve the correct linker arguments. That fixes my original problem: broken in glibc 2.31, working in glibc 2.35.

I get the feeling it's best to keep things as they are (where you've had no complaints for quite some time) rather than change these flags in order to allow it to accidentally work correctly across both libc environments.

LebedevRI commented 1 year ago

@LebedevRI @dmah42 I'm happy to close this PR. I've learned that if using pkg-config on its own you need to include the --static flag to resolve the correct linker arguments. That fixes my original problem: broken in glibc 2.31, working in glibc 2.35.

Nice!

I get the feeling it's best to keep things as they are (where you've had no complaints for quite some time) rather than change these flags in order to allow it to accidentally work correctly across both libc environments.

Yeah, i think the LHS of the diff isn't incorrect.