Skip to content

Commit b257e8a

Browse files
[Microbench] Sync with google/benchmark to change FindPFM.cmake (#198)
libpfm only contains dynamic library in some of our environments. Since we don't actually static link them, only find dynamic library is enough. This also aligns with LLVM's configuration https://github.com/llvm/llvm-project/blob/7d5376270ae5807a29597a91d7cf59f967ccf39e/llvm/cmake/modules/FindLibpfm.cmake#L13 Cherry-picked from: google/benchmark@a092f82 Signed-off-by: Peter Rong <[email protected]>
1 parent a5f02a8 commit b257e8a

File tree

1 file changed

+21
-14
lines changed

1 file changed

+21
-14
lines changed
Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,33 @@
11
# If successful, the following variables will be defined:
2-
# HAVE_LIBPFM.
3-
# Set BENCHMARK_ENABLE_LIBPFM to 0 to disable, regardless of libpfm presence.
4-
include(CheckIncludeFile)
5-
include(CheckLibraryExists)
2+
# PFM_FOUND.
3+
# PFM_LIBRARIES
4+
# PFM_INCLUDE_DIRS
5+
# the following target will be defined:
6+
# PFM::libpfm
7+
68
include(FeatureSummary)
7-
enable_language(C)
9+
include(FindPackageHandleStandardArgs)
810

911
set_package_properties(PFM PROPERTIES
1012
URL http://perfmon2.sourceforge.net/
11-
DESCRIPTION "a helper library to develop monitoring tools"
13+
DESCRIPTION "A helper library to develop monitoring tools"
1214
PURPOSE "Used to program specific performance monitoring events")
1315

14-
check_library_exists(libpfm.a pfm_initialize "" HAVE_LIBPFM_INITIALIZE)
15-
if(HAVE_LIBPFM_INITIALIZE)
16-
check_include_file(perfmon/perf_event.h HAVE_PERFMON_PERF_EVENT_H)
17-
check_include_file(perfmon/pfmlib.h HAVE_PERFMON_PFMLIB_H)
18-
check_include_file(perfmon/pfmlib_perf_event.h HAVE_PERFMON_PFMLIB_PERF_EVENT_H)
19-
if(HAVE_PERFMON_PERF_EVENT_H AND HAVE_PERFMON_PFMLIB_H AND HAVE_PERFMON_PFMLIB_PERF_EVENT_H)
16+
find_library(PFM_LIBRARY NAMES pfm)
17+
find_path(PFM_INCLUDE_DIR NAMES perfmon/pfmlib.h)
18+
19+
find_package_handle_standard_args(PFM REQUIRED_VARS PFM_LIBRARY PFM_INCLUDE_DIR)
20+
21+
if (PFM_FOUND AND NOT TARGET PFM::libpfm)
22+
add_library(PFM::libpfm UNKNOWN IMPORTED)
23+
set_target_properties(PFM::libpfm PROPERTIES
24+
IMPORTED_LOCATION "${PFM_LIBRARY}"
25+
INTERFACE_INCLUDE_DIRECTORIES "${PFM_INCLUDE_DIR}")
2026
message("Using Perf Counters.")
2127
set(HAVE_LIBPFM 1)
2228
set(PFM_FOUND 1)
23-
endif()
2429
else()
25-
message("Perf Counters support requested, but was unable to find libpfm.")
30+
message("Perf Counters support requested, but was unable to find libpfm.")
2631
endif()
32+
33+
mark_as_advanced(PFM_LIBRARY PFM_INCLUDE_DIR)

0 commit comments

Comments
 (0)