Commit 36e9df71 authored by Christoph Richter's avatar Christoph Richter
Browse files

Allow custom CMake commands

parent a7623b9b
......@@ -9,4 +9,5 @@
* If `isGenerateCMakeEnabled()` additionally to the C++ files _CMakeLists.txt_ is generated.
This CMake file builds a static library out of the generated components.
* Find package (https://cmake.org/cmake/help/v3.8/command/find_package.html?highlight=i) can be configured via public method `getCMakeConfig()` from the generator class. FindModule files are generated automatically which searches for header include directories and libraries at default locations.
* Example: `getCMakeConfig().addModuleDependency(new CMakeFindModule("LibName", "LibHeader.hpp", "libname", headerSearchPaths, bibrarySearchPaths, findHeaderEnabled, findLibEnabled, isRequiered));`
\ No newline at end of file
* Example: `getCMakeConfig().addModuleDependency(new CMakeFindModule("LibName", "LibHeader.hpp", "libname", headerSearchPaths, bibrarySearchPaths, findHeaderEnabled, findLibEnabled, isRequiered));`
* Additionally any CMake command can be inserted via `getCMakeConfig().addCMakeCommand("CMAKE_CXX_FLAGS \"${CMAKE_CXX_FLAGS} -Wno-deprecated\"")`or at the end via `addCMakeCommandEnd("#some command at the end")`
\ No newline at end of file
......@@ -8,7 +8,7 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-generator</artifactId>
<version>0.0.22-SNAPSHOT</version>
<version>0.0.23-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
......@@ -21,8 +21,8 @@
<Common-MontiCar.version>0.0.14-SNAPSHOT</Common-MontiCar.version>
<Embedded-MontiArc.version>0.0.18-SNAPSHOT</Embedded-MontiArc.version>
<Embedded-MontiArc-Behaviour.version>0.0.14-SNAPSHOT</Embedded-MontiArc-Behaviour.version>
<Math.version>0.0.18-SNAPSHOT</Math.version>
<Embedded-MontiArc-Math.version>0.0.19-SNAPSHOT</Embedded-MontiArc-Math.version>
<Math.version>0.0.19-SNAPSHOT</Math.version>
<Embedded-MontiArc-Math.version>0.0.20-SNAPSHOT</Embedded-MontiArc-Math.version>
<tagging.version>0.0.4</tagging.version>
<!-- .. Libraries .................................................. -->
<guava.version>18.0</guava.version>
......
......@@ -51,6 +51,10 @@ public class CMakeConfig {
private HashSet<CMakeFindModule> moduleList = new HashSet<>();
private List<String> cmakeCommandList = new ArrayList<>();
private List<String> cmakeCommandListEnd = new ArrayList<>();
// constructor
public CMakeConfig(String compName) {
cMakeListsViewModel.setCompName(compName);
......@@ -59,7 +63,8 @@ public class CMakeConfig {
// methods
protected void configureCMakeListsViewModel() {
// nothing here
cMakeListsViewModel.setCmakeCommandList(cmakeCommandList);
cMakeListsViewModel.setCmakeCommandListEnd(cmakeCommandListEnd);
}
public List<FileContent> generateCMakeFiles() {
......@@ -111,4 +116,24 @@ public class CMakeConfig {
public CMakeListsCPPViewModel getCMakeListsViewModel() {
return cMakeListsViewModel;
}
/**
* Adds an arbitrary cmake command before target settings
*
* @param cmd some valid cmake command as string
*/
public void addCMakeCommand(String cmd) {
cmakeCommandList.add(cmd);
}
/**
* Adds an arbitrary cmake command at the end of the file
*
* @param cmd some valid cmake command as string
*/
public void addCMakeCommandEnd(String cmd) {
cmakeCommandListEnd.add(cmd);
}
}
......@@ -2,7 +2,9 @@ package de.monticore.lang.monticar.generator.cmake;
import de.monticore.lang.monticar.generator.cpp.viewmodel.ViewModelBase;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
/**
* View model which is used by the freemarker template
......@@ -19,6 +21,10 @@ public class CMakeListsCPPViewModel extends ViewModelBase {
private HashSet<CMakeFindModule> moduleDependencies;
private List<String> cmakeCommandList = new ArrayList<>();
private List<String> cmakeCommandListEnd = new ArrayList<>();
// methods
public String getCompName() {
......@@ -36,4 +42,20 @@ public class CMakeListsCPPViewModel extends ViewModelBase {
public void setModuleDependencies(HashSet<CMakeFindModule> moduleDependencies) {
this.moduleDependencies = moduleDependencies;
}
public List<String> getCmakeCommandList() {
return cmakeCommandList;
}
public void setCmakeCommandList(List<String> cmakeCommandList) {
this.cmakeCommandList = cmakeCommandList;
}
public List<String> getCmakeCommandListEnd() {
return cmakeCommandListEnd;
}
public void setCmakeCommandListEnd(List<String> cmakeCommandListEnd) {
this.cmakeCommandListEnd = cmakeCommandListEnd;
}
}
......@@ -13,6 +13,11 @@ find_package(${var.packageName} <#if var.required>REQUIRED<#else>OPTIONAL</#if>)
<#if var.findLibrary>set(LIBS ${r"${LIBS}"} ${r"${"}${var.packageName}${r"_LIBRARIES}"})</#if>
</#list>
# additional commands
<#list viewModel.cmakeCommandList as cmd>
${cmd}
</#list>
# create static library
include_directories(${r"${INCLUDE_DIRS}"})
add_library(${viewModel.compName} ${viewModel.compName}.h)
......@@ -22,3 +27,8 @@ set_target_properties(${viewModel.compName} PROPERTIES LINKER_LANGUAGE CXX)
# export cmake project
export(TARGETS ${viewModel.compName} FILE ${viewModel.compName}.cmake)
# additional commands end
<#list viewModel.cmakeCommandListEnd as cmd>
${cmd}
</#list>
......@@ -11,6 +11,8 @@ find_package(Armadillo REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
# additional commands
# create static library
include_directories(${INCLUDE_DIRS})
add_library(test_basicConstantAssignment test_basicConstantAssignment.h)
......@@ -20,3 +22,5 @@ set_target_properties(test_basicConstantAssignment PROPERTIES LINKER_LANGUAGE CX
# export cmake project
export(TARGETS test_basicConstantAssignment FILE test_basicConstantAssignment.cmake)
# additional commands end
......@@ -11,6 +11,8 @@ find_package(Armadillo REQUIRED)
set(INCLUDE_DIRS ${INCLUDE_DIRS} ${Armadillo_INCLUDE_DIRS})
set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
# additional commands
# create static library
include_directories(${INCLUDE_DIRS})
add_library(testing_model testing_model.h)
......@@ -20,3 +22,5 @@ set_target_properties(testing_model PROPERTIES LINKER_LANGUAGE CXX)
# export cmake project
export(TARGETS testing_model FILE testing_model.cmake)
# additional commands end
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