Commit 93d97751 authored by Georg Vinogradov's avatar Georg Vinogradov

Complete CMakeLists.txt generation

parent 7d1e9dff
Pipeline #158117 passed with stages
in 3 minutes and 25 seconds
......@@ -50,5 +50,34 @@ public class GeneratorMqtt
return files;
}
File generateCMake(EMAComponentInstanceSymbol component)
{
// Create and fill model
MqttAdapterModel model = new MqttAdapterModel(component.getFullName());
//Generate files and write to project
String content = MqttTemplates.generateMqttCMakeLists(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;
}
}
......@@ -24,6 +24,14 @@ public class MqttAdapterModel {
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.mqtt.template;
public class MqttCMakeModel {
private String name;
public String getName() {
return name;
}
}
......@@ -40,7 +40,7 @@ public class MqttTemplates {
return generate(PrettyPrint, data);
}
public static String generateMqttCMakeLists(MqttCMakeModel model) {
public static String generateMqttCMakeLists(MqttAdapterModel model) {
HashMap<String, Object> data = new HashMap<>();
data.put("model", model);
return generate(MQTT_CMAKELISTS, data);
......
<#--@formatter:off-->
# Setting cmake version
cmake_minimum_required(VERSION 3.1...3.14)
if(<#noparse>${CMAKE_VERSION}</#noparse> VERSION_LESS 3.12)
......@@ -6,10 +7,10 @@ endif()
# Using C++ version 11 with threads for compiling
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "<#noparse>${CMAKE_CXX_FLAGS}<#noparse> -std=c++11 -pthread")
set(CMAKE_CXX_FLAGS "<#noparse>${CMAKE_CXX_FLAGS}</#noparse> -std=c++11 -pthread")
# Setting project name and description
project(${model.name})
project(${model.getCompName()})
set(SEARCH_MQTT FALSE)
......@@ -24,13 +25,13 @@ ELSE()
ENDIF()
# Adding library as a target
add_library(MqttAdapter_tests_a_${model.name}
add_library(MqttAdapter_${model.getEscapedCompName()}
Callback.cpp
MqttAdapter_tests_a_${model.name}.cpp
tests_a_${model.name}.cpp
MqttAdapter_${model.getEscapedCompName()}.cpp
${model.getEscapedCompName()}.cpp
Callback.hpp
MqttAdapter_tests_a_${model.name}.h
tests_a_${model.name}.h
MqttAdapter_${model.getEscapedCompName()}.h
${model.getEscapedCompName()}.h
)
# Checking if everything was found
......@@ -46,10 +47,10 @@ if(SEARCH_MQTT)
endif()
# Adding include directory to a target
target_include_directories(MqttAdapter_tests_a_${model.name} PUBLIC <#noparse>${MQTT_INCLUDE_DIR}</#noparse>)
target_include_directories(MqttAdapter_${model.getEscapedCompName()} PUBLIC <#noparse>${MQTT_INCLUDE_DIR}</#noparse>)
# Linking libraries to target
target_link_libraries(MqttAdapter_tests_a_${model.name} PUBLIC <#noparse>${MQTT_LIBS}</#noparse>)
target_link_libraries(MqttAdapter_${model.getEscapedCompName()} PUBLIC <#noparse>${MQTT_LIBS}</#noparse>)
# Export target to a cmake module file for outside usage
export(TARGETS MqttAdapter_tests_a_${model.name} FILE MqttAdapter_tests_a_${model.name}.cmake)
export(TARGETS MqttAdapter_${model.getEscapedCompName()} FILE MQTTAdapter_${model.getEscapedCompName()}.cmake)
package de.monticore.lang.monticar.generator.mqtt;
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.mqtt.MqttConnectionSymbol;
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);
GeneratorMqtt generatorMqtt = new GeneratorMqtt();
// Connect component's ports to topics
componentInstanceSymbol.getPortInstance("portA").orElse(null).setMiddlewareSymbol(new MqttConnectionSymbol("/clock"));
List<File> files = new ArrayList<>();
files.add(generatorMqtt.generateCMake(componentInstanceSymbol));
testFilesAreEqual(files, "echoCMake/");
}
}
# Setting cmake version
cmake_minimum_required(VERSION 3.1...3.14)
if(${CMAKE_VERSION} VERSION_LESS 3.12)
cmake_policy(VERSION ${CMAKE_MAJOR_VERSION}.${CMAKE_MINOR_VERSION})
endif()
# Using C++ version 11 with threads for compiling
set (CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++11 -pthread")
# Setting project name and description
project(tests.a.compA)
set(SEARCH_MQTT FALSE)
# Check is environment variable was set
IF(DEFINED ENV{MQTT_INCLUDE_DIR} AND DEFINED ENV{MQTT_LIBS})
message("...MQTT environment variables are set" )
ELSE()
message("MQTT environment variables are not defined.")
# Find mqtt packages using modules
find_package(MQTT REQUIRED)
SET(SEARCH_MQTT TRUE)
ENDIF()
# Adding library as a target
add_library(MqttAdapter_tests_a_compA
Callback.cpp
MqttAdapter_tests_a_compA.cpp
tests_a_compA.cpp
Callback.hpp
MqttAdapter_tests_a_compA.h
tests_a_compA.h
)
# Checking if everything was found
if(SEARCH_MQTT)
if (NOT MQTT_C_LIB OR NOT MQTT_A_LIB OR NOT MQTT_PP_LIB)
message(FATAL_ERROR "MQTT libraries not found!")
elseif (NOT MQTT_INCLUDE_DIR)
message(FATAL_ERROR "MQTT includes not found!")
else()
message("MQTT includes found in " ${MQTT_INCLUDE_DIR})
message("MQTT libraries found in " ${MQTT_LIBS})
endif()
endif()
# Adding include directory to a target
target_include_directories(MqttAdapter_tests_a_compA PUBLIC ${MQTT_INCLUDE_DIR})
# Linking libraries to target
target_link_libraries(MqttAdapter_tests_a_compA PUBLIC ${MQTT_LIBS})
# Export target to a cmake module file for outside usage
export(TARGETS MqttAdapter_tests_a_compA FILE MQTTAdapter_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