UsePkgConfig.cmake 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  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. # Copyright 2006-2009 Kitware, Inc.
  15. #
  16. # Distributed under the OSI-approved BSD License (the "License");
  17. # see accompanying file Copyright.txt for details.
  18. #
  19. # This software is distributed WITHOUT ANY WARRANTY; without even the
  20. # implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  21. # See the License for more information.
  22. #=============================================================================
  23. # (To distribute this file outside of CMake, substitute the full
  24. # License text for the above reference.)
  25. find_program(PKGCONFIG_EXECUTABLE NAMES pkg-config )
  26. macro(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. # if pkg-config has been found
  35. if(PKGCONFIG_EXECUTABLE)
  36. exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --exists RETURN_VALUE _return_VALUE OUTPUT_VARIABLE _pkgconfigDevNull )
  37. # and if the package of interest also exists for pkg-config, then get the information
  38. if(NOT _return_VALUE)
  39. exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=includedir
  40. OUTPUT_VARIABLE ${_include_DIR} )
  41. string(REGEX REPLACE "[\r\n]" " " ${_include_DIR} "${${_include_DIR}}")
  42. exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --variable=libdir
  43. OUTPUT_VARIABLE ${_link_DIR} )
  44. string(REGEX REPLACE "[\r\n]" " " ${_link_DIR} "${${_link_DIR}}")
  45. exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --libs
  46. OUTPUT_VARIABLE ${_link_FLAGS} )
  47. string(REGEX REPLACE "[\r\n]" " " ${_link_FLAGS} "${${_link_FLAGS}}")
  48. exec_program(${PKGCONFIG_EXECUTABLE} ARGS ${_package} --cflags
  49. OUTPUT_VARIABLE ${_cflags} )
  50. string(REGEX REPLACE "[\r\n]" " " ${_cflags} "${${_cflags}}")
  51. else()
  52. message(STATUS "PKGCONFIG() indicates that ${_package} is not installed (install the package which contains ${_package}.pc if you want to support this feature)")
  53. endif()
  54. # if pkg-config has NOT been found, INFORM the user
  55. else()
  56. message(STATUS "WARNING: PKGCONFIG() indicates that the tool pkg-config has not been found on your system. You should install it.")
  57. endif()
  58. endmacro()
  59. mark_as_advanced(PKGCONFIG_EXECUTABLE)