UsePkgConfig.cmake 2.99 KB
Newer Older
1 2 3 4 5 6 7
#.rst:
# UsePkgConfig
# ------------
#
# Obsolete pkg-config module for CMake, use FindPkgConfig instead.
#
#
8
#
9
# This module defines the following macro:
10 11 12
#
# PKGCONFIG(package includedir libdir linkflags cflags)
#
13 14 15 16 17
# Calling PKGCONFIG will fill the desired information into the 4 given
# arguments, e.g.  PKGCONFIG(libart-2.0 LIBART_INCLUDE_DIR
# LIBART_LINK_DIR LIBART_LINK_FLAGS LIBART_CFLAGS) if pkg-config was NOT
# found or the specified software package doesn't exist, the variable
# will be empty when the function returns, otherwise they will contain
18
# the respective information
19

20 21 22 23 24 25 26 27 28 29
#=============================================================================
# Copyright 2006-2009 Kitware, Inc.
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
30
# (To distribute this file outside of CMake, substitute the full
31
#  License text for the above reference.)
32

33
find_program(PKGCONFIG_EXECUTABLE NAMES pkg-config )
34

35 36
macro(PKGCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
  message(STATUS
37
    "WARNING: you are using the obsolete 'PKGCONFIG' macro, use FindPkgConfig")
38
# reset the variables at the beginning
39 40 41 42
  set(${_include_DIR})
  set(${_link_DIR})
  set(${_link_FLAGS})
  set(${_cflags})
43 44

  # if pkg-config has been found
45
  if(PKGCONFIG_EXECUTABLE)
46

47
    exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --exists RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull )
48 49

    # and if the package of interest also exists for pkg-config, then get the information
50
    if(NOT _return_VALUE)
51

52
      exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=includedir
53
        OUTPUT_VARIABLE ${_include_DIR} )
54
      string(REGEX REPLACE "[\r\n]" " " ${_include_DIR} "${${_include_DIR}}")
55

56

57
      exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=libdir
58
        OUTPUT_VARIABLE ${_link_DIR} )
59
      string(REGEX REPLACE "[\r\n]" " " ${_link_DIR} "${${_link_DIR}}")
60

61
      exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --libs
62
        OUTPUT_VARIABLE ${_link_FLAGS} )
63
      string(REGEX REPLACE "[\r\n]" " " ${_link_FLAGS} "${${_link_FLAGS}}")
64

65
      exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --cflags
66
        OUTPUT_VARIABLE ${_cflags} )
67
      string(REGEX REPLACE "[\r\n]" " " ${_cflags} "${${_cflags}}")
68

69
    else()
70

71
      message(STATUS "PKGCONFIG() indicates that ${_package} is not installed (install the package which contains ${_package}.pc if you want to support this feature)")
72

73
    endif()
74

75
  # if pkg-config has NOT been found, INFORM the user
76
  else()
77

78
    message(STATUS "WARNING: PKGCONFIG() indicates that the tool pkg-config has not been found on your system. You should install it.")
79

80
  endif()
81

82
endmacro()
83

84
mark_as_advanced(PKGCONFIG_EXECUTABLE)