gflags.cmake 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. # ---[ gflags
  2. # We will try to use the config mode first, and then manual find.
  3. find_package(gflags CONFIG QUIET)
  4. if(NOT TARGET gflags)
  5. find_package(gflags MODULE QUIET)
  6. endif()
  7. if(TARGET gflags)
  8. message(STATUS "Caffe2: Found gflags with new-style gflags target.")
  9. elseif(GFLAGS_FOUND)
  10. message(STATUS "Caffe2: Found gflags with old-style gflag starget.")
  11. add_library(gflags UNKNOWN IMPORTED)
  12. set_property(
  13. TARGET gflags PROPERTY IMPORTED_LOCATION ${GFLAGS_LIBRARY})
  14. set_property(
  15. TARGET gflags PROPERTY INTERFACE_INCLUDE_DIRECTORIES
  16. ${GFLAGS_INCLUDE_DIR})
  17. else()
  18. message(STATUS
  19. "Caffe2: Cannot find gflags automatically. Using legacy find.")
  20. # - Try to find GFLAGS in the legacy way.
  21. #
  22. # The following variables are optionally searched for defaults
  23. # GFLAGS_ROOT_DIR: Base directory where all GFLAGS components are found
  24. #
  25. # The following are set after configuration is done:
  26. # GFLAGS_FOUND
  27. # GFLAGS_INCLUDE_DIRS
  28. # GFLAGS_LIBRARIES
  29. # GFLAGS_LIBRARYRARY_DIRS
  30. include(FindPackageHandleStandardArgs)
  31. set(GFLAGS_ROOT_DIR "" CACHE PATH "Folder contains Gflags")
  32. # We are testing only a couple of files in the include directories
  33. if(WIN32)
  34. find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h
  35. PATHS ${GFLAGS_ROOT_DIR}/src/windows)
  36. else()
  37. find_path(GFLAGS_INCLUDE_DIR gflags/gflags.h
  38. PATHS ${GFLAGS_ROOT_DIR})
  39. endif()
  40. if(WIN32)
  41. find_library(GFLAGS_LIBRARY_RELEASE
  42. NAMES libgflags
  43. PATHS ${GFLAGS_ROOT_DIR}
  44. PATH_SUFFIXES Release)
  45. find_library(GFLAGS_LIBRARY_DEBUG
  46. NAMES libgflags-debug
  47. PATHS ${GFLAGS_ROOT_DIR}
  48. PATH_SUFFIXES Debug)
  49. set(GFLAGS_LIBRARY optimized ${GFLAGS_LIBRARY_RELEASE} debug ${GFLAGS_LIBRARY_DEBUG})
  50. else()
  51. find_library(GFLAGS_LIBRARY gflags)
  52. endif()
  53. find_package_handle_standard_args(
  54. gflags DEFAULT_MSG GFLAGS_INCLUDE_DIR GFLAGS_LIBRARY)
  55. if(GFLAGS_FOUND)
  56. message(
  57. STATUS
  58. "Caffe2: Found gflags (include: ${GFLAGS_INCLUDE_DIR}, "
  59. "library: ${GFLAGS_LIBRARY})")
  60. add_library(gflags UNKNOWN IMPORTED)
  61. set_property(
  62. TARGET gflags PROPERTY IMPORTED_LOCATION ${GFLAGS_LIBRARY})
  63. set_property(
  64. TARGET gflags PROPERTY INTERFACE_INCLUDE_DIRECTORIES
  65. ${GFLAGS_INCLUDE_DIR})
  66. endif()
  67. endif()
  68. # After above, we should have the gflags target now.
  69. if(NOT TARGET gflags)
  70. message(WARNING
  71. "Caffe2: gflags cannot be found. Depending on whether you are building "
  72. "Caffe2 or a Caffe2 dependent library, the next warning / error will "
  73. "give you more info.")
  74. endif()