Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
monticore
EmbeddedMontiArc
generators
EMAM2RosCpp
Commits
15d18b8e
Commit
15d18b8e
authored
Apr 05, 2019
by
Alexander David Hellwig
Browse files
Simplify CMake model
parent
e1291d9d
Changes
3
Hide whitespace changes
Inline
Side-by-side
src/main/java/de/monticore/lang/monticar/generator/roscpp/LanguageUnitRosCMake.java
View file @
15d18b8e
...
...
@@ -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
;
}
}
src/main/java/de/monticore/lang/monticar/generator/roscpp/template/RosCppCMakeListsModel.java
View file @
15d18b8e
...
...
@@ -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
);
}
}
src/main/resources/de/monticore/lang/monticar/generator/roscpp/template/CMakeLists.ftl
View file @
15d18b8e
...
...
@@ -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.get
AdditionalLibrari
es() as lib>
<#list model.get
Packag
es() 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.get
AdditionalInclud
es() as incl>
<#list model.get
Packag
es() as incl>
list(APPEND INCLUDE_DIRS ${r"${"}${incl}_INCLUDE_DIRS})
</#list>
target_include_directories(${model.name} PUBLIC <#noparse>${INCLUDE_DIRS}</#noparse>)
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment