| 1 |
include(FindPkgConfig) |
| 2 |
|
| 3 |
# This function will find and set up a pkg-config based module. |
| 4 |
# If a pc-file was found, it will resolve library paths to |
| 5 |
# absolute paths. Furthermore, the function will automatically |
| 6 |
# fall back to use static libraries in case no dynamic libraries |
| 7 |
# were found. |
| 8 |
function(FIND_PKGLIBRARIES prefix package) |
| 9 |
pkg_check_modules(${prefix} ${package}) |
| 10 |
if(NOT ${prefix}_FOUND) |
| 11 |
return() |
| 12 |
endif() |
| 13 |
|
| 14 |
foreach(LIBRARY ${${prefix}_LIBRARIES}) |
| 15 |
find_library(${LIBRARY}_RESOLVED ${LIBRARY} PATHS ${${prefix}_LIBRARY_DIRS}) |
| 16 |
if(${${LIBRARY}_RESOLVED} STREQUAL "${LIBRARY}_RESOLVED-NOTFOUND") |
| 17 |
message(FATAL_ERROR "could not resolve ${LIBRARY}") |
| 18 |
endif() |
| 19 |
list(APPEND RESOLVED_LIBRARIES ${${LIBRARY}_RESOLVED}) |
| 20 |
endforeach() |
| 21 |
|
| 22 |
set(${prefix}_FOUND 1 PARENT_SCOPE) |
| 23 |
set(${prefix}_LIBRARIES ${RESOLVED_LIBRARIES} PARENT_SCOPE) |
| 24 |
set(${prefix}_INCLUDE_DIRS ${${prefix}_INCLUDE_DIRS} PARENT_SCOPE) |
| 25 |
set(${prefix}_LDFLAGS ${${prefix}_LDFLAGS} PARENT_SCOPE) |
| 26 |
|
| 27 |
message(STATUS " Resolved libraries: ${RESOLVED_LIBRARIES}") |
| 28 |
endfunction() |