Commit 1a4f7394 authored by Markus Georg Bendel's avatar Markus Georg Bendel

Add basic CMake generation

parent ce6f2ac5
Pipeline #159053 failed with stages
in 56 seconds
# Setting cmake version
cmake_minimum_required (VERSION 2.8)
# Using C++ version 11 with threads for compiling
# Using C++ with flags
set (CMAKE_CXX_FLAGS "-g -std=c++0x")
# Find packages and include directories
# Find vsomeip and boost packages
find_package (vsomeip 2.10.0 REQUIRED)
find_package( Boost 1.55 COMPONENTS system thread log REQUIRED )
#include vsomeip and boost directories
include_directories (
${Boost_INCLUDE_DIR}
${VSOMEIP_INCLUDE_DIRS}
)
# Linking libraries to target
add_library(SomeipAdapter_tests_a_compA SomeipAdapter_tests_a_compA.cpp)
target_link_libraries(SomeipAdapter_tests_a_compA vsomeip ${Boost_LIBRARIES})
add_library(SomeIPAdapter_tests_a_compA SomeIPAdapter_tests_a_compA.cpp)
target_link_libraries(SomeIPAdapter_tests_a_compA vsomeip ${Boost_LIBRARIES})
# Export target to a cmake module file for outside usage
export(TARGETS SomeipAdapter_tests_a_compA FILE SomeipAdapter_tests_a_compA.cmake)
export(TARGETS SomeIPAdapter_tests_a_compA FILE SomeIPAdapter_tests_a_compA.cmake)
#include "SomeipAdapter_tests_a_compA.h"
#include "SomeIPAdapter_tests_a_compA.h"
#define SAMPLE_SERVICE_ID 0x1234
#define SAMPLE_INSTANCE_ID 0x5678
......@@ -12,42 +12,42 @@ std::shared_ptr<vsomeip::application> _clockSubscriber;
std::shared_ptr<vsomeip::application> _echoPublisher;
SomeipAdapter_tests_a_compA::SomeipAdapter_tests_a_compA() {}
SomeIPAdapter_tests_a_compA::SomeIPAdapter_tests_a_compA() {}
void SomeipAdapter_tests_a_compA::init(tests_a_compA *comp)
void SomeIPAdapter_tests_a_compA::init(tests_a_compA *comp)
{
this->component = comp;
_clockSubscriber = vsomeip::runtime::get()->create_application("Subscriber");
_clockSubscriber->init();
//_clockSubscriber->register_availability_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, on_availability);
_clockSubscriber->request_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
_clockSubscriber->register_message_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID, std::bind(&SomeipAdapter_tests_a_compA::on_message, this, std::placeholders::_1));
_clockSubscriber->register_message_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID, std::bind(&SomeIPAdapter_tests_a_compA::on_message, this, std::placeholders::_1));
//_clockSubscriber->register_message_handler(vsomeip::ANY_SERVICE, vsomeip::ANY_INSTANCE, vsomeip::ANY_METHOD, std::bind(&SomeipAdapter_tests_a_compA::on_message, this, std::placeholders::_1));
std::set<vsomeip::eventgroup_t> its_groups;
its_groups.insert(SAMPLE_EVENTGROUP_ID);
_clockSubscriber->request_event(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENT_ID, its_groups, true);
_clockSubscriber->subscribe(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENTGROUP_ID);
_clockSubscriber->start();
_echoPublisher = vsomeip::runtime::get()->create_application("Publisher");
_echoPublisher->init();
//_echoPublisher->register_message_handler(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_METHOD_ID, on_message);
_echoPublisher->offer_service(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID);
_echoPublisher->start();
}
void SomeipAdapter_tests_a_compA::on_message(const std::shared_ptr<vsomeip::message> &_request) {
void SomeIPAdapter_tests_a_compA::on_message(const std::shared_ptr<vsomeip::message> &_request) {
std::shared_ptr<vsomeip::payload> its_payload = _request->get_payload();
vsomeip::length_t l = its_payload->get_length();
double dataFromMessage = *((double*)its_payload->get_data());
component->rosIn = dataFromMessage;
std::cout << "SERVICE: Received message from ["
......@@ -56,28 +56,28 @@ void SomeipAdapter_tests_a_compA::on_message(const std::shared_ptr<vsomeip::mess
<< dataFromMessage << std::endl;
}
void SomeipAdapter_tests_a_compA::publish_echoPublisher()
void SomeIPAdapter_tests_a_compA::publish_echoPublisher()
{
double d = component->rosOut;
uint8_t *byteArray = (uint8_t*)&d;
vsomeip::byte_t *p;
p = byteArray;
p = byteArray;
std::shared_ptr< vsomeip::payload > payload = vsomeip::runtime::get()->create_payload(p,8);
//const vsomeip::byte_t its_data[] = component->rosOut; //component->rosOut
//std::shared_ptr< vsomeip::payload > payload = vsomeip::runtime::get()->create_payload();
//payload->set_data(its_data, sizeof(its_data));
std::set<vsomeip::eventgroup_t> its_groups;
its_groups.insert(SAMPLE_EVENTGROUP_ID);
_echoPublisher->offer_event(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENT_ID, its_groups, true);
_echoPublisher->notify(SAMPLE_SERVICE_ID, SAMPLE_INSTANCE_ID, SAMPLE_EVENT_ID, payload);
}
void SomeipAdapter_tests_a_compA::tick()
void SomeIPAdapter_tests_a_compA::tick()
{
publish_echoPublisher();
}
......@@ -11,22 +11,22 @@
using namespace std;
class SomeipAdapter_tests_a_compA {
class SomeIPAdapter_tests_a_compA {
public:
SomeipAdapter_tests_a_compA();
SomeIPAdapter_tests_a_compA();
void init(tests_a_compA* comp);
void publish_echoPublisher();
void tick();
void on_message(const std::shared_ptr<vsomeip::message> &_response);
private:
tests_a_compA* component = nullptr;
};
......@@ -20,18 +20,18 @@ public class GeneratorSomeIP {
// Get info about the ports from the component
Collection<EMAPortInstanceSymbol> ports = component.getPortInstanceList();
// Create and fill model
SomeIPAdapterModel model = new SomeIPAdapterModel(component.getFullName());
model.addPorts(ports);
//Generate files and write to project
String content = SomeIPTemplates.generateSomeIPAdapter(model);
File file = new File("./target/generated-sources/ports.txt");
files.add(file);
FileWriter fr = null;
try {
fr = new FileWriter(file);
......@@ -49,4 +49,33 @@ public class GeneratorSomeIP {
return files;
}
File generateCMake(EMAComponentInstanceSymbol component) {
// Create and fill model
SomeIPAdapterModel model = new SomeIPAdapterModel(component.getFullName());
//Generate files and write to project
String content = SomeIPTemplates.generateSomeIPCMakeLists(model);
File file = new File("./target/generated-sources/CMakeLists.txt");
FileWriter fr = null;
try {
fr = new FileWriter(file);
fr.write(content);
} catch (IOException e) {
e.printStackTrace();
} finally {
//Close resources
try {
fr.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return file;
}
}
......@@ -22,6 +22,14 @@ public class SomeIPAdapterModel {
return compName;
}
public String getEscapedCompName() {
return compName
.replace('.', '_')
.replace('[', '_')
.replace(']', '_');
}
// Parse through component to find information about its ports
public void addPorts(Collection<EMAPortInstanceSymbol> ports)
{
......
package de.monticore.lang.monticar.generator.someip.template;
import de.se_rwth.commons.logging.Log;
import freemarker.template.Configuration;
import freemarker.template.Template;
import freemarker.template.TemplateException;
......@@ -14,6 +15,7 @@ import java.util.Map;
public class SomeIPTemplates {
private static final Template SOMEIP_PRETTYPRINT;
private static final Template SOMEIP_CMAKELISTS;
// Loading .ftl files
static {
......@@ -24,6 +26,7 @@ public class SomeIPTemplates {
conf.setClassForTemplateLoading(SomeIPTemplates.class, "");
try {
SOMEIP_PRETTYPRINT = conf.getTemplate("PrettyPrint.ftl");
SOMEIP_CMAKELISTS = conf.getTemplate("CMakeLists.ftl");
} catch (IOException e) {
String msg = "could not load template";
Log.error(msg, e);
......@@ -38,6 +41,12 @@ public class SomeIPTemplates {
}
public static String generateSomeIPCMakeLists(SomeIPAdapterModel model) {
HashMap<String, Object> data = new HashMap<>();
data.put("model", model);
return generate(SOMEIP_CMAKELISTS, data);
}
@SuppressWarnings("rawtypes")
private static String generate(Template template, Map dataForTemplate) {
Log.errorIfNull(template);
......
<#--@formatter:off-->
# Setting cmake version
cmake_minimum_required (VERSION 2.8)
# Using C++ with flags
set (CMAKE_CXX_FLAGS "-g -std=c++0x")
# Find vsomeip and boost packages
find_package (vsomeip 2.10.0 REQUIRED)
find_package( Boost 1.55 COMPONENTS system thread log REQUIRED )
#include vsomeip and boost directories
include_directories (
<#noparse>${Boost_INCLUDE_DIR}</#noparse>
<#noparse>${VSOMEIP_INCLUDE_DIRS}</#noparse>
)
# Linking libraries to target
add_library(SomeIPAdapter_${model.getEscapedCompName()} SomeIPAdapter_${model.getEscapedCompName()}.cpp)
target_link_libraries(SomeipAdapter_${model.getEscapedCompName()} vsomeip <#noparse>${Boost_LIBRARIES}</#noparse>)
# Export target to a cmake module file for outside usage
export(TARGETS SomeIPAdapter_${model.getEscapedCompName()} FILE SomeIPAdapter_${model.getEscapedCompName()}.cmake)
package de.monticore.lang.monticar.generator.someip;
import static org.junit.Assert.assertNotNull;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.junit.Test;
import de.monticore.lang.embeddedmontiarc.embeddedmontiarc._symboltable.instanceStructure.EMAComponentInstanceSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.someip.SomeIPConnectionSymbol;
import de.monticore.lang.embeddedmontiarc.tagging.middleware.ros.RosToEmamTagSchema;
import de.monticore.lang.tagging._symboltable.TaggingResolver;
public class CMakeGenerationTest extends AbstractSymtabTest {
@Test
public void testCMake() throws IOException {
TaggingResolver taggingResolver = createSymTabAndTaggingResolver("src/test/resources/");
// Ros schema is used for now
RosToEmamTagSchema.registerTagTypes(taggingResolver);
// Create component instance and run the generator
EMAComponentInstanceSymbol componentInstanceSymbol = taggingResolver.<EMAComponentInstanceSymbol>resolve("tests.a.compA", EMAComponentInstanceSymbol.KIND).orElse(null);
assertNotNull(componentInstanceSymbol);
GeneratorSomeIP generatorSomeIP = new GeneratorSomeIP();
// Connect component's ports to topics
componentInstanceSymbol.getPortInstance("portA").orElse(null).setMiddlewareSymbol(new SomeIPConnectionSymbol(1,2,3));
List<File> files = new ArrayList<>();
files.add(generatorSomeIP.generateCMake(componentInstanceSymbol));
testFilesAreEqual(files, "echoCMake/");
}
}
# Setting cmake version
cmake_minimum_required (VERSION 2.8)
# Using C++ with flags
set (CMAKE_CXX_FLAGS "-g -std=c++0x")
# Find vsomeip and boost packages
find_package (vsomeip 2.10.0 REQUIRED)
find_package( Boost 1.55 COMPONENTS system thread log REQUIRED )
#include vsomeip and boost directories
include_directories (
${Boost_INCLUDE_DIR}
${VSOMEIP_INCLUDE_DIRS}
)
# Linking libraries to target
add_library(SomeIPAdapter_tests_a_compA SomeIPAdapter_tests_a_compA.cpp)
target_link_libraries(SomeIPAdapter_tests_a_compA vsomeip ${Boost_LIBRARIES})
# Export target to a cmake module file for outside usage
export(TARGETS SomeIPAdapter_tests_a_compA FILE SomeIPAdapter_tests_a_compA.cmake)
Markdown is supported
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