]>
Commit | Line | Data |
---|---|---|
4b3ec53c XL |
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(LIBRARY) | |
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() |