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