### Configuration
###
option(DOWNLOAD_PROTOBUF "Download Protocol Buffer source" ON)
-option(BUILD_PROTOBUF "Locally build Protocol Buffer from the downloaded source" ON)
+option(BUILD_PROTOBUF "Locally build Protocol Buffer from the downloaded source" OFF)
option(DOWNLOAD_EIGEN "Download Eigen source" ON)
option(DOWNLOAD_FARMHASH "Download farmhash source" ON)
option(DOWNLOAD_GEMMLOWP "Download GEMM low precesion library source" ON)
+# TODO Use CONFIG version after bug fix
+function(_Protobuf_module_import)
+ # Let's use find_package here not to export unnecessary definitions
+ find_package(Protobuf MODULE QUIET)
+
+ if(NOT PROTOBUF_FOUND)
+ set(Protobuf_FOUND FALSE PARENT_SCOPE)
+ return()
+ endif(NOT PROTOBUF_FOUND)
+
+ if(NOT TARGET protoc)
+ add_executable(protoc IMPORTED)
+ set_target_properties(protoc PROPERTIES IMPORTED_LOCATION ${PROTOBUF_PROTOC_EXECUTABLE})
+ endif(NOT TARGET protoc)
+
+ if(NOT TARGET libprotobuf)
+ add_library(libprotobuf INTERFACE)
+ target_include_directories(libprotobuf INTERFACE ${PROTOBUF_INCLUDE_DIRS})
+ target_link_libraries(libprotobuf INTERFACE ${PROTOBUF_LIBRARIES})
+ endif(NOT TARGET libprotobuf)
+
+ set(Protobuf_FOUND TRUE PARENT_SCOPE)
+endfunction(_Protobuf_module_import)
+
function(_Protobuf_import)
# Let's use find_package here not to export unnecessary definitions
# NOTE Here we use "exact" match to avoid possible infinite loop
message(STATUS "Succeeded in building Protocol Buffer")
endfunction(_Protobuf_build)
+# TODO Use Protocol Buffer 3.6.1
_Protobuf_build()
-_Protobuf_import()
+#_Protobuf_import()
+_Protobuf_module_import()
if(Protobuf_FOUND)
function(Protobuf_Generate PREFIX OUTPUT_DIR PROTO_DIR)