Caffe2Config.cmake 5.2 KB

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