Skip to content

Add -lpfm to pkg-config Libs.private when libpfm is enabled#2194

Open
kiwigitops wants to merge 1 commit into
google:mainfrom
kiwigitops:fix-pkgconfig-libpfm
Open

Add -lpfm to pkg-config Libs.private when libpfm is enabled#2194
kiwigitops wants to merge 1 commit into
google:mainfrom
kiwigitops:fix-pkgconfig-libpfm

Conversation

@kiwigitops
Copy link
Copy Markdown

Summary

When BENCHMARK_ENABLE_LIBPFM=ON, libpfm is linked into the benchmark library via the PFM::libpfm imported target. The pkg-config generation derives Libs.private from the target's LINK_LIBRARIES, but the loop only emits -l flags for entries that are not CMake targets. Imported targets like PFM::libpfm are silently skipped, so -lpfm never makes it into benchmark.pc.

As a result, projects that statically link benchmark through pkg-config fail to resolve pfm_initialize / pfm_get_os_event_encoding at link time.

This adds -lpfm to the private link libraries for the PFM::libpfm target, alongside the existing private dependencies (-lpthread, etc.).

Closes #1908.

Testing

  • git diff --check

Copy link
Copy Markdown
Collaborator

@LebedevRI LebedevRI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably be using get_target_property() instead of
guessing the lib name, oh, and, this seems to completely not handle -L?

The private link library derivation skips CMake targets, so the PFM::libpfm imported target was never translated into linker flags. Static consumers using pkg-config then fail to resolve pfm_* symbols. Resolve imported targets through their IMPORTED_LOCATION and emit the corresponding -L/-l flags alongside the other private libraries.
@kiwigitops kiwigitops force-pushed the fix-pkgconfig-libpfm branch from 568b121 to 4b81276 Compare May 22, 2026 00:51
@kiwigitops
Copy link
Copy Markdown
Author

Good points, updated. It now resolves the target via get_target_property(... IMPORTED_LOCATION) and derives the flags from the resolved path instead of hardcoding -lpfm, emitting both -L<dir> and -l<name>. So PFM::libpfm (or any imported private dependency) contributes its directory and library name to Libs.private.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] pkgconfig benchmark.pc not modified with addition of -lpfm when BENCHMARK_ENABLE_LIBPFM=On

2 participants