Caffe2Config.cmake 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. # - Config file for the Caffe2 package
  2. # It defines the following variable(s)
  3. # CAFFE2_INCLUDE_DIRS - include directories for FooBar
  4. # as well as Caffe2 targets for other cmake libraries to use.
  5. # library version information
  6. set(CAFFE2_VERSION_MAJOR 2)
  7. set(CAFFE2_VERSION_MINOR 0)
  8. set(CAFFE2_VERSION_PATCH 0)
  9. set(CAFFE2_VERSION "2.0.0")
  10. # Utils functions.
  11. include("${CMAKE_CURRENT_LIST_DIR}/public/utils.cmake")
  12. # Depending on whether Caffe2 uses gflags during compile time or
  13. # not, invoke gflags.
  14. if(OFF)
  15. include("${CMAKE_CURRENT_LIST_DIR}/public/gflags.cmake")
  16. if(NOT TARGET gflags)
  17. message(FATAL_ERROR
  18. "Your installed Caffe2 version uses gflags but the gflags library "
  19. "cannot be found. Did you accidentally remove it, or have you set "
  20. "the right CMAKE_PREFIX_PATH and/or GFLAGS_ROOT_DIR? If you do not "
  21. "have gflags, you will need to install gflags and set the library "
  22. "path accordingly.")
  23. endif()
  24. endif()
  25. # Depending on whether Caffe2 uses glog during compile time or
  26. # not, invoke glog.
  27. if(OFF)
  28. include("${CMAKE_CURRENT_LIST_DIR}/public/glog.cmake")
  29. if(NOT TARGET glog::glog)
  30. message(FATAL_ERROR
  31. "Your installed Caffe2 version uses glog but the glog library "
  32. "cannot be found. Did you accidentally remove it, or have you set "
  33. "the right CMAKE_PREFIX_PATH and/or GFLAGS_ROOT_DIR? If you do not "
  34. "have glog, you will need to install glog and set the library "
  35. "path accordingly.")
  36. endif()
  37. endif()
  38. # Protobuf
  39. if(ON)
  40. if(NOT TARGET protobuf::libprotobuf)
  41. # Define protobuf::libprotobuf as a dummy target to resolve references to
  42. # protobuf::libprotobuf in Caffe2Targets.cmake.
  43. add_library(dummy INTERFACE)
  44. add_library(protobuf::libprotobuf ALIAS dummy)
  45. endif()
  46. else()
  47. include("${CMAKE_CURRENT_LIST_DIR}/public/protobuf.cmake")
  48. if(NOT TARGET protobuf::libprotobuf)
  49. message(FATAL_ERROR
  50. "Your installed Caffe2 version uses protobuf but the protobuf library "
  51. "cannot be found. Did you accidentally remove it, or have you set "
  52. "the right CMAKE_PREFIX_PATH? If you do not have protobuf, you will "
  53. "need to install protobuf and set the library path accordingly.")
  54. endif()
  55. message(STATUS "Caffe2: Protobuf version " ${Protobuf_VERSION})
  56. # If during build time we know the protobuf version, we will also do a sanity
  57. # check to ensure that the protobuf library that Caffe2 found is consistent
  58. # with the compiled version.
  59. if(FALSE)
  60. if(NOT (${Protobuf_VERSION} VERSION_EQUAL Protobuf_VERSION_NOTFOUND))
  61. message(FATAL_ERROR
  62. "Your installed Caffe2 is built with protobuf "
  63. "Protobuf_VERSION_NOTFOUND"
  64. ", while your current cmake setting discovers protobuf version "
  65. ${Protobuf_VERSION}
  66. ". Please specify a protobuf version that is the same as the built "
  67. "version.")
  68. endif()
  69. endif()
  70. endif()
  71. if (OFF)
  72. include("${CMAKE_CURRENT_LIST_DIR}/public/LoadHIP.cmake")
  73. endif()
  74. if(ON)
  75. # The file public/cuda.cmake exclusively uses CAFFE2_USE_*.
  76. # If Caffe2 was compiled with the libraries below, they must
  77. # be found again when including the Caffe2 target.
  78. set(CAFFE2_USE_CUDA ON)
  79. set(CAFFE2_USE_TENSORRT OFF)
  80. include("${CMAKE_CURRENT_LIST_DIR}/public/cuda.cmake")
  81. if(ON AND NOT CAFFE2_USE_CUDA)
  82. message(FATAL_ERROR
  83. "Your installed Caffe2 version uses CUDA but I cannot find the CUDA "
  84. "libraries. Please set the proper CUDA prefixes and / or install "
  85. "CUDA.")
  86. endif()
  87. if(OFF AND NOT CAFFE2_USE_TENSORRT)
  88. message(FATAL_ERROR
  89. "Your installed Caffe2 version uses TensorRT but I cannot find the TensorRT "
  90. "libraries. Please set the proper TensorRT prefixes and / or install "
  91. "TensorRT.")
  92. endif()
  93. endif()
  94. include("${CMAKE_CURRENT_LIST_DIR}/public/mkl.cmake")
  95. if(OFF)
  96. include("${CMAKE_CURRENT_LIST_DIR}/public/mkldnn.cmake")
  97. endif()
  98. # import targets
  99. include ("${CMAKE_CURRENT_LIST_DIR}/Caffe2Targets.cmake")
  100. # Interface libraries, that allows one to build proper link flags.
  101. # We will also define a helper variable, Caffe2_MAIN_LIBS, that resolves to
  102. # the main caffe2 libraries in cases of cuda presence / absence.
  103. set(Caffe2_MAIN_LIBS torch_library)
  104. # include directory.
  105. #
  106. # Newer versions of CMake set the INTERFACE_INCLUDE_DIRECTORIES property
  107. # of the imported targets. It is hence not necessary to add this path
  108. # manually to the include search path for targets which link to gflags.
  109. # The following lines are here for backward compatibility, in case one
  110. # would like to use the old-style include path.
  111. get_filename_component(
  112. CMAKE_CURRENT_LIST_DIR "${CMAKE_CURRENT_LIST_FILE}" PATH)
  113. # Note: the current list dir is _INSTALL_PREFIX/share/cmake/Gloo.
  114. get_filename_component(
  115. _INSTALL_PREFIX "${CMAKE_CURRENT_LIST_DIR}/../../../" ABSOLUTE)
  116. set(CAFFE2_INCLUDE_DIRS "${_INSTALL_PREFIX}/include")