Compiling entire project
Can run CIFAR10 Python example!
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 20112fb..eac8db6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -58,3 +58,11 @@
add_subdirectory(caffe2)
target_link_libraries(Caffe2_CPU)
target_compile_features(Caffe2_CPU PRIVATE cxx_range_for)
+
+# ---[ Copy all python files to build directory
+# ---[ Assemble list of python files to copy
+# Copy the files
+# file(COPY ${Caffe2_PYTHON_SRC} DESTINATION ${CMAKE_BINARY_DIR})
+install(DIRECTORY ${CMAKE_SOURCE_DIR} DESTINATION ${CMAKE_INSTALL_PREFIX}
+ FILES_MATCHING PATTERN "*.py")
+
diff --git a/caffe/proto/CMakeLists.txt b/caffe/proto/CMakeLists.txt
index 33d9657..ad7a563 100644
--- a/caffe/proto/CMakeLists.txt
+++ b/caffe/proto/CMakeLists.txt
@@ -1,8 +1,9 @@
-find_package(Protobuf REQUIRED)
+# find_package(Protobuf REQUIRED)
file(GLOB Caffe_PROTOBUF_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.proto")
-PROTOBUF_GENERATE_CPP(Caffe_PROTO_SRCS Caffe_PROTO_HEADERS ${Caffe_PROTOBUF_FILES})
+# PROTOBUF_GENERATE_CPP(Caffe_PROTO_SRCS Caffe_PROTO_HEADERS ${Caffe_PROTOBUF_FILES})
+caffe_protobuf_generate_cpp_py(${CMAKE_CURRENT_SOURCE_DIR} Caffe_PROTO_SRCS Caffe_PROTO_HEADERS Caffe_PROTO_PY ${Caffe_PROTOBUF_FILES})
add_library(Caffe_PROTO SHARED ${Caffe_PROTO_HEADERS} ${Caffe_PROTO_SRCS})
target_include_directories(Caffe_PROTO PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
diff --git a/caffe2/proto/CMakeLists.txt b/caffe2/proto/CMakeLists.txt
index c74be66..d100247 100644
--- a/caffe2/proto/CMakeLists.txt
+++ b/caffe2/proto/CMakeLists.txt
@@ -1,8 +1,9 @@
-find_package(Protobuf REQUIRED)
+# find_package(Protobuf REQUIRED)
file(GLOB Caffe2_PROTOBUF_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.proto")
-PROTOBUF_GENERATE_CPP(Caffe2_PROTO_SRCS Caffe2_PROTO_HEADERS ${Caffe2_PROTOBUF_FILES})
+# PROTOBUF_GENERATE_CPP(Caffe2_PROTO_SRCS Caffe2_PROTO_HEADERS ${Caffe2_PROTOBUF_FILES})
+caffe_protobuf_generate_cpp_py(${CMAKE_CURRENT_SOURCE_DIR} Caffe2_PROTO_SRCS Caffe2_PROTO_HEADERS Caffe2_PROTO_PY ${Caffe2_PROTOBUF_FILES})
add_library(Caffe2_PROTO SHARED ${Caffe2_PROTO_HEADERS} ${Caffe2_PROTO_SRCS})
target_include_directories(Caffe2_PROTO PUBLIC ${CMAKE_CURRENT_BINARY_DIR})
diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
index 8e922b2..6b63b60 100644
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -1,6 +1,8 @@
# This list is required for static linking and exported to Caffe2Config.cmake
set(Caffe2_LINKER_LIBS "")
+# ---[ Custom Protobuf
+include(cmake/ProtoBuf.cmake)
# ---[ Threads
find_package(Threads REQUIRED)
list(APPEND Caffe2_LINKER_LIBS ${CMAKE_THREAD_LIBS_INIT})
diff --git a/cmake/ProtoBuf.cmake b/cmake/ProtoBuf.cmake
new file mode 100644
index 0000000..73f647f
--- /dev/null
+++ b/cmake/ProtoBuf.cmake
@@ -0,0 +1,90 @@
+# Finds Google Protocol Buffers library and compilers and extends
+# the standard cmake script with version and python generation support
+
+find_package( Protobuf REQUIRED )
+include_directories(SYSTEM ${PROTOBUF_INCLUDE_DIR})
+list(APPEND Caffe_LINKER_LIBS ${PROTOBUF_LIBRARIES})
+
+# As of Ubuntu 14.04 protoc is no longer a part of libprotobuf-dev package
+# and should be installed separately as in: sudo apt-get install protobuf-compiler
+if(EXISTS ${PROTOBUF_PROTOC_EXECUTABLE})
+ message(STATUS "Found PROTOBUF Compiler: ${PROTOBUF_PROTOC_EXECUTABLE}")
+else()
+ message(FATAL_ERROR "Could not find PROTOBUF Compiler")
+endif()
+
+if(PROTOBUF_FOUND)
+ # fetches protobuf version
+ caffe_parse_header(${PROTOBUF_INCLUDE_DIR}/google/protobuf/stubs/common.h VERION_LINE GOOGLE_PROTOBUF_VERSION)
+ string(REGEX MATCH "([0-9])00([0-9])00([0-9])" PROTOBUF_VERSION ${GOOGLE_PROTOBUF_VERSION})
+ set(PROTOBUF_VERSION "${CMAKE_MATCH_1}.${CMAKE_MATCH_2}.${CMAKE_MATCH_3}")
+ unset(GOOGLE_PROTOBUF_VERSION)
+endif()
+
+# place where to generate protobuf sources
+set(proto_gen_folder "${PROJECT_BINARY_DIR}/include/caffe/proto")
+include_directories("${PROJECT_BINARY_DIR}/include")
+
+set(PROTOBUF_GENERATE_CPP_APPEND_PATH TRUE)
+
+################################################################################################
+# Modification of standard 'protobuf_generate_cpp()' with output dir parameter and python support
+# Usage:
+# caffe_protobuf_generate_cpp_py(<output_dir> <srcs_var> <hdrs_var> <python_var> <proto_files>)
+function(caffe_protobuf_generate_cpp_py output_dir srcs_var hdrs_var python_var)
+ if(NOT ARGN)
+ message(SEND_ERROR "Error: caffe_protobuf_generate_cpp_py() called without any proto files")
+ return()
+ endif()
+
+ if(PROTOBUF_GENERATE_CPP_APPEND_PATH)
+ # Create an include path for each file specified
+ foreach(fil ${ARGN})
+ get_filename_component(abs_fil ${fil} ABSOLUTE)
+ get_filename_component(abs_path ${abs_fil} PATH)
+ list(FIND _protoc_include ${abs_path} _contains_already)
+ if(${_contains_already} EQUAL -1)
+ list(APPEND _protoc_include -I ${abs_path})
+ endif()
+ endforeach()
+ else()
+ set(_protoc_include -I ${CMAKE_CURRENT_SOURCE_DIR})
+ endif()
+
+ if(DEFINED PROTOBUF_IMPORT_DIRS)
+ foreach(dir ${PROTOBUF_IMPORT_DIRS})
+ get_filename_component(abs_path ${dir} ABSOLUTE)
+ list(FIND _protoc_include ${abs_path} _contains_already)
+ if(${_contains_already} EQUAL -1)
+ list(APPEND _protoc_include -I ${abs_path})
+ endif()
+ endforeach()
+ endif()
+
+ set(${srcs_var})
+ set(${hdrs_var})
+ set(${python_var})
+ foreach(fil ${ARGN})
+ get_filename_component(abs_fil ${fil} ABSOLUTE)
+ get_filename_component(fil_we ${fil} NAME_WE)
+
+ list(APPEND ${srcs_var} "${output_dir}/${fil_we}.pb.cc")
+ list(APPEND ${hdrs_var} "${output_dir}/${fil_we}.pb.h")
+ list(APPEND ${python_var} "${output_dir}/${fil_we}_pb2.py")
+
+ add_custom_command(
+ OUTPUT "${output_dir}/${fil_we}.pb.cc"
+ "${output_dir}/${fil_we}.pb.h"
+ "${output_dir}/${fil_we}_pb2.py"
+ COMMAND ${CMAKE_COMMAND} -E make_directory "${output_dir}"
+ COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --cpp_out ${output_dir} ${_protoc_include} ${abs_fil}
+ COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --python_out ${output_dir} ${_protoc_include} ${abs_fil}
+ DEPENDS ${abs_fil}
+ COMMENT "Running C++/Python protocol buffer compiler on ${fil}" VERBATIM )
+ endforeach()
+
+ set_source_files_properties(${${srcs_var}} ${${hdrs_var}} ${${python_var}} PROPERTIES GENERATED TRUE)
+ set(${srcs_var} ${${srcs_var}} PARENT_SCOPE)
+ set(${hdrs_var} ${${hdrs_var}} PARENT_SCOPE)
+ set(${python_var} ${${python_var}} PARENT_SCOPE)
+endfunction()