diff --git a/caffe/proto/CMakeLists.txt b/caffe/proto/CMakeLists.txt index 99e478ea33c..a6f1fc5cb66 100644 --- a/caffe/proto/CMakeLists.txt +++ b/caffe/proto/CMakeLists.txt @@ -2,7 +2,7 @@ file(GLOB Caffe_PROTOBUF_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.proto") -caffe_protobuf_generate_cpp_py(${CMAKE_CURRENT_BINARY_DIR} Caffe_PROTO_SRCS Caffe_PROTO_HEADERS Caffe_PROTO_PY ${Caffe_PROTOBUF_FILES}) +caffe2_protobuf_generate_cpp_py(Caffe_PROTO_SRCS Caffe_PROTO_HEADERS Caffe_PROTO_PY ${Caffe_PROTOBUF_FILES}) add_library(Caffe_PROTO OBJECT ${Caffe_PROTO_HEADERS} ${Caffe_PROTO_SRCS}) install(FILES ${Caffe_PROTO_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/caffe/proto) diff --git a/caffe2/proto/CMakeLists.txt b/caffe2/proto/CMakeLists.txt index bd1d9047f94..f255880a8dc 100644 --- a/caffe2/proto/CMakeLists.txt +++ b/caffe2/proto/CMakeLists.txt @@ -2,7 +2,7 @@ file(GLOB Caffe2_PROTOBUF_FILES "${CMAKE_CURRENT_SOURCE_DIR}/*.proto") -caffe_protobuf_generate_cpp_py(${CMAKE_CURRENT_BINARY_DIR} Caffe2_PROTO_SRCS Caffe2_PROTO_HEADERS Caffe2_PROTO_PY ${Caffe2_PROTOBUF_FILES}) +caffe2_protobuf_generate_cpp_py(Caffe2_PROTO_SRCS Caffe2_PROTO_HEADERS Caffe2_PROTO_PY ${Caffe2_PROTOBUF_FILES}) add_library(Caffe2_PROTO OBJECT ${Caffe2_PROTO_HEADERS} ${Caffe2_PROTO_SRCS}) install(FILES ${Caffe2_PROTO_HEADERS} DESTINATION ${CMAKE_INSTALL_PREFIX}/include/caffe2/proto) diff --git a/cmake/ProtoBuf.cmake b/cmake/ProtoBuf.cmake index f48c827ecbe..2e63b89bcd3 100644 --- a/cmake/ProtoBuf.cmake +++ b/cmake/ProtoBuf.cmake @@ -45,46 +45,16 @@ if (NOT (Protobuf_FOUND OR PROTOBUF_FOUND) ) message(FATAL_ERROR "Could not find Protobuf or compile local 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( ) -function(caffe_protobuf_generate_cpp_py output_dir srcs_var hdrs_var python_var) +# caffe2_protobuf_generate_cpp_py( ) +function(caffe2_protobuf_generate_cpp_py 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}) @@ -92,17 +62,18 @@ function(caffe_protobuf_generate_cpp_py output_dir srcs_var hdrs_var python_var) 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") + list(APPEND ${srcs_var} "${CMAKE_CURRENT_BINARY_DIR}/${fil_we}.pb.cc") + list(APPEND ${hdrs_var} "${CMAKE_CURRENT_BINARY_DIR}/${fil_we}.pb.h") + list(APPEND ${python_var} "${CMAKE_CURRENT_BINARY_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} + OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${fil_we}.pb.cc" + "${CMAKE_CURRENT_BINARY_DIR}/${fil_we}.pb.h" + "${CMAKE_CURRENT_BINARY_DIR}/${fil_we}_pb2.py" + WORKING_DIRECTORY ${PROJECT_SOURCE_DIR} + COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_CURRENT_BINARY_DIR}" + COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} -I${PROJECT_SOURCE_DIR} --cpp_out "${PROJECT_BINARY_DIR}" ${abs_fil} + COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} -I${PROJECT_SOURCE_DIR} --python_out "${PROJECT_BINARY_DIR}" ${abs_fil} DEPENDS ${abs_fil} COMMENT "Running C++/Python protocol buffer compiler on ${fil}" VERBATIM ) endforeach()