1*da0073e9SAndroid Build Coastguard Worker# ---[ Protobuf 2*da0073e9SAndroid Build Coastguard Worker 3*da0073e9SAndroid Build Coastguard Worker# We will try to use the config mode first, and then manual find. 4*da0073e9SAndroid Build Coastguard Workerfind_package(Protobuf CONFIG QUIET) 5*da0073e9SAndroid Build Coastguard Workerif(NOT Protobuf_FOUND) 6*da0073e9SAndroid Build Coastguard Worker find_package(Protobuf MODULE QUIET) 7*da0073e9SAndroid Build Coastguard Workerendif() 8*da0073e9SAndroid Build Coastguard Worker 9*da0073e9SAndroid Build Coastguard Workerif((TARGET protobuf::libprotobuf OR TARGET protobuf::libprotobuf-lite) AND TARGET protobuf::protoc) 10*da0073e9SAndroid Build Coastguard Worker # Hooray. This is the most ideal situation, meaning that you either have a 11*da0073e9SAndroid Build Coastguard Worker # Protobuf config file installed (like on Windows), or you are using a 12*da0073e9SAndroid Build Coastguard Worker # modern CMake that ships with a FindProtobuf.cmake file that produces 13*da0073e9SAndroid Build Coastguard Worker # modern targets. 14*da0073e9SAndroid Build Coastguard Worker message(STATUS "Caffe2: Found protobuf with new-style protobuf targets.") 15*da0073e9SAndroid Build Coastguard Workerelseif(Protobuf_FOUND OR PROTOBUF_FOUND) 16*da0073e9SAndroid Build Coastguard Worker # If the modern targets are not present, we will generate them for you for 17*da0073e9SAndroid Build Coastguard Worker # backward compatibility. This is backported from CMake's new FindProtobuf.cmake 18*da0073e9SAndroid Build Coastguard Worker # content. 19*da0073e9SAndroid Build Coastguard Worker if((NOT PROTOBUF_LIBRARY) AND (NOT PROTOBUF_LITE_LIBRARY)) 20*da0073e9SAndroid Build Coastguard Worker message(FATAL_ERROR 21*da0073e9SAndroid Build Coastguard Worker "Caffe2: Found protobuf with old style targets, but could not find targets." 22*da0073e9SAndroid Build Coastguard Worker " PROTOBUF_LIBRARY: " ${PROTOBUF_LIBRARY} 23*da0073e9SAndroid Build Coastguard Worker " PROTOBUF_LITE_LIBRARY: " ${PROTOBUF_LITE_LIBRARY} 24*da0073e9SAndroid Build Coastguard Worker " Protobuf_LIBRARY: " ${Protobuf_LIBRARY} 25*da0073e9SAndroid Build Coastguard Worker " Protobuf_LITE_LIBRARY: " ${Protobuf_LITE_LIBRARY}) 26*da0073e9SAndroid Build Coastguard Worker endif() 27*da0073e9SAndroid Build Coastguard Worker message(STATUS "Caffe2: Found protobuf with old-style protobuf targets.") 28*da0073e9SAndroid Build Coastguard Worker 29*da0073e9SAndroid Build Coastguard Worker if(PROTOBUF_LIBRARY) 30*da0073e9SAndroid Build Coastguard Worker if(NOT TARGET protobuf::libprotobuf) 31*da0073e9SAndroid Build Coastguard Worker add_library(protobuf::libprotobuf UNKNOWN IMPORTED) 32*da0073e9SAndroid Build Coastguard Worker set_target_properties(protobuf::libprotobuf PROPERTIES 33*da0073e9SAndroid Build Coastguard Worker INTERFACE_INCLUDE_DIRECTORIES "${PROTOBUF_INCLUDE_DIRS}") 34*da0073e9SAndroid Build Coastguard Worker endif() 35*da0073e9SAndroid Build Coastguard Worker if(EXISTS "${PROTOBUF_LIBRARY}") 36*da0073e9SAndroid Build Coastguard Worker set_target_properties(protobuf::libprotobuf PROPERTIES 37*da0073e9SAndroid Build Coastguard Worker IMPORTED_LOCATION "${PROTOBUF_LIBRARY}") 38*da0073e9SAndroid Build Coastguard Worker endif() 39*da0073e9SAndroid Build Coastguard Worker if(EXISTS "${PROTOBUF_LIBRARY_RELEASE}") 40*da0073e9SAndroid Build Coastguard Worker set_property(TARGET protobuf::libprotobuf APPEND PROPERTY 41*da0073e9SAndroid Build Coastguard Worker IMPORTED_CONFIGURATIONS RELEASE) 42*da0073e9SAndroid Build Coastguard Worker set_target_properties(protobuf::libprotobuf PROPERTIES 43*da0073e9SAndroid Build Coastguard Worker IMPORTED_LOCATION_RELEASE "${PROTOBUF_LIBRARY_RELEASE}") 44*da0073e9SAndroid Build Coastguard Worker endif() 45*da0073e9SAndroid Build Coastguard Worker if(EXISTS "${PROTOBUF_LIBRARY_DEBUG}") 46*da0073e9SAndroid Build Coastguard Worker set_property(TARGET protobuf::libprotobuf APPEND PROPERTY 47*da0073e9SAndroid Build Coastguard Worker IMPORTED_CONFIGURATIONS DEBUG) 48*da0073e9SAndroid Build Coastguard Worker set_target_properties(protobuf::libprotobuf PROPERTIES 49*da0073e9SAndroid Build Coastguard Worker IMPORTED_LOCATION_DEBUG "${PROTOBUF_LIBRARY_DEBUG}") 50*da0073e9SAndroid Build Coastguard Worker endif() 51*da0073e9SAndroid Build Coastguard Worker endif() 52*da0073e9SAndroid Build Coastguard Worker 53*da0073e9SAndroid Build Coastguard Worker if(PROTOBUF_LITE_LIBRARY) 54*da0073e9SAndroid Build Coastguard Worker if(NOT TARGET protobuf::libprotobuf-lite) 55*da0073e9SAndroid Build Coastguard Worker add_library(protobuf::libprotobuf-lite UNKNOWN IMPORTED) 56*da0073e9SAndroid Build Coastguard Worker set_target_properties(protobuf::libprotobuf-lite PROPERTIES 57*da0073e9SAndroid Build Coastguard Worker INTERFACE_INCLUDE_DIRECTORIES "${PROTOBUF_INCLUDE_DIRS}") 58*da0073e9SAndroid Build Coastguard Worker endif() 59*da0073e9SAndroid Build Coastguard Worker if(EXISTS "${PROTOBUF_LITE_LIBRARY}") 60*da0073e9SAndroid Build Coastguard Worker set_target_properties(protobuf::libprotobuf-lite PROPERTIES 61*da0073e9SAndroid Build Coastguard Worker IMPORTED_LOCATION "${PROTOBUF_LITE_LIBRARY}") 62*da0073e9SAndroid Build Coastguard Worker endif() 63*da0073e9SAndroid Build Coastguard Worker if(EXISTS "${PROTOBUF_LITE_LIBRARY_RELEASE}") 64*da0073e9SAndroid Build Coastguard Worker set_property(TARGET protobuf::libprotobuf-lite APPEND PROPERTY 65*da0073e9SAndroid Build Coastguard Worker IMPORTED_CONFIGURATIONS RELEASE) 66*da0073e9SAndroid Build Coastguard Worker set_target_properties(protobuf::libprotobuf-lite PROPERTIES 67*da0073e9SAndroid Build Coastguard Worker IMPORTED_LOCATION_RELEASE "${PROTOBUF_LITE_LIBRARY_RELEASE}") 68*da0073e9SAndroid Build Coastguard Worker endif() 69*da0073e9SAndroid Build Coastguard Worker if(EXISTS "${PROTOBUF_LITE_LIBRARY_DEBUG}") 70*da0073e9SAndroid Build Coastguard Worker set_property(TARGET protobuf::libprotobuf-lite APPEND PROPERTY 71*da0073e9SAndroid Build Coastguard Worker IMPORTED_CONFIGURATIONS DEBUG) 72*da0073e9SAndroid Build Coastguard Worker set_target_properties(protobuf::libprotobuf-lite PROPERTIES 73*da0073e9SAndroid Build Coastguard Worker IMPORTED_LOCATION_DEBUG "${PROTOBUF_LITE_LIBRARY_DEBUG}") 74*da0073e9SAndroid Build Coastguard Worker endif() 75*da0073e9SAndroid Build Coastguard Worker endif() 76*da0073e9SAndroid Build Coastguard Worker 77*da0073e9SAndroid Build Coastguard Worker if(PROTOBUF_PROTOC_EXECUTABLE) 78*da0073e9SAndroid Build Coastguard Worker if(NOT TARGET protobuf::protoc) 79*da0073e9SAndroid Build Coastguard Worker add_executable(protobuf::protoc IMPORTED) 80*da0073e9SAndroid Build Coastguard Worker endif() 81*da0073e9SAndroid Build Coastguard Worker set_property(TARGET protobuf::protoc PROPERTY 82*da0073e9SAndroid Build Coastguard Worker IMPORTED_LOCATION ${PROTOBUF_PROTOC_EXECUTABLE}) 83*da0073e9SAndroid Build Coastguard Worker endif() 84*da0073e9SAndroid Build Coastguard Workerendif() 85*da0073e9SAndroid Build Coastguard Worker 86*da0073e9SAndroid Build Coastguard Worker# After above, we should have the protobuf related target now. 87*da0073e9SAndroid Build Coastguard Workerif((NOT TARGET protobuf::libprotobuf) AND (NOT TARGET protobuf::libprotobuf-lite)) 88*da0073e9SAndroid Build Coastguard Worker message(WARNING 89*da0073e9SAndroid Build Coastguard Worker "Protobuf cannot be found. Depending on whether you are building Caffe2 " 90*da0073e9SAndroid Build Coastguard Worker "or a Caffe2 dependent library, the next warning / error will give you " 91*da0073e9SAndroid Build Coastguard Worker "more info.") 92*da0073e9SAndroid Build Coastguard Workerendif() 93