UsePkgConfig.cmake 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. #.rst:
  2. # UsePkgConfig
  3. # ------------
  4. #
  5. # Obsolete pkg-config module for CMake, use FindPkgConfig instead.
  6. #
  7. #
  8. #
  9. # This module defines the following macro:
  10. #
  11. # PKGCONFIG(package includedir libdir linkflags cflags)
  12. #
  13. # Calling PKGCONFIG will fill the desired information into the 4 given
  14. # arguments, e.g. PKGCONFIG(libart-2.0 LIBART_INCLUDE_DIR
  15. # LIBART_LINK_DIR LIBART_LINK_FLAGS LIBART_CFLAGS) if pkg-config was NOT
  16. # found or the specified software package doesn't exist, the variable
  17. # will be empty when the function returns, otherwise they will contain
  18. # the respective information
  19. #=============================================================================
  20. # Copyright 2006-2009 Kitware, Inc.
  21. #
  22. # Distributed under the OSI-approved BSD License (the "License");
  23. # see accompanying file Copyright.txt for details.
  24. #
  25. # This software is distributed WITHOUT ANY WARRANTY; without even the
  26. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  27. # See the License for more information.
  28. #=============================================================================
  29. # (To distribute this file outside of CMake, substitute the full
  30. # License text for the above reference.)
  31. find_program(PKGCONFIG_EXECUTABLE NAMES pkg-config )
  32. macro(PKGCONFIG _package _include_DIR _link_DIR _link_FLAGS _cflags)
  33. message(STATUS
  34. "WARNING: you are using the obsolete 'PKGCONFIG' macro, use FindPkgConfig")
  35. # reset the variables at the beginning
  36. set(${_include_DIR})
  37. set(${_link_DIR})
  38. set(${_link_FLAGS})
  39. set(${_cflags})
  40. # if pkg-config has been found
  41. if(PKGCONFIG_EXECUTABLE)
  42. exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --exists RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull )
  43. # and if the package of interest also exists for pkg-config, then get the information
  44. if(NOT _return_VALUE)
  45. exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=includedir
  46. OUTPUT_VARIABLE ${_include_DIR} )
  47. string(REGEX REPLACE "[\r\n]" " " ${_include_DIR} "${${_include_DIR}}")
  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. exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --libs
  52. OUTPUT_VARIABLE ${_link_FLAGS} )
  53. string(REGEX REPLACE "[\r\n]" " " ${_link_FLAGS} "${${_link_FLAGS}}")
  54. exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --cflags
  55. OUTPUT_VARIABLE ${_cflags} )
  56. string(REGEX REPLACE "[\r\n]" " " ${_cflags} "${${_cflags}}")
  57. else()
  58. message(STATUS "PKGCONFIG() indicates that ${_package} is not installed (install the package which contains ${_package}.pc if you want to support this feature)")
  59. endif()
  60. # if pkg-config has NOT been found, INFORM the user
  61. else()
  62. message(STATUS "WARNING: PKGCONFIG() indicates that the tool pkg-config has not been found on your system. You should install it.")
  63. endif()
  64. endmacro()
  65. mark_as_advanced(PKGCONFIG_EXECUTABLE)