# Getting pthreads cflags and library flags from Threads::Threads

**URL:** <https://discourse.cmake.org/t/getting-pthreads-cflags-and-library-flags-from-threads-threads/10304>\
**Category:** Code\
**Created:** [March 6, 2024, 11:09am UTC](https://discourse.cmake.org/t/getting-pthreads-cflags-and-library-flags-from-threads-threads/10304 "2024-03-06T11:09:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mdorier](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/m/eb9ed0/32.png) [@mdorier](https://discourse.cmake.org/u/mdorier)\
**Post date:** [March 6, 2024, 11:09am UTC](https://discourse.cmake.org/t/getting-pthreads-cflags-and-library-flags-from-threads-threads/10304/1 "2024-03-06T11:09:13Z")

</div>

I am porting a C library from autotools to cmake. The library depends on pthreads, which with autotools is detected using an `AX_PTHREAD` macro from an `ax_pthread.m4` file. This macro sets `PTHREAD_LIBS` and `PTHREAD_CFLAGS` appropriately for the target platform.

In cmake, I am replacing this with a `find_package(Threads REQUIRED)` and `target_link_libraries( ... Threads::Threads)`.

One thing I can’t figure out how to do however is this: my library has a .pc file for pkg-config which is generated (currently by autotools) from a .pc.in file which relies on `PTHREAD_LIBS` and `PTHREAD_CFLAGS` to know what cflags and libs pkg-config should return. I am replacing the generation of this .pc file with cmake’s `configure_file (...)`, but I don’t know how to get the equivalent of `PTHREAD_LIBS` and `PTHREAD_CFLAGS` from the `Threads::Threads` target. How can I do that?

---

<div class="post-metadata">

**Author:** ![ben.boeckel](https://discourse.cmake.org/letter_avatar_proxy/v4/letter/b/ea5d25/32.png) [@ben.boeckel](https://discourse.cmake.org/u/ben.boeckel)\
**Post date:** [April 10, 2024, 9:36pm UTC](https://discourse.cmake.org/t/getting-pthreads-cflags-and-library-flags-from-threads-threads/10304/2 "2024-04-10T21:36:03Z")

</div>

You should be able to use `$<TARGET_PROPERTY:Threads::Threads:INTERFACE_COMPILE_OPTIONS>` and the like. You’ll then need `file(GENERATE)` instead of `configure_file()`.
