UsePkgConfig.cmake 2.7 KB

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