glog.cmake 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. # ---[ glog
  2. # We will try to use the config mode first, and then manual find.
  3. find_package(glog CONFIG QUIET)
  4. if(NOT TARGET glog::glog)
  5. find_package(glog MODULE QUIET)
  6. endif()
  7. if(TARGET glog::glog)
  8. message(STATUS "Caffe2: Found glog with new-style glog target.")
  9. elseif(GLOG_FOUND)
  10. message(
  11. STATUS
  12. "Caffe2: Found glog with old-style glog starget. Glog never shipped "
  13. "old style glog targets, so somewhere in your cmake path there might "
  14. "be a custom Findglog.cmake file that got triggered. We will make a "
  15. "best effort to create the new style glog target for you.")
  16. add_library(glog::glog UNKNOWN IMPORTED)
  17. set_property(
  18. TARGET glog::glog PROPERTY IMPORTED_LOCATION ${GLOG_LIBRARY})
  19. set_property(
  20. TARGET glog::glog PROPERTY INTERFACE_INCLUDE_DIRECTORIES
  21. ${GLOG_INCLUDE_DIR})
  22. else()
  23. message(STATUS "Caffe2: Cannot find glog automatically. Using legacy find.")
  24. # - Try to find Glog
  25. #
  26. # The following variables are optionally searched for defaults
  27. # GLOG_ROOT_DIR: Base directory where all GLOG components are found
  28. #
  29. # The following are set after configuration is done:
  30. # GLOG_FOUND
  31. # GLOG_INCLUDE_DIRS
  32. # GLOG_LIBRARIES
  33. # GLOG_LIBRARYRARY_DIRS
  34. include(FindPackageHandleStandardArgs)
  35. set(GLOG_ROOT_DIR "" CACHE PATH "Folder contains Google glog")
  36. if(NOT WIN32)
  37. find_path(GLOG_INCLUDE_DIR glog/logging.h
  38. PATHS ${GLOG_ROOT_DIR})
  39. endif()
  40. find_library(GLOG_LIBRARY glog
  41. PATHS ${GLOG_ROOT_DIR}
  42. PATH_SUFFIXES lib lib64)
  43. find_package_handle_standard_args(glog DEFAULT_MSG GLOG_INCLUDE_DIR GLOG_LIBRARY)
  44. if(GLOG_FOUND)
  45. message(STATUS
  46. "Caffe2: Found glog (include: ${GLOG_INCLUDE_DIR}, "
  47. "library: ${GLOG_LIBRARY})")
  48. add_library(glog::glog UNKNOWN IMPORTED)
  49. set_property(
  50. TARGET glog::glog PROPERTY IMPORTED_LOCATION ${GLOG_LIBRARY})
  51. set_property(
  52. TARGET glog::glog PROPERTY INTERFACE_INCLUDE_DIRECTORIES
  53. ${GLOG_INCLUDE_DIR})
  54. endif()
  55. endif()
  56. # After above, we should have the glog::glog target now.
  57. if(NOT TARGET glog::glog)
  58. message(WARNING
  59. "Caffe2: glog cannot be found. Depending on whether you are building "
  60. "Caffe2 or a Caffe2 dependent library, the next warning / error will "
  61. "give you more info.")
  62. endif()