Index: lib/MsgUtils/cmake/MsgUtils.cmake =================================================================== diff -u -rcfc0df719cb5033078d0cac45ce0f6243810f2e7 -rfa691c15183dfe8596de699ef8c3a7fcdb90edab --- lib/MsgUtils/cmake/MsgUtils.cmake (.../MsgUtils.cmake) (revision cfc0df719cb5033078d0cac45ce0f6243810f2e7) +++ lib/MsgUtils/cmake/MsgUtils.cmake (.../MsgUtils.cmake) (revision fa691c15183dfe8596de699ef8c3a7fcdb90edab) @@ -1,10 +1,101 @@ +# \brief This function adds a custom command to generate message defintions from inputted message conf files +# \param[in] _input_confs list of message conf files to use to generate the header +# \param[in] _device_name name of device these files are being generated for +# \param[in] _header_dir directory where the header file will be outputted +# \param[in] _source_dir directory where the source file will be outputted +# \param[in] _namespace C++ namespace for the outputted message definitions +function(generate_msg_defs_cpp _input_confs _device_name _header_dir _source_dir _namespace) + find_package(Python3 COMPONENTS Interpreter Development REQUIRED) + + # create a variable with the full path output header file + get_filename_component(_header_dir ${_header_dir} ABSOLUTE) # cmake < 3.20 + # cmake >= 3.20: cmake_path(ABSOLUTE_PATH _header_path) + string(JOIN "/" _header_path ${_header_dir} ${_device_name}MsgDefs.h) + + # create a variable with the full path output header file + get_filename_component(_source_dir ${_source_dir} ABSOLUTE) # cmake < 3.20 + # cmake >= 3.20: cmake_path(ABSOLUTE_PATH _source_path) + string(JOIN "/" _source_path ${_source_dir} ${_device_name}MsgDefs.cpp) + + # generate a pretty string containing a list of the relative paths of all csv files + foreach(_path ${${_input_confs}}) + # cmake >= 3.20: cmake_path(ABSOLUTE_PATH _path) + get_filename_component(_path ${_path} ABSOLUTE) + list(APPEND _files ${_path}) + endforeach() + list(JOIN _files ", " _file_list) + + add_custom_command( + DEPENDS + ${MSGUTILS_SCRIPTS_DIR}/MsgData.py + ${MSGUTILS_SCRIPTS_DIR}/MsgCpp.py + ${MSGUTILS_SCRIPTS_DIR}/GenerateMsgDefsCpp.py + ${MSGUTILS_SCRIPTS_DIR}/templates/MsgDefs_h.jinja + ${MSGUTILS_SCRIPTS_DIR}/templates/MsgDefs_cpp.jinja + ${${_input_confs}} + OUTPUT + ${_header_path} + ${_source_path} + COMMAND + ${Python3_EXECUTABLE} ${MSGUTILS_SCRIPTS_DIR}/GenerateMsgDefsCpp.py + --namespace ${_namespace} + --header_dir ${_header_dir} + --source_dir ${_source_dir} + ${${_input_confs}} + ${_device_name} + COMMENT "Generating MsgDefs C++ header ${_header_path} and source ${_source_path} from input ${_file_list}" + VERBATIM + ) +endfunction() + +# \brief This function adds a custom command to generate a Protobuf file from inputted message conf files +# \param[in] _input_confs list of message conf files to use to generate the header +# \param[in] _protobuf_filename name of the generated protobuf file +# \param[in] _output_path directory where the header file will be outputted +# \param[in] _namespace C++ namespace for the outputted message definitions +function(generate_protobuf _input_confs _protobuf_filename _output_path _namespace) + find_package(Python3 COMPONENTS Interpreter Development REQUIRED) + + # create a variable with the full path output header file + string(JOIN "/" _protobuf_abs_filename ${_output_path} ${_protobuf_filename}) + # cmake >= 3.20: cmake_path(ABSOLUTE_PATH _protobuf_abs_filename) + get_filename_component(_protobuf_abs_filename ${_protobuf_abs_filename} ABSOLUTE) # cmake < 3.20 + + # generate a pretty string containing a list of the relative paths of all csv files + foreach(_path ${${_input_confs}}) + # cmake >= 3.20: cmake_path(ABSOLUTE_PATH _path) + get_filename_component(_path ${_path} ABSOLUTE) # cmake < 3.20 + list(APPEND _files ${_path}) + endforeach() + list(JOIN _files ", " _file_list) + + add_custom_command( + DEPENDS + ${MSGUTILS_SCRIPTS_DIR}/MsgData.py + ${MSGUTILS_SCRIPTS_DIR}/MsgProtobuf.py + ${MSGUTILS_SCRIPTS_DIR}/GenerateProtobuf.py + ${MSGUTILS_SCRIPTS_DIR}/templates/MsgDefs_proto.jinja + ${${_input_confs}} + OUTPUT + ${_protobuf_abs_filename} + COMMAND + ${Python3_EXECUTABLE} ${MSGUTILS_SCRIPTS_DIR}/GenerateProtobuf.py + --namespace ${_namespace} + --output_dir ${_output_path} + ${${_input_confs}} + ${_protobuf_filename} + COMMENT "Generating Protobuf definitions ${_protobuf_abs_filename} from input ${_file_list}" + VERBATIM + ) +endfunction() + # \brief This function adds a custom command to generate message defintions from inputted CSV files # \param[in] _input_csvs list of CSV files to use to generate the header # \param[in] _device_name name of device these files are being generated for # \param[in] _header_dir directory where the header file will be outputted # \param[in] _source_dir directory where the source file will be outputted # \param[in] _namespace C++ namespace for the outputted message definitions -function(generate_msg_defs_cpp _input_csvs _device_name _header_dir _source_dir _namespace) +function(generate_msg_defs_cpp_csvs _input_csvs _device_name _header_dir _source_dir _namespace) find_package(Python3 COMPONENTS Interpreter Development REQUIRED) # create a variable with the full path output header file @@ -53,7 +144,7 @@ # \param[in] _protobuf_filename name of the generated protobuf file # \param[in] _output_path directory where the header file will be outputted # \param[in] _namespace C++ namespace for the outputted message definitions -function(generate_protobuf _input_csvs _protobuf_filename _output_path _namespace) +function(generate_protobuf_csvs _input_csvs _protobuf_filename _output_path _namespace) find_package(Python3 COMPONENTS Interpreter Development REQUIRED) # create a variable with the full path output header file