| 1 | # - pkg-config module for CMake |
|---|
| 2 | # |
|---|
| 3 | # Defines the following macros: |
|---|
| 4 | # |
|---|
| 5 | # PKGCONFIG(package includedir libdir linkflags cflags) |
|---|
| 6 | # |
|---|
| 7 | # Calling PKGCONFIG will fill the desired information into the 4 given arguments, |
|---|
| 8 | # e.g. PKGCONFIG(libart-2.0 LIBART_INCLUDE_DIR LIBART_LINK_DIR LIBART_LINK_FLAGS LIBART_CFLAGS) |
|---|
| 9 | # if pkg-config was NOT found or the specified software package doesn't exist, the |
|---|
| 10 | # variable will be empty when the function returns, otherwise they will contain the respective information |
|---|
| 11 | # |
|---|
| 12 | |
|---|
| 13 | |
|---|
| 14 | |
|---|
| 15 | FIND_PROGRAM(PKGCONFIG_EXECUTABLE NAMES pkg-config PATHS /usr/local/bin ) |
|---|
| 16 | |
|---|
| 17 | MACRO(PKGCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags) |
|---|
| 18 | # reset the variables at the beginning |
|---|
| 19 | SET(${_include_DIR}) |
|---|
| 20 | SET(${_link_DIR}) |
|---|
| 21 | SET(${_link_FLAGS}) |
|---|
| 22 | SET(${_cflags}) |
|---|
| 23 | IF(MSVC) |
|---|
| 24 | SET(_msvc_mode --msvc-syntax) |
|---|
| 25 | ELSE(MSVC) |
|---|
| 26 | SET(_msvc_mode) |
|---|
| 27 | ENDIF(MSVC) |
|---|
| 28 | # if pkg-config has been found |
|---|
| 29 | IF(PKGCONFIG_EXECUTABLE) |
|---|
| 30 | |
|---|
| 31 | EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --exists RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull ) |
|---|
| 32 | |
|---|
| 33 | # and if the package of interest also exists for pkg-config, then get the information |
|---|
| 34 | IF(NOT _return_VALUE) |
|---|
| 35 | |
|---|
| 36 | EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_msvc_mode} ${_package} --variable=includedir OUTPUT_VARIABLE __include_DIR) |
|---|
| 37 | STRING(REPLACE "\n" "" ${_include_DIR} ${__include_DIR}) |
|---|
| 38 | |
|---|
| 39 | EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_msvc_mode} ${_package} --variable=libdir OUTPUT_VARIABLE __link_DIR) |
|---|
| 40 | STRING(REPLACE "\n" "" ${_link_DIR} ${__link_DIR}) |
|---|
| 41 | |
|---|
| 42 | EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_msvc_mode} ${_package} --libs OUTPUT_VARIABLE __link_FLAGS) |
|---|
| 43 | STRING(REPLACE "\n" "" ${_link_FLAGS} ${__link_FLAGS}) |
|---|
| 44 | |
|---|
| 45 | EXEC_PROGRAM(${PKGCONFIG_EXECUTABLE} ARGS ${_msvc_mode} ${_package} --cflags OUTPUT_VARIABLE __cflags) |
|---|
| 46 | STRING(REPLACE "\n" "" ${_cflags} ${__cflags}) |
|---|
| 47 | |
|---|
| 48 | ENDIF(NOT _return_VALUE) |
|---|
| 49 | |
|---|
| 50 | ENDIF(PKGCONFIG_EXECUTABLE) |
|---|
| 51 | |
|---|
| 52 | ENDMACRO(PKGCONFIG _include_DIR _link_DIR _link_FLAGS _cflags) |
|---|
| 53 | |
|---|
| 54 | MARK_AS_ADVANCED(PKGCONFIG_EXECUTABLE) |
|---|