FindLibpci.cmake 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. #[=======================================================================[.rst
  2. FindLibpci
  3. ----------
  4. FindModule for Libpci and associated libraries
  5. .. versionchanged:: 3.0
  6. Updated FindModule to CMake standards
  7. Imported Targets
  8. ^^^^^^^^^^^^^^^^
  9. .. versionadded:: 2.0
  10. This module defines the :prop_tgt:`IMPORTED` target ``Libpci::pci``.
  11. Result Variables
  12. ^^^^^^^^^^^^^^^^
  13. This module sets the following variables:
  14. ``Libpci_FOUND``
  15. True, if all required components and the core library were found.
  16. ``Libpci_VERSION``
  17. Detected version of found Libpci libraries.
  18. Cache variables
  19. ^^^^^^^^^^^^^^^
  20. The following cache variables may also be set:
  21. ``Libpci_LIBRARY``
  22. Path to the library component of Libpci.
  23. ``Libpci_INCLUDE_DIR``
  24. Directory containing ``Libpci.h``.
  25. #]=======================================================================]
  26. include(FindPackageHandleStandardArgs)
  27. find_package(PkgConfig QUIET)
  28. if(PKG_CONFIG_FOUND)
  29. pkg_search_module(PC_Libpci QUIET libpci)
  30. endif()
  31. find_path(
  32. Libpci_INCLUDE_DIR
  33. NAMES pci.h
  34. HINTS ${PC_Libpci_INCLUDE_DIRS}
  35. PATHS /usr/include/ /usr/local/include
  36. PATH_SUFFIXES pci
  37. DOC "Libpci include directory"
  38. )
  39. find_library(
  40. Libpci_LIBRARY
  41. NAMES libpci pci
  42. HINTS ${PC_Libpci_LIBRARY_DIRS}
  43. PATHS /usr/lib /usr/local/lib
  44. DOC "Libpci location"
  45. )
  46. if(PC_Libpci_VERSION VERSION_GREATER 0)
  47. set(Libpci_VERSION ${PC_Libpci_VERSION})
  48. elseif(EXISTS "${Libpci_INCLUDE_DIR}/config.h")
  49. file(STRINGS "${Libpci_INCLUDE_DIR}/config.h" _VERSION_STRING REGEX "^.*PCILIB_VERSION[ \t]+\"[0-9\\.]+\"[ \t]*$")
  50. string(REGEX REPLACE ".*PCILIB_VERSION[ \t]+\"([0-9\\.]+)\".*" "\\1" Libpci_VERSION "${_VERSION_STRING}")
  51. else()
  52. if(NOT Libpci_FIND_QUIETLY)
  53. message(AUTHOR_WARNING "Failed to find Libpci version.")
  54. endif()
  55. set(Libpci_VERSION 0.0.0)
  56. endif()
  57. find_package_handle_standard_args(
  58. Libpci
  59. REQUIRED_VARS Libpci_LIBRARY Libpci_INCLUDE_DIR
  60. VERSION_VAR Libpci_VERSION
  61. REASON_FAILURE_MESSAGE "Ensure that libpci is installed on the system."
  62. )
  63. mark_as_advanced(Libpci_INCLUDE_DIR Libpci_LIBRARY)
  64. if(Libpci_FOUND)
  65. if(NOT TARGET Libpci::pci)
  66. if(IS_ABSOLUTE "${Libpci_LIBRARY}")
  67. add_library(Libpci::pci UNKNOWN IMPORTED)
  68. set_property(TARGET Libpci::pci PROPERTY IMPORTED_LOCATION "${Libpci_LIBRARY}")
  69. else()
  70. add_library(Libpci::pci INTERFACE IMPORTED)
  71. set_property(TARGET Libpci::pci PROPERTY IMPORTED_LIBNAME "${Libpci_LIBRARY}")
  72. endif()
  73. set_target_properties(
  74. Libpci::pci
  75. PROPERTIES
  76. INTERFACE_COMPILE_OPTIONS "${PC_Libpci_CFLAFGS_OTHER}"
  77. INTERFACE_INCLUDE_DIRECTORIES "${Libpci_INCLUDE_DIR}"
  78. VERSION ${Libpci_VERSION}
  79. )
  80. endif()
  81. endif()
  82. include(FeatureSummary)
  83. set_package_properties(
  84. Libpci
  85. PROPERTIES
  86. URL "https://mj.ucw.cz/sw/pciutils"
  87. DESCRIPTION "Offers access to the PCI configuration space on a variety of operating systems."
  88. )