File: protobuf.cmake

package info (click to toggle)
pytorch 1.13.1%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 139,252 kB
  • sloc: cpp: 1,100,274; python: 706,454; ansic: 83,052; asm: 7,618; java: 3,273; sh: 2,841; javascript: 612; makefile: 323; xml: 269; ruby: 185; yacc: 144; objc: 68; lex: 44
file content (92 lines) | stat: -rw-r--r-- 4,003 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# ---[ Protobuf

# We will try to use the config mode first, and then manual find.
find_package(Protobuf CONFIG QUIET)
if(NOT Protobuf_FOUND)
  find_package(Protobuf MODULE QUIET)
endif()

if((TARGET protobuf::libprotobuf OR TARGET protobuf::libprotobuf-lite) AND TARGET protobuf::protoc)
  # Hooray. This is the most ideal situation, meaning that you either have a
  # Protobuf config file installed (like on Windows), or you are using a
  # modern CMake that ships with a FindProtobuf.cmake file that produces
  # modern targets.
  message(STATUS "Caffe2: Found protobuf with new-style protobuf targets.")
elseif(Protobuf_FOUND OR PROTOBUF_FOUND)
  # If the modern targets are not present, we will generate them for you for
  # backward compatibility. This is backported from CMake's new FindProtobuf.cmake
  # content.
  if((NOT PROTOBUF_LIBRARY) AND (NOT PROTOBUF_LITE_LIBRARY))
    message(FATAL_ERROR
        "Caffe2: Found protobuf with old style targets, but could not find targets."
        " PROTOBUF_LIBRARY: " ${PROTOBUF_LIBRARY}
        " PROTOBUF_LITE_LIBRARY: " ${PROTOBUF_LITE_LIBRARY}
        " Protobuf_LIBRARY: " ${Protobuf_LIBRARY}
        " Protobuf_LITE_LIBRARY: " ${Protobuf_LITE_LIBRARY})
  endif()
  message(STATUS "Caffe2: Found protobuf with old-style protobuf targets.")

  if(PROTOBUF_LIBRARY)
    if(NOT TARGET protobuf::libprotobuf)
      add_library(protobuf::libprotobuf UNKNOWN IMPORTED)
      set_target_properties(protobuf::libprotobuf PROPERTIES
          INTERFACE_INCLUDE_DIRECTORIES "${PROTOBUF_INCLUDE_DIRS}")
    endif()
    if(EXISTS "${PROTOBUF_LIBRARY}")
      set_target_properties(protobuf::libprotobuf PROPERTIES
          IMPORTED_LOCATION "${PROTOBUF_LIBRARY}")
    endif()
    if(EXISTS "${PROTOBUF_LIBRARY_RELEASE}")
      set_property(TARGET protobuf::libprotobuf APPEND PROPERTY
          IMPORTED_CONFIGURATIONS RELEASE)
      set_target_properties(protobuf::libprotobuf PROPERTIES
          IMPORTED_LOCATION_RELEASE "${PROTOBUF_LIBRARY_RELEASE}")
    endif()
    if(EXISTS "${PROTOBUF_LIBRARY_DEBUG}")
      set_property(TARGET protobuf::libprotobuf APPEND PROPERTY
          IMPORTED_CONFIGURATIONS DEBUG)
      set_target_properties(protobuf::libprotobuf PROPERTIES
          IMPORTED_LOCATION_DEBUG "${PROTOBUF_LIBRARY_DEBUG}")
    endif()
  endif()

  if(PROTOBUF_LITE_LIBRARY)
    if(NOT TARGET protobuf::libprotobuf-lite)
      add_library(protobuf::libprotobuf-lite UNKNOWN IMPORTED)
      set_target_properties(protobuf::libprotobuf-lite PROPERTIES
          INTERFACE_INCLUDE_DIRECTORIES "${PROTOBUF_INCLUDE_DIRS}")
    endif()
    if(EXISTS "${PROTOBUF_LITE_LIBRARY}")
      set_target_properties(protobuf::libprotobuf-lite PROPERTIES
          IMPORTED_LOCATION "${PROTOBUF_LITE_LIBRARY}")
    endif()
    if(EXISTS "${PROTOBUF_LITE_LIBRARY_RELEASE}")
      set_property(TARGET protobuf::libprotobuf-lite APPEND PROPERTY
          IMPORTED_CONFIGURATIONS RELEASE)
      set_target_properties(protobuf::libprotobuf-lite PROPERTIES
          IMPORTED_LOCATION_RELEASE "${PROTOBUF_LITE_LIBRARY_RELEASE}")
    endif()
    if(EXISTS "${PROTOBUF_LITE_LIBRARY_DEBUG}")
      set_property(TARGET protobuf::libprotobuf-lite APPEND PROPERTY
          IMPORTED_CONFIGURATIONS DEBUG)
      set_target_properties(protobuf::libprotobuf-lite PROPERTIES
          IMPORTED_LOCATION_DEBUG "${PROTOBUF_LITE_LIBRARY_DEBUG}")
    endif()
  endif()

  if(PROTOBUF_PROTOC_EXECUTABLE)
    if(NOT TARGET protobuf::protoc)
      add_executable(protobuf::protoc IMPORTED)
    endif()
    set_property(TARGET protobuf::protoc PROPERTY
        IMPORTED_LOCATION ${PROTOBUF_PROTOC_EXECUTABLE})
  endif()
endif()

# After above, we should have the protobuf related target now.
if((NOT TARGET protobuf::libprotobuf) AND (NOT TARGET protobuf::libprotobuf-lite))
  message(WARNING
      "Protobuf cannot be found. Depending on whether you are building Caffe2 "
      "or a Caffe2 dependent library, the next warning / error will give you "
      "more info.")
endif()