You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@singa.apache.org by wa...@apache.org on 2016/06/03 07:49:03 UTC

[58/60] incubator-singa git commit: SINGA-189 Generate python outputs of proto files

SINGA-189 Generate python outputs of proto files

Remove ProtoBuf.cmake. Add python outputs generated by proto files locate at build/src.
The proto headers are now at build/include/singa/proto.


Project: http://git-wip-us.apache.org/repos/asf/incubator-singa/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-singa/commit/da23e577
Tree: http://git-wip-us.apache.org/repos/asf/incubator-singa/tree/da23e577
Diff: http://git-wip-us.apache.org/repos/asf/incubator-singa/diff/da23e577

Branch: refs/heads/dev
Commit: da23e577e48e9f52644dabaa844a010a97286b70
Parents: 3e2507b
Author: xiezl <xi...@comp.nus.edu.sg>
Authored: Fri Jun 3 01:15:53 2016 +0800
Committer: xiezl <xi...@comp.nus.edu.sg>
Committed: Fri Jun 3 01:15:53 2016 +0800

----------------------------------------------------------------------
 cmake/Dependencies.cmake |   7 ++-
 cmake/ProtoBuf.cmake     | 116 ------------------------------------------
 src/CMakeLists.txt       |  25 ++++++---
 test/CMakeLists.txt      |   1 +
 4 files changed, 26 insertions(+), 123 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/da23e577/cmake/Dependencies.cmake
----------------------------------------------------------------------
diff --git a/cmake/Dependencies.cmake b/cmake/Dependencies.cmake
index 5505ad6..d3f0b00 100644
--- a/cmake/Dependencies.cmake
+++ b/cmake/Dependencies.cmake
@@ -1,6 +1,11 @@
 SET(SINGA_LINKER_LIBS "")
 
