Skip to content

Commit 792bf0b

Browse files
authored
Fix for cmake 1.11 (#14350)
test=develop
1 parent 080740b commit 792bf0b

File tree

1 file changed

+49
-53
lines changed

1 file changed

+49
-53
lines changed

cmake/external/protobuf.cmake

Lines changed: 49 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -30,66 +30,61 @@ UNSET_VAR(PROTOBUF_LITE_LIBRARY)
3030
UNSET_VAR(PROTOBUF_LIBRARY)
3131
UNSET_VAR(PROTOBUF_INCLUDE_DIR)
3232
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()
3339

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
7142
foreach(FIL ${ARGN})
7243
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})
7948
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()
8056

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()
8864
endforeach()
65+
endif()
8966

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()
9388

9489
# Print and set the protobuf library information,
9590
# finish this cmake process and exit from this file.
@@ -126,6 +121,7 @@ macro(PROMPT_PROTOBUF_LIB)
126121
# FIND_Protobuf.cmake uses `Protobuf_PROTOC_EXECUTABLE`.
127122
# make `protobuf_generate_cpp` happy.
128123
SET(Protobuf_PROTOC_EXECUTABLE ${PROTOBUF_PROTOC_EXECUTABLE})
124+
129125
FOREACH(dep ${protobuf_DEPS})
130126
ADD_DEPENDENCIES(protobuf ${dep})
131127
ADD_DEPENDENCIES(protobuf_lite ${dep})

0 commit comments

Comments
 (0)