Commit be5f5860 authored by Evgeny Kusmenko's avatar Evgeny Kusmenko
Browse files

Merge branch 'MsBuildFix' into 'master'

Ms build fix

See merge request !27
parents 14784b20 b70e356e
Pipeline #100940 passed with stages
in 45 minutes and 40 seconds
......@@ -4,10 +4,10 @@
# EMAM2Cpp
##CMake Generation:
## CMake Generation:
* Available since version 0.0.22-SNAPSHOT.
###Interface in Java Code
### Interface in Java Code
* 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.
......
......@@ -30,7 +30,7 @@
<groupId>de.monticore.lang.monticar</groupId>
<artifactId>embedded-montiarc-math-generator</artifactId>
<version>0.1.4-SNAPSHOT</version>
<version>0.1.5-SNAPSHOT</version>
<!-- == PROJECT DEPENDENCIES ============================================= -->
......@@ -47,7 +47,7 @@
<!--<Embedded-MontiArc-Math.version>0.0.19-SNAPSHOT</Embedded-MontiArc-Math.version>-->
<!--<tagging.version>0.0.4</tagging.version>-->
<Embedded-MontiArc-Math.version>0.1.5-SNAPSHOT</Embedded-MontiArc-Math.version>
<Embedded-MontiArc-Math.version>0.1.7-SNAPSHOT</Embedded-MontiArc-Math.version>
<!-- .. Libraries .................................................. -->
<guava.version>18.0</guava.version>
......
......@@ -91,6 +91,8 @@ public class CMakeConfig {
List<FileContent> files = new ArrayList<FileContent>();
// generate CMakeLists.txt
files.add(generateCMakeLists());
// generate ${component.name}.cpp
files.add(generateComponentCpp());
// generate FindModule.cmake's
for (CMakeFindModule module : moduleList) {
files.add(generateCMakeFindPackage(module));
......@@ -98,6 +100,14 @@ public class CMakeConfig {
return files;
}
private FileContent generateComponentCpp() {
FileContent result = new FileContent();
String compName = cMakeListsViewModel.getCompName().replace(".", "_");
result.setFileName(compName + ".cpp");
result.setFileContent("#include \""+ compName +".h\"");
return result;
}
private FileContent generateCMakeFindPackage(CMakeFindModule module) {
FileContent result = null;
// map data
......
......@@ -28,12 +28,16 @@ import de.monticore.lang.monticar.generator.FileContent;
public class ArmadilloHelper {
public static String fileName = "HelperA";
public static FileContent getArmadilloHelperFileContent() {
public static FileContent getArmadilloHelperFileContent(boolean generateTests) {
FileContent fileContent = new FileContent();
fileContent.setFileName(fileName + ".h");
String fileContentString = ArmadilloHelperSource.armadilloHelperSourceCode;
String fileContentString = generateTests ? ArmadilloHelperSource.armadilloHelperSourceCodeWithTests : ArmadilloHelperSource.armadilloHelperSourceCode;
fileContent.setFileContent(fileContentString);
return fileContent;
}
public static FileContent getArmadilloHelperFileContent(){
return getArmadilloHelperFileContent(false);
}
}
......@@ -24,7 +24,7 @@ package de.monticore.lang.monticar.generator.cpp;
* @author Sascha Schneiders
*/
public class ArmadilloHelperSource {
public static String armadilloHelperSourceCode = "#ifndef HELPERA_H\n" +
public static String armadilloHelperSourceCodeWithTests = "#ifndef HELPERA_H\n" +
"#define HELPERA_H\n" +
"#include <iostream>\n" +
"#include \"armadillo.h\"\n" +
......@@ -180,4 +180,146 @@ public class ArmadilloHelperSource {
"}\n" +
"};\n" +
"#endif\n";
public static String armadilloHelperSourceCode = "#ifndef HELPERA_H\n" +
"#define HELPERA_H\n" +
"#include <iostream>\n" +
"#include \"armadillo.h\"\n" +
"#include <stdarg.h>\n" +
"#include <initializer_list>\n" +
"#include <fstream>\n" +
"using namespace arma;\n" +
"#ifndef _FILESTRING_CONVERSION___A\n" +
"#define _FILESTRING_CONVERSION___A\n" +
"void toFileString(std::ofstream& myfile, mat A){\n" +
" myfile << \"[\";\n" +
" for (int i = 0; i < A.n_rows; i++){\n" +
" for (int j = 0; j < A.n_cols; j++){\n" +
" myfile << A(i,j);\n" +
" if(j + 1 < A.n_cols){\n" +
" myfile << \", \";\n" +
" }\n" +
" }\n" +
" if(i + 1 < A.n_rows){\n" +
" myfile << \";\";\n" +
" }\n" +
" }\n" +
" myfile << \"]\";\n" +
"}\n" +
"void toFileString(std::ofstream& myfile, double A){\n" +
" myfile << A;\n" +
"}\n" +
"void toFileString(std::ofstream& myfile, float A){\n" +
" myfile << A;\n" +
"}\n" +
"void toFileString(std::ofstream& myfile, int A){\n" +
" myfile << A;\n" +
"}\n" +
"void toFileString(std::ofstream& myfile, bool A){\n" +
" myfile << A;\n" +
"}\n" +
"bool Is_close(mat& X, mat& Y, double tol)\n" +
"{\n" +
" // abs returns a mat type then max checks columns and returns a row_vec\n" +
" // max used again will return the biggest element in the row_vec\n" +
" bool close(false);\n" +
" if(arma::max(arma::max(arma::abs(X-Y))) < tol)\n" +
" {\n" +
" close = true;\n" +
" }\n" +
" return close;\n" +
"}\n" +
"#endif\n" +
"class HelperA{\n" +
"public:\n" +
"static mat getEigenVectors(mat A){\n" +
"vec eigenValues;\n" +
"mat eigenVectors;\n" +
"eig_sym(eigenValues,eigenVectors,A);\n" +
"return eigenVectors;\n" +
"}\n" +
"static vec getEigenValues(mat A){\n" +
"vec eigenValues;\n" +
"mat eigenVectors;\n" +
"eig_sym(eigenValues,eigenVectors,A);\n" +
"return eigenValues;\n" +
"}\n" +
"\n" +
"static mat getKMeansClusters(mat A, int k){\n" +
"mat clusters;\n" +
"kmeans(clusters,A.t(),k,random_subset,20,true);\n" +
"/*printf(\"cluster centroid calculation done\\n\");\n" +
"std::ofstream myfile;\n" +
" myfile.open(\"data after cluster.txt\");\n" +
" myfile << A;\n" +
" myfile.close();\n" +
"\t \n" +
"\t std::ofstream myfile2;\n" +
" myfile2.open(\"cluster centroids.txt\");\n" +
" myfile2 << clusters;\n" +
" myfile2.close();*/\n" +
"mat indexedData=getKMeansClustersIndexData(A.t(), clusters);\n" +
"\n" +
"/*std::ofstream myfile3;\n" +
" myfile3.open(\"data after index.txt\");\n" +
" myfile3 << indexedData;\n" +
" myfile3.close();\n" +
"\t */\n" +
"return indexedData;\n" +
"}\n" +
"\n" +
"static mat getKMeansClustersIndexData(mat A, mat centroids){\n" +
"\tmat result=mat(A.n_cols, 1);\n" +
"\tfor(int i=0;i<A.n_cols;++i){\n" +
"\t\tresult(i, 0) = getIndexForClusterCentroids(A, i, centroids);\n" +
"\t}\n" +
"\treturn result;\n" +
"}\n" +
"\n" +
"static int getIndexForClusterCentroids(mat A, int colIndex, mat centroids){\n" +
"\tint index=1;\n" +
"\tdouble lowestDistance=getEuclideanDistance(A, colIndex, centroids, 0);\n" +
"\tfor(int i=1;i<centroids.n_cols;++i){\n" +
"\t\tdouble curDistance=getEuclideanDistance(A, colIndex, centroids, i);\n" +
"\t\tif(curDistance<lowestDistance){\n" +
"\t\t\tlowestDistance=curDistance;\n" +
"\t\t\tindex=i+1;\n" +
"\t\t}\n" +
"\t}\n" +
"\treturn index;\n" +
"}\n" +
"\n" +
"static double getEuclideanDistance(mat A, int colIndexA, mat B, int colIndexB){\n" +
"\tdouble distance=0;\n" +
"\tfor(int i=0;i<A.n_rows;++i){\n" +
"\t\tdouble elementA=A(i,colIndexA);\n" +
"\t\tdouble elementB=B(i,colIndexB);\n" +
"\t\tdouble diff=elementA-elementB;\n" +
"\t\tdistance+=diff*diff;\n" +
"\t}\n" +
"\treturn sqrt(distance);\n" +
"}\n" +
"\n" +
"static mat getSqrtMat(mat A){\n" +
" cx_mat result=sqrtmat(A);\n" +
" return real(result);\n" +
"}\n" +
"\n" +
"static mat getSqrtMatDiag(mat A){\n" +
"for(int i=0;i<A.n_rows;++i){\n" +
" double curVal = A(i,i);\n" +
" A(i,i) = sqrt(curVal);\n" +
"}\n" +
"return A;\n" +
"}\n" +
"\n" +
"static mat invertDiagMatrix(mat A){\n" +
"for(int i=0;i<A.n_rows;++i){\n" +
" double curVal = A(i,i);\n" +
" A(i,i) = 1/curVal;\n" +
"}\n" +
"return A;\n" +
"}\n" +
"};\n" +
"#endif\n";
}
......@@ -224,7 +224,7 @@ public class GeneratorCPP implements Generator {
if (MathConverter.curBackend.getBackendName().equals("OctaveBackend"))
fileContents.add(OctaveHelper.getOctaveHelperFileContent());
if (MathConverter.curBackend.getBackendName().equals("ArmadilloBackend"))
fileContents.add(ArmadilloHelper.getArmadilloHelperFileContent());
fileContents.add(ArmadilloHelper.getArmadilloHelperFileContent(isGenerateTests));
if (shouldGenerateMainClass()) {
//fileContents.add(getMainClassFileContent(componentInstanceSymbol, fileContents.get(0)));
......@@ -235,7 +235,7 @@ public class GeneratorCPP implements Generator {
if (MathConverter.curBackend.getBackendName().equals("OctaveBackend"))
fileContents.add(OctaveHelper.getOctaveHelperFileContent());
if (MathConverter.curBackend.getBackendName().equals("ArmadilloBackend"))
fileContents.add(ArmadilloHelper.getArmadilloHelperFileContent());
fileContents.add(ArmadilloHelper.getArmadilloHelperFileContent(isGenerateTests));
if(componentInstanceSymbol instanceof EMADynamicComponentInstanceSymbol){
//TODO: add Events Value Helper
......
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
project(${viewModel.compName} LANGUAGES CXX)
......@@ -20,7 +20,7 @@ ${cmd}
# create static library
include_directories(${r"${INCLUDE_DIRS}"})
add_library(${viewModel.compName} ${viewModel.compName}.h)
add_library(${viewModel.compName} ${viewModel.compName}.cpp)
target_include_directories(${viewModel.compName} PUBLIC ${r"${CMAKE_CURRENT_SOURCE_DIR}"} ${r"${INCLUDE_DIRS}"})
target_link_libraries(${viewModel.compName} PUBLIC ${r"${LIBS}"})
set_target_properties(${viewModel.compName} PROPERTIES LINKER_LANGUAGE CXX)
......
......@@ -101,7 +101,7 @@ public class GenerateCMakeTest extends AbstractSymtabTest {
for (File f : files) {
if (f.getName().startsWith("Find"))
findFiles.add(f);
else if (f.getName().endsWith(".hpp") || f.getName().endsWith(".cpp"))
else if (f.getName().endsWith(".hpp") || f.getName().endsWith("tests_main.cpp"))
testFiles.add(f);
else if (f.toPath().getParent().endsWith("reporting")) {
//don't care about reporting files
......
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
project(test_basicConstantAssignment LANGUAGES CXX)
......@@ -15,7 +15,7 @@ set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
# create static library
include_directories(${INCLUDE_DIRS})
add_library(test_basicConstantAssignment test_basicConstantAssignment.h)
add_library(test_basicConstantAssignment test_basicConstantAssignment.cpp)
target_include_directories(test_basicConstantAssignment PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIRS})
target_link_libraries(test_basicConstantAssignment PUBLIC ${LIBS})
set_target_properties(test_basicConstantAssignment PROPERTIES LINKER_LANGUAGE CXX)
......
#include "test_basicConstantAssignment.h"
\ No newline at end of file
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
project(test_basicPortsMath LANGUAGES CXX)
......@@ -15,7 +15,7 @@ set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
# create static library
include_directories(${INCLUDE_DIRS})
add_library(test_basicPortsMath test_basicPortsMath.h)
add_library(test_basicPortsMath test_basicPortsMath.cpp)
target_include_directories(test_basicPortsMath PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIRS})
target_link_libraries(test_basicPortsMath PUBLIC ${LIBS})
set_target_properties(test_basicPortsMath PROPERTIES LINKER_LANGUAGE CXX)
......
#include "test_basicPortsMath.h"
\ No newline at end of file
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
project(test_math_floatDivisionTest LANGUAGES CXX)
......@@ -15,7 +15,7 @@ set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
# create static library
include_directories(${INCLUDE_DIRS})
add_library(test_math_floatDivisionTest test_math_floatDivisionTest.h)
add_library(test_math_floatDivisionTest test_math_floatDivisionTest.cpp)
target_include_directories(test_math_floatDivisionTest PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIRS})
target_link_libraries(test_math_floatDivisionTest PUBLIC ${LIBS})
set_target_properties(test_math_floatDivisionTest PROPERTIES LINKER_LANGUAGE CXX)
......
#include "test_math_floatDivisionTest.h"
\ No newline at end of file
cmake_minimum_required(VERSION 3.5)
set(CMAKE_CXX_STANDARD 11)
set(CMAKE_CXX_STANDARD 14)
project(testing_model LANGUAGES CXX)
......@@ -15,7 +15,7 @@ set(LIBS ${LIBS} ${Armadillo_LIBRARIES})
# create static library
include_directories(${INCLUDE_DIRS})
add_library(testing_model testing_model.h)
add_library(testing_model testing_model.cpp)
target_include_directories(testing_model PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${INCLUDE_DIRS})
target_link_libraries(testing_model PUBLIC ${LIBS})
set_target_properties(testing_model PROPERTIES LINKER_LANGUAGE CXX)
......
#include "testing_model.h"
\ No newline at end of file
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