-INCLUDE("cmake/ProtoBuf.cmake")
+#INCLUDE("cmake/ProtoBuf.cmake")
+
+FIND_PACKAGE( Protobuf REQUIRED )
+INCLUDE_DIRECTORIES(SYSTEM ${PROTOBUF_INCLUDE_DIR})
+MESSAGE(STATUS "proto libs " ${PROTOBUF_LIBRARIES})
+LIST(APPEND singa_linker_libs ${PROTOBUF_LIBRARIES})
 
 IF(USE_LMDB)
     FIND_PACKAGE(LMDB REQUIRED)

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/da23e577/cmake/ProtoBuf.cmake
----------------------------------------------------------------------
diff --git a/cmake/ProtoBuf.cmake b/cmake/ProtoBuf.cmake
deleted file mode 100644
index 437d136..0000000
--- a/cmake/ProtoBuf.cmake
+++ /dev/null
@@ -1,116 +0,0 @@
-#/**
-# * Licensed to the Apache Software Foundation (ASF) under one
-# * or more contributor license agreements.  See the NOTICE file
-# * distributed with this work for additional information
-# * regarding copyright ownership.  The ASF licenses this file
-# * to you under the Apache License, Version 2.0 (the
-# * "License"); you may not use this file except in compliance
-# * with the License.  You may obtain a copy of the License at
-# *
-# *     http://www.apache.org/licenses/LICENSE-2.0
-# *
-# * Unless required by applicable law or agreed to in writing, software
-# * distributed under the License is distributed on an "AS IS" BASIS,
-# * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# * See the License for the specific language governing permissions and
-# * limitations under the License.
-# */
-
-# This file is adpated from Caffe cmake/ProtoBuf.cmake.
-# We changed 'caffe' to 'singa'
-
-# 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})
-MESSAGE(STATUS "proto libs " ${PROTOBUF_LIBRARIES})
-list(APPEND singa_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/singa/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:
-#   singa_protobuf_generate_cpp_py(<output_dir> <srcs_var> <hdrs_var>
-#                                  <python_var> <proto_files>)
-function(singa_protobuf_generate_cpp_py output_dir srcs_var hdrs_var python_var)
-  if(NOT ARGN)
-    message(SEND_ERROR
-      "Error: singa_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()

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/da23e577/src/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 28066de..952f7ee 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,8 +1,21 @@
 # generate protobuf sources
 FILE(GLOB proto_files proto/*.proto)
-singa_protobuf_generate_cpp_py(${proto_gen_folder} proto_srcs proto_hdrs proto_python ${proto_files})
-# include python files either to force generation
-ADD_LIBRARY(proto STATIC ${proto_hdrs} ${proto_srcs} ${proto_python})
+protobuf_generate_cpp(proto_srcs proto_hdrs ${proto_files})
+protobuf_generate_python(proto_pys ${proto_files})
+INCLUDE_DIRECTORIES("${CMAKE_BINARY_DIR}/include")
+#message(STATUS "include: ${CMAKE_BINARY_DIR} ")
+#message(STATUS "srcs: ${proto_srcs}")
+#message(STATUS "hdrs: ${proto_hdrs}")
+#message(STATUS "pys: ${proto_pys}")
+ADD_LIBRARY(proto STATIC ${proto_hdrs} ${proto_srcs} ${proto_pys})
+FOREACH(fil ${proto_hdrs})
+    ADD_CUSTOM_COMMAND(
+        TARGET proto PRE_BUILD
+        COMMAND ${CMAKE_COMMAND} -E make_directory "${CMAKE_BINARY_DIR}/include/singa/proto"
+        COMMAND ${CMAKE_COMMAND} -E copy ${fil} "${CMAKE_BINARY_DIR}/include/singa/proto"
+        #COMMAND ${CMAKE_COMMAND} -E echo "copy done"
+        )
+ENDFOREACH()
 LIST(APPEND SINGA_LINKER_LIBS proto)
 
 #FILE(GLOB_RECURSE utils_source ${CMAKE_CURRENT_SOURCE_DIR}/utils/ "*.cc")
@@ -19,14 +32,14 @@ AUX_SOURCE_DIRECTORY(core/memory core_source)
 AUX_SOURCE_DIRECTORY(core/scheduler core_source)
 AUX_SOURCE_DIRECTORY(core/tensor core_source)
 FILE(GLOB_RECURSE cuda_source core "*.cu")
-set(FLAGS_BACKUP ${CMAKE_CXX_FLAGS})
-set(CMAKE_CXX_FLAGS "")
+SET(FLAGS_BACKUP ${CMAKE_CXX_FLAGS})
+SET(CMAKE_CXX_FLAGS "")
 CUDA_COMPILE(cuda_objs SHARED ${cuda_source} OPTIONS "-Xcompiler -fPIC")
 #message(STATUS "FLAGS ${CMAKE_CXX_FLAGS}")
 #message(STATUS "CORE ${cuda_source}")
 #message(STATUS "OBJ ${cuda_objs}")
 include_directories("${CMAKE_CURRENT_SOURCE_DIR}/core/tensor")
-set(CMAKE_CXX_FLAGS ${FLAGS_BACKUP})
+SET(CMAKE_CXX_FLAGS ${FLAGS_BACKUP})
 ADD_LIBRARY(singa_core SHARED ${core_source} ${cuda_objs})
 TARGET_LINK_LIBRARIES(singa_core ${SINGA_LINKER_LIBS})
 LIST(APPEND SINGA_LINKER_LIBS singa_core)

http://git-wip-us.apache.org/repos/asf/incubator-singa/blob/da23e577/test/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt
index a8b0e29..92401ad 100644
--- a/test/CMakeLists.txt
+++ b/test/CMakeLists.txt
@@ -1,4 +1,5 @@
 INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
+INCLUDE_DIRECTORIES(${CMAKE_BINARY_DIR}/include)
 ADD_LIBRARY(gtest STATIC EXCLUDE_FROM_ALL "gtest/gtest.h" "gtest/gtest-all.cc")
 
 AUX_SOURCE_DIRECTORY(singa singa_test_source)