UsePkgConfig.cmake 2.5 KB

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