message(FATAL_ERROR "Test should be enabled to measure test coverage")
endif(${ENABLE_COVERAGE} AND NOT ${ENABLE_TEST})
-find_package(Protobuf)
-
-if(NOT DEFINED ENABLE_CAFFE_SUPPORT)
- set(ENABLE_CAFFE_SUPPORT ${PROTOBUF_FOUND})
-endif(NOT DEFINED ENABLE_CAFFE_SUPPORT)
-
-if(${ENABLE_CAFFE_SUPPORT} AND NOT ${PROTOBUF_FOUND})
- message(FATAL_ERROR "Protocol buffer is required to enable Caffe frontend")
-endif(${ENABLE_CAFFE_SUPPORT} AND NOT ${PROTOBUF_FOUND})
-
option(ENABLE_EXAMPLE_BUILD "Build examples" ON)
option(ENABLE_CONTRIB_BUILD "Build incubating projects under contrib/" ON)
--- /dev/null
+function(_Protobuf_import)
+ # Let's use find_package here not to export unnecessary definitions
+ find_package(Protobuf)
+
+ 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_import)
+
+# TODO Allow users to download and build protobuf 3.X
+_Protobuf_import()
+
+if(Protobuf_FOUND)
+ function(Protobuf_Generate PREFIX OUTPUT_DIR PROTO_DIR)
+ get_filename_component(abs_output_dir ${OUTPUT_DIR} ABSOLUTE)
+ get_filename_component(abs_proto_dir ${PROTO_DIR} ABSOLUTE)
+
+ foreach(proto ${ARGN})
+ get_filename_component(fil "${proto}" NAME)
+ get_filename_component(dir "${proto}" DIRECTORY)
+
+ get_filename_component(fil_we "${fil}" NAME_WE)
+
+ get_filename_component(abs_fil "${abs_proto_base}/${proto}" ABSOLUTE)
+ get_filename_component(abs_dir "${abs_fil}" DIRECTORY)
+
+ list(APPEND PROTO_FILES "${abs_proto_dir}/${proto}")
+ list(APPEND OUTPUT_FILES "${abs_output_dir}/${dir}/${fil_we}.pb.h")
+ list(APPEND OUTPUT_FILES "${abs_output_dir}/${dir}/${fil_we}.pb.cc")
+ endforeach()
+
+ add_custom_command(OUTPUT ${OUTPUT_FILES}
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${abs_output_dir}"
+ COMMAND "$<TARGET_FILE:protoc>" --cpp_out "${abs_output_dir}" -I "${abs_proto_dir}" ${PROTO_FILES})
+
+ set(${PREFIX}_SOURCES ${OUTPUT_FILES} PARENT_SCOPE)
+ set(${PREFIX}_INCLUDE_DIRS ${abs_output_dir} PARENT_SCOPE)
+ endfunction(Protobuf_Generate)
+endif(Protobuf_FOUND)
-protobuf_generate_cpp(PROTO_SRC PROTO_HDR res/caffe.proto)
+##
+## Check Prerequisites
+##
+nncc_find_package(Protobuf QUIET)
-add_nncc_library(nncc_frontend_caffe_core ${PROTO_SRC})
-target_include_directories(nncc_frontend_caffe_core PUBLIC ${PROTOBUF_INCLUDE_DIRS})
-target_include_directories(nncc_frontend_caffe_core PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
-target_link_libraries(nncc_frontend_caffe_core ${PROTOBUF_LIBRARIES})
+option(ENABLE_CAFFE_SUPPORT "Build Caffe frontend" ${Protobuf_FOUND})
+
+if(NOT ENABLE_CAFFE_SUPPORT)
+ return()
+endif(NOT ENABLE_CAFFE_SUPPORT)
+
+##
+## Build
+##
+nncc_find_package(Protobuf REQUIRED)
+
+set(GENERATED_OUTPUT_DIR "${CMAKE_CURRENT_BINARY_DIR}/generated")
+
+Protobuf_Generate(CAFFE_PROTO "${GENERATED_OUTPUT_DIR}"
+ "${CMAKE_CURRENT_SOURCE_DIR}/res"
+ "caffe.proto")
+
+add_nncc_library(nncc_frontend_caffe_core ${CAFFE_PROTO_SOURCES})
+target_include_directories(nncc_frontend_caffe_core PUBLIC ${CAFFE_PROTO_INCLUDE_DIRS})
+target_link_libraries(nncc_frontend_caffe_core libprotobuf)
add_nncc_example_executable(caffe_core_io_example examples/caffe_core_io.cpp)
nncc_example_link_libraries(caffe_core_io_example nncc_frontend_caffe_core)