Commit 15d18b8e authored by Alexander David Hellwig's avatar Alexander David Hellwig
Browse files

Simplify CMake model

parent e1291d9d
......@@ -11,7 +11,6 @@ import de.monticore.lang.monticar.generator.rosmsg.util.FileContent;
import java.util.ArrayList;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;
public class LanguageUnitRosCMake {
......@@ -20,13 +19,8 @@ public class LanguageUnitRosCMake {
String name = NameHelper.getAdapterName(component);
RosCppCMakeListsModel model = new RosCppCMakeListsModel(name, compName);
List<String> allPackages = new ArrayList<>();
if (!ros2Mode) {
allPackages.add("roscpp");
} else {
allPackages.add("rclcpp");
}
allPackages.add(ros2Mode ? "rclcpp" : "roscpp");
rosInterfaces.stream()
.map(RosInterface::getRosConnectionSymbol)
......@@ -35,33 +29,11 @@ public class LanguageUnitRosCMake {
.map(n -> n.split("/")[0])
.forEach(allPackages::add);
List<String> distinctSortedPackages = allPackages.stream()
.distinct()
.sorted()
.collect(Collectors.toList());
distinctSortedPackages.stream()
.filter(p -> !p.equals("struct_msgs"))
.forEach(model::addPackage);
distinctSortedPackages
.forEach(model::addInclude);
distinctSortedPackages
.forEach(model::addLibrary);
allPackages.forEach(model::addPackage);
List<FileContent> result = new ArrayList<>();
FileContent fileContent = new FileContent();
fileContent.setFileName("CMakeLists.txt");
fileContent.setFileContent(RosCppTemplates.generateRosCMakeLists(model));
result.add(fileContent);
FileContent cppFile = new FileContent();
cppFile.setFileName(name + ".cpp");
cppFile.setFileContent("#include \"" + name + ".h\"");
result.add(cppFile);
result.add(new FileContent("CMakeLists.txt", RosCppTemplates.generateRosCMakeLists(model)));
result.add(new FileContent(name + ".cpp","#include \"" + name + ".h\""));
return result;
}
}
......@@ -3,13 +3,12 @@ package de.monticore.lang.monticar.generator.roscpp.template;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.stream.Collectors;
public class RosCppCMakeListsModel {
private String name;
private String compName;
private List<String> packages = new ArrayList<>();
private List<String> additionalIncludes = new ArrayList<>();
private List<String> additionalLibraries = new ArrayList<>();
public String getName() {
return name;
......@@ -20,15 +19,10 @@ public class RosCppCMakeListsModel {
}
public List<String> getPackages() {
return packages;
}
public List<String> getAdditionalIncludes() {
return additionalIncludes;
}
public List<String> getAdditionalLibraries() {
return additionalLibraries;
return packages.stream()
.sorted()
.distinct()
.collect(Collectors.toList());
}
public RosCppCMakeListsModel(String name, String compName) {
......@@ -43,20 +37,4 @@ public class RosCppCMakeListsModel {
public boolean addPackages(Collection<? extends String> collection) {
return packages.addAll(collection);
}
public boolean addInclude(String s) {
return additionalIncludes.add(s);
}
public boolean addIncludes(Collection<? extends String> collection) {
return additionalIncludes.addAll(collection);
}
public boolean addLibrary(String s) {
return additionalLibraries.add(s);
}
public boolean addLibraries(Collection<? extends String> collection) {
return additionalLibraries.addAll(collection);
}
}
......@@ -4,20 +4,22 @@ set (CMAKE_CXX_STANDARD 14)
set (AMENT_CMAKE_UNINSTALL_TARGET FALSE)
<#list model.getPackages() as pack>
find_package(${pack} REQUIRED)
<#if pack != "struct_msgs">
find_package(${pack} REQUIRED)
</#if>
</#list>
add_library(${model.name} ${model.name}.cpp)
list(APPEND LIBRARIES ${model.compName})
list(APPEND LIBRARIES IAdapter_${model.compName})
<#list model.getAdditionalLibraries() as lib>
<#list model.getPackages() as lib>
list(APPEND LIBRARIES ${r"${"}${lib}_LIBRARIES})
</#list>
target_link_libraries(${model.name} <#noparse>${LIBRARIES}</#noparse>)
list(APPEND INCLUDE_DIRS <#noparse>${CMAKE_CURRENT_SOURCE_DIR}</#noparse>)
<#list model.getAdditionalIncludes() as incl>
<#list model.getPackages() as incl>
list(APPEND INCLUDE_DIRS ${r"${"}${incl}_INCLUDE_DIRS})
</#list>
target_include_directories(${model.name} PUBLIC <#noparse>${INCLUDE_DIRS}</#noparse>)
......
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