1# Distributed under the OSI-approved BSD 3-Clause License. See accompanying 2# file Copyright.txt or https://cmake.org/licensing for details. 3 4#[=======================================================================[.rst: 5UsePkgConfig 6------------ 7 8Obsolete pkg-config module for CMake, use FindPkgConfig instead. 9 10 11 12This module defines the following macro: 13 14PKGCONFIG(package includedir libdir linkflags cflags) 15 16Calling PKGCONFIG will fill the desired information into the 4 given 17arguments, e.g. PKGCONFIG(libart-2.0 LIBART_INCLUDE_DIR 18LIBART_LINK_DIR LIBART_LINK_FLAGS LIBART_CFLAGS) if pkg-config was NOT 19found or the specified software package doesn't exist, the variable 20will be empty when the function returns, otherwise they will contain 21the respective information 22#]=======================================================================] 23 24find_program(PKGCONFIG_EXECUTABLE NAMES pkg-config ) 25 26macro(PKGCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags) 27 message(STATUS 28 "WARNING: you are using the obsolete 'PKGCONFIG' macro, use FindPkgConfig") 29# reset the variables at the beginning 30 set(${_include_DIR}) 31 set(${_link_DIR}) 32 set(${_link_FLAGS}) 33 set(${_cflags}) 34 35 # if pkg-config has been found 36 if(PKGCONFIG_EXECUTABLE) 37 38 exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --exists RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull ) 39 40 # and if the package of interest also exists for pkg-config, then get the information 41 if(NOT _return_VALUE) 42 43 exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=includedir 44 OUTPUT_VARIABLE ${_include_DIR} ) 45 string(REGEX REPLACE "[\r\n]" " " ${_include_DIR} "${${_include_DIR}}") 46 47 48 exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=libdir 49 OUTPUT_VARIABLE ${_link_DIR} ) 50 string(REGEX REPLACE "[\r\n]" " " ${_link_DIR} "${${_link_DIR}}") 51 52 exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --libs 53 OUTPUT_VARIABLE ${_link_FLAGS} ) 54 string(REGEX REPLACE "[\r\n]" " " ${_link_FLAGS} "${${_link_FLAGS}}") 55 56 exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --cflags 57 OUTPUT_VARIABLE ${_cflags} ) 58 string(REGEX REPLACE "[\r\n]" " " ${_cflags} "${${_cflags}}") 59 60 else() 61 62 message(STATUS "PKGCONFIG() indicates that ${_package} is not installed (install the package which contains ${_package}.pc if you want to support this feature)") 63 64 endif() 65 66 # if pkg-config has NOT been found, INFORM the user 67 else() 68 69 message(STATUS "WARNING: PKGCONFIG() indicates that the tool pkg-config has not been found on your system. You should install it.") 70 71 endif() 72 73endmacro() 74 75mark_as_advanced(PKGCONFIG_EXECUTABLE) 76