Adding guards around adding protobuf targets (#1997)

* Adding guards around adding protobuf targets

* Moving include_dirs add into target creation
This commit is contained in:
Paul Jesse Hellemn
2018-02-21 18:48:30 -08:00
committed by GitHub
parent 3ee9b5edca
commit 090850e89b

View File

@ -6,7 +6,7 @@ if (NOT Protobuf_FOUND)
find_package(Protobuf MODULE QUIET)
endif()
if (TARGET protobuf::libprotobuf)
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
@ -18,31 +18,35 @@ elseif(Protobuf_FOUND OR PROTOBUF_FOUND)
# content.
message(STATUS "Caffe2: Found protobuf with old-style protobuf targets.")
if(PROTOBUF_LIBRARY)
add_library(protobuf::libprotobuf UNKNOWN IMPORTED)
set_target_properties(protobuf::libprotobuf PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}")
if (NOT TARGET protobuf::libprotobuf)
add_library(protobuf::libprotobuf UNKNOWN IMPORTED)
set_target_properties(protobuf::libprotobuf PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}")
endif()
if(EXISTS "${PROTOBUF_LIBRARY}")
set_target_properties(protobuf::libprotobuf PROPERTIES
IMPORTED_LOCATION "${PROTOBUF_LIBRARY}")
IMPORTED_LOCATION "${PROTOBUF_LIBRARY}")
endif()
if(EXISTS "${PROTOBUF_LIBRARY_RELEASE}")
set_property(TARGET protobuf::libprotobuf APPEND PROPERTY
IMPORTED_CONFIGURATIONS RELEASE)
IMPORTED_CONFIGURATIONS RELEASE)
set_target_properties(protobuf::libprotobuf PROPERTIES
IMPORTED_LOCATION_RELEASE "${PROTOBUF_LIBRARY_RELEASE}")
IMPORTED_LOCATION_RELEASE "${PROTOBUF_LIBRARY_RELEASE}")
endif()
if(EXISTS "${PROTOBUF_LIBRARY_DEBUG}")
set_property(TARGET protobuf::libprotobuf APPEND PROPERTY
IMPORTED_CONFIGURATIONS DEBUG)
IMPORTED_CONFIGURATIONS DEBUG)
set_target_properties(protobuf::libprotobuf PROPERTIES
IMPORTED_LOCATION_DEBUG "${PROTOBUF_LIBRARY_DEBUG}")
IMPORTED_LOCATION_DEBUG "${PROTOBUF_LIBRARY_DEBUG}")
endif()
endif()
if(PROTOBUF_LITE_LIBRARY)
add_library(protobuf::libprotobuf-lite UNKNOWN IMPORTED)
set_target_properties(protobuf::libprotobuf-lite PROPERTIES
INTERFACE_INCLUDE_DIRECTORIES "${Protobuf_INCLUDE_DIR}")
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_DIR}")
endif()
if(EXISTS "${PROTOBUF_LITE_LIBRARY}")
set_target_properties(protobuf::libprotobuf-lite PROPERTIES
IMPORTED_LOCATION "${PROTOBUF_LITE_LIBRARY}")
@ -62,7 +66,9 @@ elseif(Protobuf_FOUND OR PROTOBUF_FOUND)
endif()
if(PROTOBUF_PROTOC_EXECUTABLE)
add_executable(protobuf::protoc IMPORTED)
if (NOT TARGET protobuf::protoc)
add_executable(protobuf::protoc IMPORTED)
endif()
set_property(TARGET protobuf::protoc PROPERTY
IMPORTED_LOCATION ${PROTOBUF_PROTOC_EXECUTABLE})
endif()