CheckLib.cmake 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. find_package(PkgConfig)
  2. macro(_internal_message msg)
  3. if(NOT ${_is_quiet})
  4. message(STATUS "${msg}")
  5. endif()
  6. endmacro()
  7. macro(check_lib var pc lib)
  8. set(_is_required 0)
  9. set(_is_quiet 0)
  10. set(_arg_list ${ARGN})
  11. foreach(_arg ${ARGN})
  12. if(_arg STREQUAL "REQUIRED")
  13. list(REMOVE_ITEM _arg_list "REQUIRED")
  14. set(_is_required 1)
  15. endif()
  16. if(_arg STREQUAL "QUIET")
  17. list(REMOVE_ITEM _arg_list "QUIET")
  18. set(_is_quiet 1)
  19. endif()
  20. endforeach()
  21. if(PKG_CONFIG_FOUND AND NOT ${var}_FOUND)
  22. pkg_search_module(${var} QUIET ${pc})
  23. endif()
  24. if(${var}_FOUND)
  25. if(${var}_INCLUDE_DIRS)
  26. include_directories(${${var}_INCLUDE_DIRS})
  27. endif()
  28. # Make sure include directories for headers found using find_path below
  29. # are re-added when reconfiguring
  30. if(${var}_INCLUDE)
  31. include_directories(${${var}_INCLUDE})
  32. endif()
  33. _internal_message("${lib} found")
  34. else()
  35. find_library(${var} ${lib})
  36. if(_arg_list)
  37. find_path(${var}_INCLUDE ${_arg_list})
  38. else()
  39. set(${var}_INCLUDE FALSE)
  40. endif()
  41. if(${var} AND ${var}_INCLUDE)
  42. include_directories(${${var}_INCLUDE})
  43. _internal_message("${lib} found")
  44. set(${var}_FOUND 1 CACHE INTERNAL "")
  45. else()
  46. if(_is_required)
  47. message(FATAL_ERROR "${lib} is required but not found")
  48. else()
  49. _internal_message("${lib} not found")
  50. endif()
  51. endif()
  52. endif()
  53. endmacro()