提交 30b75a51 编写于 作者: Y Yu Yang

Also add pb_py_library

上级 b1a311c4
......@@ -341,13 +341,6 @@ function(pb_cc_library TARGET_NAME)
foreach(FIL ${pb_cc_library_SRCS})
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
get_filename_component(FIL_WE ${FIL} NAME_WE)
if(NOT PROTOBUF_GENERATE_CPP_APPEND_PATH)
get_filename_component(FIL_DIR ${FIL} DIRECTORY)
if(FIL_DIR)
set(FIL_WE "${FIL_DIR}/${FIL_WE}")
endif()
endif()
list(APPEND proto_srcs "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.cc")
list(APPEND proto_hdrs "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}.pb.h")
......@@ -364,3 +357,27 @@ function(pb_cc_library TARGET_NAME)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
cc_library(${TARGET_NAME} SRCS ${proto_srcs})
endfunction()
function(pb_py_library TARGET_NAME)
set(oneValueArgs TARGET_DIR)
set(multiValueArgs SRCS)
cmake_parse_arguments(pb_py_library "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
if (NOT ${pb_py_library_TARGET_DIR})
set(pb_py_library_TARGET_DIR ${CMAKE_CURRENT_BINARY_DIR})
endif()
set(py_srcs)
foreach(FIL ${pb_py_library_SRCS})
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
get_filename_component(FIL_WE ${FIL} NAME_WE)
set(cur_py_src ${pb_py_library_TARGET_DIR}/${FIL_WE}_pb2.py)
list(APPEND py_srcs "${cur_py_src}")
add_custom_command(OUTPUT ${cur_py_src}
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE}
ARGS "--python_out=${pb_py_library_TARGET_DIR}" "-I" ${CMAKE_CURRENT_SOURCE_DIR} ${ABS_FIL}
DEPENDS ${ABS_FIL} protoc
COMMENT "Running Python protocol buffer compiler on ${FIL}")
endforeach()
add_custom_target(${TARGET_NAME} ALL DEPENDS ${py_srcs})
endfunction()
\ No newline at end of file
set(proto_filenames
DataConfig.proto
DataFormat.proto
ModelConfig.proto
ParameterConfig.proto
ParameterService.proto
TrainerConfig.proto
OptimizerConfig.proto
ParameterServerConfig.proto)
set(PROTO_GEN)
set(PROTO_GEN_PY)
foreach(filename ${proto_filenames})
get_filename_component(base_filename ${filename} NAME_WE)
set(CUR_PROTO_GEN_PY
${PROJ_ROOT}/paddle/python/paddle/proto/${base_filename}_pb2.py)
set(PROTO_GEN_PY
${CUR_PROTO_GEN_PY}
${PROTO_GEN_PY})
add_custom_command(OUTPUT ${CUR_PROTO_GEN_PY}
COMMAND env ${py_env} ${PROTOBUF_PROTOC_EXECUTABLE} --python_out ${PROJ_ROOT}/python/paddle/proto
--proto_path ${PROJ_ROOT}/proto ${PROJ_ROOT}/proto/${filename}
DEPENDS ${filename} ${external_project_dependencies})
endforeach()
add_custom_target(gen_proto_py ALL DEPENDS ${PROTO_GEN_PY})
file(GLOB proto_filenames . *.proto)
pb_cc_library(paddle_proto SRCS ${proto_filenames})
pb_py_library(gen_proto_py SRCS ${proto_filenames} TARGET_DIR ${CMAKE_CURRENT_SOURCE_DIR})
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册