Commit af3f2c84 authored by Alexander David Hellwig's avatar Alexander David Hellwig
Browse files

Move templates from constants to files

parent e5788144
package de.monticore.lang.monticar.generator.roscpp.helper;
import de.se_rwth.commons.logging.Log;
import org.apache.commons.io.IOUtils;
import java.util.HashMap;
import java.util.Map;
public class TemplateHelper {
private static Map<String, String> cache = new HashMap<>();
private static String getTemplate(String fileName) {
if (cache.containsKey(fileName)) {
return cache.get(fileName);
}
String tmpStr = "";
String resourceFileName = "/de/monticore/lang/monticar/generator/roscpp/" + fileName;
try {
tmpStr = IOUtils.toString(TemplateHelper.class.getResourceAsStream(resourceFileName));
} catch (Exception e) {
//Not recoverable
Log.error("Template file not found: " + resourceFileName);
}
cache.put(fileName, tmpStr);
return tmpStr;
}
public static String getCMakeListsTemplate() {
return getTemplate("CMakeLists.template");
}
public static String getMsgGenTemplate() {
return getTemplate("msgGen.template");
}
public static String getRos2MsgGenTemplate() {
return getTemplate("ros2MsgGen.template");
}
public static String getGenerateMsgsPyTemplate() {
return getTemplate("generateMsgs.py.template");
}
}
cmake_minimum_required(VERSION 3.5)
project (<name>)
set (CMAKE_CXX_STANDARD 14)
set (AMENT_CMAKE_UNINSTALL_TARGET FALSE)
<packages>
add_library(<name> <name>.cpp)
set_target_properties(<name> PROPERTIES LINKER_LANGUAGE CXX)
target_link_libraries(<name> <compName> IAdapter_<compName> <libraries>)
target_include_directories(<name> PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} <include_dirs>)
<dependency>
export(TARGETS <name> FILE <name>.cmake)
\ No newline at end of file
import rosidl_generator_cpp
import rosidl_typesupport_cpp
import os
cur_dir = os.path.dirname(os.path.abspath(__file__)).replace("\\","/")
template = None
with open(cur_dir + "/rclcpp_msg_gen.json", "r") as f:
template = f.read()
if template == None:
print("Could not load template file!")
exit(1)
ros_base = os.path.dirname(os.path.abspath(rosidl_generator_cpp.__file__))
if os.name == "posix":
ros_base = os.path.abspath(ros_base + "/../../../..")
else:
ros_base = os.path.abspath(ros_base + "/../../..")
template = template.replace("<ros_base>",ros_base.replace("\\","/"))
template = template.replace("<cur_dir>",cur_dir.replace("\\","/"))
generator_arguments_file = cur_dir + "/rclcpp_msg_gen_filled.json"
with open(generator_arguments_file,"w") as f:
f.write(template)
rosidl_generator_cpp.generate_cpp(generator_arguments_file)
# rosidl_typesupport_cpp.generate_cpp(generator_arguments_file, ["rosidl_typesupport_cpp", "rosidl_typesupport_introspection_cpp" ,"rosidl_typesupport_opensplice_cpp"])
\ No newline at end of file
# Generate .h files from .msg files
add_custom_target(gen_<name>_<struct_replaced> ALL
COMMAND python /opt/ros/kinetic/lib/gencpp/gen_cpp.py ${CMAKE_CURRENT_SOURCE_DIR}/<struct>.msg -Istruct_msgs:${CMAKE_CURRENT_SOURCE_DIR}/struct_msgs -p struct_msgs -o ${CMAKE_CURRENT_SOURCE_DIR}/struct_msgs -e /opt/ros/kinetic/share/gencpp/)
\ No newline at end of file
# Generate .h files from .msg files
add_custom_target(gen_<name>_<struct_replaced> ALL
COMMAND ${PYTHON_EXECUTABLE} ${CMAKE_CURRENT_SOURCE_DIR}/generateMsgs.py)
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment