Commit b896d11a authored by Malte Heithoff's avatar Malte Heithoff
Browse files

Cmake Find Package

parent 0163b2c1
......@@ -22,7 +22,6 @@ import java.util.Map;
* Is responsible for generating the cmake files from freemarker templates.
* CMake dependencies to other modules can be added as Find Package file.
* See also https://cmake.org/cmake/help/v3.8/command/find_package.html?highlight=i
*
*/
public class CMakeConfig {
......@@ -55,7 +54,9 @@ public class CMakeConfig {
private List<String> cmakeCommandListEnd = new ArrayList<>();
private List<String> cmakeLibraryLinkage = new ArrayList<>();
private List<String> cmakeLibraryLinkageList = new ArrayList<>();
private List<String> cmakeFindPackageList = new ArrayList<>();
// constructor
public CMakeConfig(String compName) {
......@@ -65,9 +66,10 @@ public class CMakeConfig {
// methods
protected void configureCMakeListsViewModel() {
cMakeListsViewModel.setCmakeLibraryLinkageList(cmakeLibraryLinkage);
cMakeListsViewModel.setCmakeLibraryLinkageList(cmakeLibraryLinkageList);
cMakeListsViewModel.setCmakeCommandList(cmakeCommandList);
cMakeListsViewModel.setCmakeCommandListEnd(cmakeCommandListEnd);
cMakeListsViewModel.setCmakeFindPackageList(cmakeFindPackageList);
}
public List<FileContent> generateCMakeFiles() {
......@@ -87,7 +89,7 @@ public class CMakeConfig {
FileContent result = new FileContent();
String compName = cMakeListsViewModel.getCompName().replace(".", "_");
result.setFileName(compName + ".cpp");
result.setFileContent("#include \""+ compName +".h\"");
result.setFileContent("#include \"" + compName + ".h\"");
return result;
}
......@@ -123,7 +125,8 @@ public class CMakeConfig {
}
public void addModuleDependency(CMakeFindModule module) {
moduleList.add(module);
if (!moduleList.contains(module))
moduleList.add(module);
}
public CMakeListsCPPViewModel getCMakeListsViewModel() {
......@@ -136,7 +139,8 @@ public class CMakeConfig {
* @param cmd some valid cmake command as string
*/
public void addCMakeCommand(String cmd) {
cmakeCommandList.add(cmd);
if (!cmakeCommandList.contains(cmd))
cmakeCommandList.add(cmd);
}
/**
......@@ -145,11 +149,20 @@ public class CMakeConfig {
* @param cmd some valid cmake command as string
*/
public void addCMakeCommandEnd(String cmd) {
cmakeCommandListEnd.add(cmd);
if (!cmakeCommandListEnd.contains(cmd))
cmakeCommandListEnd.add(cmd);
}
public void addCmakeLibraryLinkage(String cmakeLibraryLinkage) {
this.cmakeLibraryLinkage.add(cmakeLibraryLinkage);
if (!cmakeLibraryLinkageList.contains(cmakeLibraryLinkage))
this.cmakeLibraryLinkageList.add(cmakeLibraryLinkage);
}
public void addFindPackage(String packageName) {
if (!cmakeFindPackageList.contains(packageName))
cmakeFindPackageList.add(packageName);
}
}
......@@ -5,6 +5,7 @@ import de.monticore.lang.monticar.generator.cpp.viewmodel.ViewModelBase;
import java.util.ArrayList;
import java.util.List;
import java.util.Objects;
/**
* Representation of CMake Find files as Java class.
......@@ -126,4 +127,24 @@ public class CMakeFindModule extends ViewModelBase {
this.fortranQuadMath = fortranQuadMath;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (!(o instanceof CMakeFindModule)) return false;
CMakeFindModule that = (CMakeFindModule) o;
return isRequired() == that.isRequired() &&
Objects.equals(getPackageName(), that.getPackageName()) &&
Objects.equals(getIncludeName(), that.getIncludeName()) &&
Objects.equals(getLibName(), that.getLibName()) &&
Objects.equals(getIncludePaths(), that.getIncludePaths()) &&
Objects.equals(getLibPaths(), that.getLibPaths()) &&
Objects.equals(getFindPath(), that.getFindPath()) &&
Objects.equals(getFindLibrary(), that.getFindLibrary()) &&
Objects.equals(getFortranQuadMath(), that.getFortranQuadMath());
}
@Override
public int hashCode() {
return Objects.hash(getPackageName(), getIncludeName(), getLibName(), getIncludePaths(), getLibPaths(), getFindPath(), getFindLibrary(), getFortranQuadMath(), isRequired());
}
}
......@@ -27,6 +27,8 @@ public class CMakeListsCPPViewModel extends ViewModelBase {
private List<String> cmakeLibraryLinkageList = new ArrayList<>();
private List<String> cmakeFindPackageList = new ArrayList<>();
// methods
public String getCompName() {
......@@ -68,4 +70,12 @@ public class CMakeListsCPPViewModel extends ViewModelBase {
public void setCmakeLibraryLinkageList(List<String> cmakeLibraryLinkageList) {
this.cmakeLibraryLinkageList = cmakeLibraryLinkageList;
}
public List<String> getCmakeFindPackageList() {
return cmakeFindPackageList;
}
public void setCmakeFindPackageList(List<String> cmakeFindPackageList) {
this.cmakeFindPackageList = cmakeFindPackageList;
}
}
......@@ -14,6 +14,11 @@ find_package(${var.packageName} <#if var.required>REQUIRED<#else></#if>)
<#if var.findLibrary>set(LIBS ${r"${LIBS}"} ${r"${"}${var.packageName}${r"_LIBRARIES}"})</#if>
<#if var.fortranQuadMath>set(LIBS ${r"${LIBS}"} "quadmath")</#if>
</#list>
<#list viewModel.cmakeFindPackageList as cmd>
find_package(${cmd} REQUIRED)
set(INCLUDE_DIRS ${r"${INCLUDE_DIRS}"} ${r"${"}${cmd}${r"_INCLUDE_DIRSr}"})
set(LIBS ${r"${LIBS}"} ${r"${"}${cmd}${r"_LIBS}"})
</#list>
# additional library linkage
<#list viewModel.cmakeLibraryLinkageList as cmd>
......
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