@@ -30,66 +30,61 @@ UNSET_VAR(PROTOBUF_LITE_LIBRARY)
30
30
UNSET_VAR (PROTOBUF_LIBRARY )
31
31
UNSET_VAR (PROTOBUF_INCLUDE_DIR )
32
32
UNSET_VAR (Protobuf_PROTOC_EXECUTABLE )
33
+ function (protobuf_generate_python SRCS )
34
+ # shameless copy from https://github.com/Kitware/CMake/blob/master/Modules/FindProtobuf.cmake
35
+ if (NOT ARGN )
36
+ message (SEND_ERROR "Error: PROTOBUF_GENERATE_PYTHON() called without any proto files" )
37
+ return ()
38
+ endif ()
33
39
34
- if (NOT COMMAND protobuf_generate_python ) # before cmake 3.4, protobuf_genrerate_python is not defined.
35
- function (protobuf_generate_python SRCS )
36
- # shameless copy from https://github.com/Kitware/CMake/blob/master/Modules/FindProtobuf.cmake
37
- if (NOT ARGN )
38
- message (SEND_ERROR "Error: PROTOBUF_GENERATE_PYTHON() called without any proto files" )
39
- return ()
40
- endif ()
41
-
42
- if (PROTOBUF_GENERATE_CPP_APPEND_PATH )
43
- # Create an include path for each file specified
44
- foreach (FIL ${ARGN} )
45
- get_filename_component (ABS_FIL ${FIL} ABSOLUTE )
46
- get_filename_component (ABS_PATH ${ABS_FIL} PATH )
47
- list (FIND _protobuf_include_path ${ABS_PATH} _contains_already )
48
- if (${_contains_already} EQUAL -1 )
49
- list (APPEND _protobuf_include_path -I ${ABS_PATH} )
50
- endif ()
51
- endforeach ()
52
- else ()
53
- set (_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR} )
54
- endif ()
55
-
56
- if (DEFINED PROTOBUF_IMPORT_DIRS AND NOT DEFINED Protobuf_IMPORT_DIRS )
57
- set (Protobuf_IMPORT_DIRS "${PROTOBUF_IMPORT_DIRS} " )
58
- endif ()
59
-
60
- if (DEFINED Protobuf_IMPORT_DIRS )
61
- foreach (DIR ${Protobuf_IMPORT_DIRS} )
62
- get_filename_component (ABS_PATH ${DIR} ABSOLUTE )
63
- list (FIND _protobuf_include_path ${ABS_PATH} _contains_already )
64
- if (${_contains_already} EQUAL -1 )
65
- list (APPEND _protobuf_include_path -I ${ABS_PATH} )
66
- endif ()
67
- endforeach ()
68
- endif ()
69
-
70
- set (${SRCS} )
40
+ if (PROTOBUF_GENERATE_CPP_APPEND_PATH )
41
+ # Create an include path for each file specified
71
42
foreach (FIL ${ARGN} )
72
43
get_filename_component (ABS_FIL ${FIL} ABSOLUTE )
73
- get_filename_component (FIL_WE ${FIL} NAME_WE )
74
- if (NOT PROTOBUF_GENERATE_CPP_APPEND_PATH )
75
- get_filename_component (FIL_DIR ${FIL} DIRECTORY )
76
- if (FIL_DIR )
77
- set (FIL_WE "${FIL_DIR} /${FIL_WE} " )
78
- endif ()
44
+ get_filename_component (ABS_PATH ${ABS_FIL} PATH )
45
+ list (FIND _protobuf_include_path ${ABS_PATH} _contains_already )
46
+ if (${_contains_already} EQUAL -1 )
47
+ list (APPEND _protobuf_include_path -I ${ABS_PATH} )
79
48
endif ()
49
+ endforeach ()
50
+ else ()
51
+ set (_protobuf_include_path -I ${CMAKE_CURRENT_SOURCE_DIR} )
52
+ endif ()
53
+ if (DEFINED PROTOBUF_IMPORT_DIRS AND NOT DEFINED Protobuf_IMPORT_DIRS )
54
+ set (Protobuf_IMPORT_DIRS "${PROTOBUF_IMPORT_DIRS} " )
55
+ endif ()
80
56
81
- list ( APPEND ${SRCS} " ${CMAKE_CURRENT_BINARY_DIR} / ${FIL_WE} _pb2.py" )
82
- add_custom_command (
83
- OUTPUT " ${CMAKE_CURRENT_BINARY_DIR} / ${FIL_WE} _pb2.py"
84
- COMMAND ${Protobuf_PROTOC_EXECUTABLE} --python_out ${CMAKE_CURRENT_BINARY_DIR} ${ _protobuf_include_path} ${ABS_FIL}
85
- DEPENDS ${ABS_FIL} ${Protobuf_PROTOC_EXECUTABLE}
86
- COMMENT "Running Python protocol buffer compiler on ${FIL} "
87
- VERBATIM )
57
+ if ( DEFINED Protobuf_IMPORT_DIRS )
58
+ foreach ( DIR ${Protobuf_IMPORT_DIRS} )
59
+ get_filename_component ( ABS_PATH ${DIR} ABSOLUTE )
60
+ list ( FIND _protobuf_include_path ${ABS_PATH} _contains_already )
61
+ if ( ${_contains_already} EQUAL -1 )
62
+ list ( APPEND _protobuf_include_path -I ${ABS_PATH} )
63
+ endif ( )
88
64
endforeach ()
65
+ endif ()
89
66
90
- set (${SRCS} ${${SRCS}} PARENT_SCOPE )
91
- endfunction ()
92
- endif ()
67
+ set (${SRCS} )
68
+ foreach (FIL ${ARGN} )
69
+ get_filename_component (ABS_FIL ${FIL} ABSOLUTE )
70
+ get_filename_component (FIL_WE ${FIL} NAME_WE )
71
+ if (NOT PROTOBUF_GENERATE_CPP_APPEND_PATH )
72
+ get_filename_component (FIL_DIR ${FIL} DIRECTORY )
73
+ if (FIL_DIR )
74
+ set (FIL_WE "${FIL_DIR} /${FIL_WE} " )
75
+ endif ()
76
+ endif ()
77
+ list (APPEND ${SRCS} "${CMAKE_CURRENT_BINARY_DIR} /${FIL_WE} _pb2.py" )
78
+ add_custom_command (
79
+ OUTPUT "${CMAKE_CURRENT_BINARY_DIR} /${FIL_WE} _pb2.py"
80
+ COMMAND ${PROTOBUF_PROTOC_EXECUTABLE} --python_out ${CMAKE_CURRENT_BINARY_DIR} ${_protobuf_include_path} ${ABS_FIL}
81
+ DEPENDS ${ABS_FIL} ${PROTOBUF_PROTOC_EXECUTABLE}
82
+ COMMENT "Running Python protocol buffer compiler on ${FIL} "
83
+ VERBATIM )
84
+ endforeach ()
85
+
86
+ set (${SRCS} ${${SRCS}} PARENT_SCOPE )
87
+ endfunction ()
93
88
94
89
# Print and set the protobuf library information,
95
90
# finish this cmake process and exit from this file.
@@ -126,6 +121,7 @@ macro(PROMPT_PROTOBUF_LIB)
126
121
# FIND_Protobuf.cmake uses `Protobuf_PROTOC_EXECUTABLE`.
127
122
# make `protobuf_generate_cpp` happy.
128
123
SET (Protobuf_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE} )
124
+
129
125
FOREACH (dep ${protobuf_DEPS} )
130
126
ADD_DEPENDENCIES (protobuf ${dep} )
131
127
ADD_DEPENDENCIES (protobuf_lite ${dep} )
0 commit comments