Skip to content

Commit d9ed709

Browse files
authored
Refactor: derive pkg-config info to link static libraries (#1998)
1 parent 1b721bb commit d9ed709

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

src/CMakeLists.txt

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ endif(HAVE_LIB_RT)
6262
# We need extra libraries on Windows
6363
if(${CMAKE_SYSTEM_NAME} MATCHES "Windows")
6464
target_link_libraries(benchmark PRIVATE shlwapi)
65-
set(BENCHMARK_PRIVATE_LINK_LIBRARIES -lShlwapi)
6665
endif()
6766

6867
# We need extra libraries on Solaris
6968
if(${CMAKE_SYSTEM_NAME} MATCHES "SunOS")
7069
target_link_libraries(benchmark PRIVATE kstat)
71-
set(BENCHMARK_PRIVATE_LINK_LIBRARIES -lkstat)
7270
endif()
7371

7472
if (NOT BUILD_SHARED_LIBS)
@@ -110,6 +108,20 @@ write_basic_package_version_file(
110108
"${version_config}" VERSION ${GENERIC_LIB_VERSION} COMPATIBILITY SameMajorVersion
111109
)
112110

111+
# Derive private link libraries from target
112+
if(NOT BUILD_SHARED_LIBS)
113+
get_target_property(LINK_LIBS benchmark LINK_LIBRARIES)
114+
if(LINK_LIBS)
115+
set(BENCHMARK_PRIVATE_LINK_LIBRARIES "")
116+
foreach(LIB IN LISTS LINK_LIBS)
117+
if(NOT TARGET "${LIB}" AND LIB MATCHES "^[a-zA-Z0-9_.-]+$")
118+
list(APPEND BENCHMARK_PRIVATE_LINK_LIBRARIES "-l${LIB}")
119+
endif()
120+
endforeach()
121+
string(JOIN " " BENCHMARK_PRIVATE_LINK_LIBRARIES ${BENCHMARK_PRIVATE_LINK_LIBRARIES})
122+
endif()
123+
endif()
124+
113125
configure_file("${PROJECT_SOURCE_DIR}/cmake/benchmark.pc.in" "${pkg_config}" @ONLY)
114126
configure_file("${PROJECT_SOURCE_DIR}/cmake/benchmark_main.pc.in" "${pkg_config_main}" @ONLY)
115127

0 commit comments

Comments
 (0)