Imported Upstream version 2.8.10.2
[platform/upstream/cmake.git] / Modules / UsePkgConfig.cmake
1 # - Obsolete pkg-config module for CMake, use FindPkgConfig instead.
2 #
3 # This module defines the following macro:
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
11 # the respective information
12 #
13
14 #=============================================================================
15 # Copyright 2006-2009 Kitware, Inc.
16 #
17 # Distributed under the OSI-approved BSD License (the "License");
18 # see accompanying file Copyright.txt for details.
19 #
20 # This software is distributed WITHOUT ANY WARRANTY; without even the
21 # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
22 # See the License for more information.
23 #=============================================================================
24 # (To distribute this file outside of CMake, substitute the full
25 #  License text for the above reference.)
26
27 find_program(PKGCONFIG_EXECUTABLE NAMES pkg-config )
28
29 macro(PKGCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
30   message(STATUS
31     "WARNING: you are using the obsolete 'PKGCONFIG' macro, use FindPkgConfig")
32 # reset the variables at the beginning
33   set(${_include_DIR})
34   set(${_link_DIR})
35   set(${_link_FLAGS})
36   set(${_cflags})
37
38   # if pkg-config has been found
39   if(PKGCONFIG_EXECUTABLE)
40
41     exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --exists RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull )
42
43     # and if the package of interest also exists for pkg-config, then get the information
44     if(NOT _return_VALUE)
45
46       exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=includedir
47         OUTPUT_VARIABLE ${_include_DIR} )
48       string(REGEX REPLACE "[\r\n]" " " ${_include_DIR} "${${_include_DIR}}")
49
50
51       exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=libdir
52         OUTPUT_VARIABLE ${_link_DIR} )
53       string(REGEX REPLACE "[\r\n]" " " ${_link_DIR} "${${_link_DIR}}")
54
55       exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --libs
56         OUTPUT_VARIABLE ${_link_FLAGS} )
57       string(REGEX REPLACE "[\r\n]" " " ${_link_FLAGS} "${${_link_FLAGS}}")
58
59       exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --cflags
60         OUTPUT_VARIABLE ${_cflags} )
61       string(REGEX REPLACE "[\r\n]" " " ${_cflags} "${${_cflags}}")
62
63     else()
64
65       message(STATUS "PKGCONFIG() indicates that ${_package} is not installed (install the package which contains ${_package}.pc if you want to support this feature)")
66
67     endif()
68
69   # if pkg-config has NOT been found, INFORM the user
70   else()
71
72     message(STATUS "WARNING: PKGCONFIG() indicates that the tool pkg-config has not been found on your system. You should install it.")
73
74   endif()
75
76 endmacro()
77
78 mark_as_advanced(PKGCONFIG_EXECUTABLE)