Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2896e5b

Browse files
committed
update cmake
1 parent 1458203 commit 2896e5b

9 files changed

Lines changed: 100 additions & 7 deletions

File tree

cmake/external/protobuf.cmake

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,70 @@ function(protobuf_generate_python SRCS)
8686
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
8787
endfunction()
8888

89+
function(grpc_protobuf_generate_python SRCS)
90+
# shameless copy from https://github.com/Kitware/CMake/blob/master/Modules/FindProtobuf.cmake
91+
if(NOT ARGN)
92+
message(SEND_ERROR "Error: GRPC_PROTOBUF_GENERATE_PYTHON() called without any proto files")
93+
return()
94+
endif()
95+
96+
if(PROTOBUF_GENERATE_CPP_APPEND_PATH)
97+
# Create an include path for each file specified
98+
foreach(FIL ${ARGN})
99+
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
100+
get_filename_component(ABS_PATH ${ABS_FIL} PATH)
101+
list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
102+
if(${_contains_already} EQUAL -1)
103+
list(APPEND _protobuf_include_path -I ${ABS_PATH})
104+
endif()
105+
endforeach()
106+
else()
107+
set(_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR})
108+
endif()
109+
if(DEFINED PROTOBUF_IMPORT_DIRS AND NOT DEFINED Protobuf_IMPORT_DIRS)
110+
set(Protobuf_IMPORT_DIRS "${PROTOBUF_IMPORT_DIRS}")
111+
endif()
112+
113+
if(DEFINED Protobuf_IMPORT_DIRS)
114+
foreach(DIR ${Protobuf_IMPORT_DIRS})
115+
get_filename_component(ABS_PATH ${DIR} ABSOLUTE)
116+
list(FIND _protobuf_include_path ${ABS_PATH} _contains_already)
117+
if(${_contains_already} EQUAL -1)
118+
list(APPEND _protobuf_include_path -I ${ABS_PATH})
119+
endif()
120+
endforeach()
121+
endif()
122+
123+
set(${SRCS})
124+
foreach(FIL ${ARGN})
125+
get_filename_component(ABS_FIL ${FIL} ABSOLUTE)
126+
get_filename_component(FIL_WE ${FIL} NAME_WE)
127+
if(NOT PROTOBUF_GENERATE_CPP_APPEND_PATH)
128+
get_filename_component(FIL_DIR ${FIL} DIRECTORY)
129+
if(FIL_DIR)
130+
set(FIL_WE "${FIL_DIR}/${FIL_WE}")
131+
endif()
132+
endif()
133+
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py")
134+
add_custom_command(
135+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2.py"
136+
COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --python_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
137+
DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_EXECUTABLE}
138+
COMMENT "Running Python protocol buffer compiler on ${FIL}"
139+
VERBATIM )
140+
list(APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2_grpc.py")
141+
add_custom_command(
142+
OUTPUT "${CMAKE_CURRENT_BINARY_DIR}/${FIL_WE}_pb2_grpc.py"
143+
COMMAND ${PYTHON_EXECUTABLE} -m grpc_tools.protoc --python_out ${CMAKE_CURRENT_BINARY_DIR} --grpc_python_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
144+
DEPENDS ${ABS_FIL}
145+
COMMENT "Running Python grpc protocol buffer compiler on ${FIL}"
146+
VERBATIM )
147+
endforeach()
148+
149+
set(${SRCS} ${${SRCS}} PARENT_SCOPE)
150+
endfunction()
151+
152+
89153
# Print and set the protobuf library information,
90154
# finish this cmake process and exit from this file.
91155
macro(PROMPT_PROTOBUF_LIB)

cmake/generic.cmake

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,15 @@ function(py_proto_compile TARGET_NAME)
704704
add_custom_target(${TARGET_NAME} ALL DEPENDS ${py_srcs})
705705
endfunction()
706706

707+
function(py_grpc_proto_compile TARGET_NAME)
708+
set(oneValueArgs "")
709+
set(multiValueArgs SRCS)
710+
cmake_parse_arguments(py_grpc_proto_compile "${options}" "${oneValueArgs}" "${multiValueArgs}" ${ARGN})
711+
set(py_srcs)
712+
grpc_protobuf_generate_python(py_srcs ${py_grpc_proto_compile_SRCS})
713+
add_custom_target(${TARGET_NAME} ALL DEPENDS ${py_srcs})
714+
endfunction()
715+
707716
function(py_test TARGET_NAME)
708717
if(WITH_TESTING)
709718
set(options "")

core/configure/CMakeLists.txt

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ py_proto_compile(general_model_config_py_proto SRCS proto/general_model_config.p
3535
add_custom_target(general_model_config_py_proto_init ALL COMMAND ${CMAKE_COMMAND} -E touch __init__.py)
3636
add_dependencies(general_model_config_py_proto general_model_config_py_proto_init)
3737

38+
py_grpc_proto_compile(multi_lang_general_model_service_py_proto SRCS proto/multi_lang_general_model_service.proto)
39+
add_custom_target(multi_lang_general_model_service_py_proto_init ALL COMMAND ${CMAKE_COMMAND} -E touch __init__.py)
40+
add_dependencies(multi_lang_general_model_service_py_proto multi_lang_general_model_service_py_proto_init)
41+
3842
if (CLIENT)
3943
py_proto_compile(sdk_configure_py_proto SRCS proto/sdk_configure.proto)
4044
add_custom_target(sdk_configure_py_proto_init ALL COMMAND ${CMAKE_COMMAND} -E touch __init__.py)
@@ -51,6 +55,11 @@ add_custom_command(TARGET general_model_config_py_proto POST_BUILD
5155
COMMENT "Copy generated general_model_config proto file into directory paddle_serving_client/proto."
5256
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
5357

58+
add_custom_command(TARGET multi_lang_general_model_service_py_proto POST_BUILD
59+
COMMAND ${CMAKE_COMMAND} -E make_directory ${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_client/proto
60+
COMMAND cp *.py ${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_client/proto
61+
COMMENT "Copy generated multi_lang_general_model_service proto file into directory paddle_serving_client/proto."
62+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
5463
endif()
5564

5665
if (APP)
@@ -77,6 +86,11 @@ add_custom_command(TARGET general_model_config_py_proto POST_BUILD
7786
COMMAND cp *.py ${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_server/proto
7887
COMMENT "Copy generated general_model_config proto file into directory paddle_serving_server/proto."
7988
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
89+
add_custom_command(TARGET multi_lang_general_model_service_py_proto POST_BUILD
90+
COMMAND ${CMAKE_COMMAND} -E make_directory ${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_server/proto
91+
COMMAND cp *.py ${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_server/proto
92+
COMMENT "Copy generated multi_lang_general_model_service proto file into directory paddle_serving_server/proto."
93+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
8094
else()
8195
add_custom_command(TARGET server_config_py_proto POST_BUILD
8296
COMMAND ${CMAKE_COMMAND} -E make_directory
@@ -95,5 +109,11 @@ add_custom_command(TARGET general_model_config_py_proto POST_BUILD
95109
COMMENT "Copy generated general_model_config proto file into directory
96110
paddle_serving_server_gpu/proto."
97111
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
112+
113+
add_custom_command(TARGET multi_lang_general_model_service_py_proto POST_BUILD
114+
COMMAND ${CMAKE_COMMAND} -E make_directory ${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_server_gpu/proto
115+
COMMAND cp *.py ${PADDLE_SERVING_BINARY_DIR}/python/paddle_serving_server_gpu/proto
116+
COMMENT "Copy generated multi_lang_general_model_service proto file into directory paddle_serving_server_gpu/proto."
117+
WORKING_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR})
98118
endif()
99119
endif()

python/paddle_serving_server/multi_lang_general_model_service.proto renamed to core/configure/proto/multi_lang_general_model_service.proto

File renamed without changes.

python/paddle_serving_client/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@
2424
from .serving_client import PredictorRes
2525

2626
import grpc
27-
import multi_lang_general_model_service_pb2
28-
import multi_lang_general_model_service_pb2_grpc
27+
from .proto import multi_lang_general_model_service_pb2
28+
from .proto import multi_lang_general_model_service_pb2_grpc
2929

3030
int_type = 0
3131
float_type = 1

python/paddle_serving_server/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,8 @@
2727

2828
import numpy as np
2929
import grpc
30-
import multi_lang_general_model_service_pb2
31-
import multi_lang_general_model_service_pb2_grpc
30+
from .proto import multi_lang_general_model_service_pb2
31+
from .proto import multi_lang_general_model_service_pb2_grpc
3232
from multiprocessing import Pool, Process
3333
from concurrent import futures
3434

python/requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
numpy>=1.12, <=1.16.4 ; python_version<"3.5"
1+
numpy>=1.12, <=1.16.4 ; grpcio>=1.28.1 ; python_version<"3.5"

python/setup.py.client.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ if '${PACK}' == 'ON':
5858

5959

6060
REQUIRED_PACKAGES = [
61-
'six >= 1.10.0', 'protobuf >= 3.1.0', 'numpy >= 1.12'
61+
'six >= 1.10.0', 'protobuf >= 3.1.0', 'numpy >= 1.12', 'grpcio >= 1.28.1'
6262
]
6363

6464
if not find_package("paddlepaddle") and not find_package("paddlepaddle-gpu"):

python/setup.py.server_gpu.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def python_version():
3737
max_version, mid_version, min_version = python_version()
3838

3939
REQUIRED_PACKAGES = [
40-
'six >= 1.10.0', 'protobuf >= 3.1.0',
40+
'six >= 1.10.0', 'protobuf >= 3.1.0', 'grpcio >= 1.28.1',
4141
'paddle_serving_client', 'flask >= 1.1.1', 'paddle_serving_app'
4242
]
4343

0 commit comments

Comments
 (0)