Skip to content

Commit e3de421

Browse files
authored
Generate proto files at build time. (#38)
* Generate proto files at build time. This change aligns the build step with others, like rosidl_typesupport_fastrtps_c, and makes dependencies clearer. * Set CMP0148 to preserve old python interpreter-finding logic * Only set CMP0148 if known
1 parent 7d9ee0b commit e3de421

File tree

1 file changed

+20
-13
lines changed

1 file changed

+20
-13
lines changed

rosidl_adapter_proto/cmake/rosidl_adapt_proto_interfaces.cmake

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@
1616
#
1717
# ================================= Apache 2.0 =================================
1818

19+
if(POLICY CMP0148)
20+
cmake_policy(SET CMP0148 OLD)
21+
endif()
22+
1923
find_package(PythonInterp REQUIRED)
2024
if(NOT PYTHON_EXECUTABLE)
2125
message(FATAL_ERROR "Variable 'PYTHON_EXECUTABLE' must not be empty")
@@ -53,26 +57,29 @@ rosidl_write_generator_arguments(
5357
TARGET_DEPENDENCIES ${_target_dependencies}
5458
ADDITIONAL_FILES "${_proto_include_dirs}")
5559

56-
execute_process(
57-
COMMAND "${PYTHON_EXECUTABLE}" "${rosidl_adapter_proto_BIN}"
58-
--generator-arguments-file "${generator_arguments_file}"
59-
--protoc-path "${Protobuf_PROTOC_EXECUTABLE}"
60-
ERROR_VARIABLE error
61-
RESULT_VARIABLE result
62-
)
63-
64-
if(NOT result EQUAL 0)
65-
message(FATAL_ERROR "Proto file generation failed, error code: ${error}")
66-
endif()
67-
6860
set(rosidl_adapter_proto_INCLUDE_DIR "${CMAKE_CURRENT_BINARY_DIR}/rosidl_adapter_proto")
6961
foreach(_abs_idl_file ${rosidl_generate_interfaces_ABS_IDL_FILES})
7062
get_filename_component(_parent_folder "${_abs_idl_file}" DIRECTORY)
7163
get_filename_component(_parent_folder "${_parent_folder}" NAME)
7264
get_filename_component(_idl_name "${_abs_idl_file}" NAME_WE)
7365
list(APPEND rosidl_adapter_proto_GENERATED_CPP "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name}.pb.cc")
66+
list(APPEND rosidl_adapter_proto_GENERATED_H "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name}.pb.h")
67+
list(APPEND rosidl_adapter_proto_GENERATED_PROTO "${rosidl_adapter_proto_OUTPUT_DIR}/${_parent_folder}/${_idl_name}.proto")
7468
endforeach()
7569

70+
add_custom_command(
71+
OUTPUT ${rosidl_adapter_proto_GENERATED_CPP}
72+
${rosidl_adapter_proto_GENERATED_H}
73+
${rosidl_adapter_proto_GENERATED_PROTO}
74+
COMMAND "${PYTHON_EXECUTABLE}"
75+
ARGS "${rosidl_adapter_proto_BIN}"
76+
--generator-arguments-file "${generator_arguments_file}"
77+
--protoc-path "${Protobuf_PROTOC_EXECUTABLE}"
78+
DEPENDS ${_target_dependencies} "${PYTHON_EXECUTABLE}"
79+
COMMENT "Generating type support for Protobuf"
80+
VERBATIM
81+
)
82+
7683
# generate header to switch between export and import for a specific package
7784
set(rosidl_adapter_proto_VISIBILITY_CONTROL_HEADER
7885
"${rosidl_adapter_proto_OUTPUT_DIR}/rosidl_adapter_proto__visibility_control.h")
@@ -93,4 +100,4 @@ install(
93100
DIRECTORY ${rosidl_adapter_proto_OUTPUT_DIR}
94101
DESTINATION "share/${PROJECT_NAME}"
95102
PATTERN "*.proto"
96-
)
103+
)

0 commit comments

Comments
 (0)