diff --git a/OMCompiler/Compiler/Script/CevalScriptBackend.mo b/OMCompiler/Compiler/Script/CevalScriptBackend.mo index fd4c379b09a..018a3ee2bf6 100644 --- a/OMCompiler/Compiler/Script/CevalScriptBackend.mo +++ b/OMCompiler/Compiler/Script/CevalScriptBackend.mo @@ -121,6 +121,7 @@ import SCodeUtil; import SemanticVersion; import Settings; import SimCodeMain; +import SimCodeFunctionUtil; import SimpleModelicaParser; import SimulationResults; import StaticScript; @@ -3473,6 +3474,22 @@ algorithm className, inFileNamePrefix, runBackend, Flags.getConfigBool(Flags.DAE_MODE), runSilent, inSimSettingsOpt, Absyn.FUNCTIONARGS({},{})); end callTranslateModel; +protected function getProcsStr + input Boolean isMake = false; + output String s; +protected + Integer n; + String sn; +algorithm + n := Flags.getConfigInt(Flags.NUM_PROC); + sn := intString(n); + s := if (n == 0) + then "" + else (if isMake + then sn + else stringAppend("-j", sn)); +end getProcsStr; + protected function configureFMU_cmake "Configure and build binaries with CMake for target platform" input String platform; @@ -3485,10 +3502,15 @@ protected String fmuSourceDir; String CMAKE_GENERATOR = "", CMAKE_BUILD_TYPE; String quote, dquote, defaultFmiIncludeDirectoy; + String CC, CXX; + SimCodeFunction.MakefileParams makefileParams; algorithm + makefileParams := SimCodeFunctionUtil.createMakefileParams({}, {}, {}, false, true); fmuSourceDir := fmutmp+"/sources/"; quote := "'"; dquote := if isWindows then "\"" else "'"; + CC := "-DCMAKE_C_COMPILER=" + dquote + makefileParams.ccompiler + dquote; + CXX := "-DCMAKE_CXX_COMPILER=" + dquote + makefileParams.cxxcompiler + dquote; defaultFmiIncludeDirectoy := dquote + Settings.getInstallationDirectoryPath() + "/include/omc/c/fmi" + dquote; // Set build type @@ -3522,15 +3544,15 @@ algorithm end if; buildDir := "build_cmake_dynamic"; cmakeCall := Autoconf.cmake + " " + CMAKE_GENERATOR + - CMAKE_BUILD_TYPE + + CMAKE_BUILD_TYPE + " " + CC + " " + CXX + " .."; cmd := "cd " + dquote + fmuSourceDir + dquote + " && " + "mkdir " + buildDir + " && cd " + buildDir + " && " + cmakeCall + " && " + - Autoconf.cmake + " --build . --target install && " + + Autoconf.cmake + " --build . --parallel " + getProcsStr() + " --target install && " + "cd .. && rm -rf " + buildDir; if 0 <> System.systemCall(cmd, outFile=logfile) then - Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {System.readFile(logfile)}); + Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {"cmd: " + cmd + "\n" + System.readFile(logfile)}); fail(); end if; then(); @@ -3541,15 +3563,15 @@ algorithm end if; buildDir := "build_cmake_dynamic"; cmakeCall := Autoconf.cmake + " " + CMAKE_GENERATOR + - CMAKE_BUILD_TYPE + + CMAKE_BUILD_TYPE + " " + CC + " " + CXX + " .."; cmd := "cd " + dquote + fmuSourceDir + dquote + " && " + "mkdir " + buildDir + " && cd " + buildDir + " && " + cmakeCall + " && " + - Autoconf.cmake + " --build . --target install && " + + Autoconf.cmake + " --build . --parallel " + getProcsStr() + " --target install && " + "cd .. && rm -rf " + buildDir; if 0 <> System.systemCall(cmd, outFile=logfile) then - Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {System.readFile(logfile)}); + Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {"cmd: " + cmd + "\n" + System.readFile(logfile)}); fail(); end if; then(); @@ -3621,7 +3643,7 @@ algorithm "cd " + dquote + "/fmu/" + fmuSourceDir + dquote + " && " + "mkdir " + buildDir + " && cd " + buildDir + " && " + cmakeCall + " && " + - "cmake --build . && make install && " + + "cmake --build . && make " + getProcsStr(true) + " install && " + "cd .. && rm -rf " + buildDir + dquote; runDockerCmd(cmd, dockerLogFile, cleanup=true, volumeID=volumeID, containerID=containerID); @@ -3979,8 +4001,8 @@ algorithm // NOTE: The FMUs use fileNamePrefix for the internal name when it would be expected to be fileNamePrefix that decides the .fmu filename // The scripting environment from a user's perspective is like that. fmuTargetName is the name of the .fmu in the templates, etc. - filenameprefix := Util.stringReplaceChar(if inFileNamePrefix == "" then AbsynUtil.pathString(className) else inFileNamePrefix, ".", "_"); - fmuTargetName := if FMUVersion == "1.0" then filenameprefix else (if inFileNamePrefix == "" then AbsynUtil.pathString(className) else inFileNamePrefix); + filenameprefix := Util.stringReplaceChar(if inFileNamePrefix == "" then AbsynUtil.pathLastIdent(className) else inFileNamePrefix, ".", "_"); + fmuTargetName := if FMUVersion == "1.0" then filenameprefix else (if inFileNamePrefix == "" then AbsynUtil.pathLastIdent(className) else inFileNamePrefix); if isSome(inSimSettings) then SOME(simSettings) := inSimSettings; else diff --git a/testsuite/omsimulator/DualMassOscillator_cs.mos b/testsuite/omsimulator/DualMassOscillator_cs.mos index a3171afa4f2..332c26c2230 100644 --- a/testsuite/omsimulator/DualMassOscillator_cs.mos +++ b/testsuite/omsimulator/DualMassOscillator_cs.mos @@ -4,8 +4,8 @@ loadFile("DualMassOscillator.mo"); getErrorString(); -buildModelFMU(DualMassOscillator.System1, version="2.0", fmuType="cs", platforms={"static"}); getErrorString(); -buildModelFMU(DualMassOscillator.System2, version="2.0", fmuType="cs", platforms={"static"}); getErrorString(); +buildModelFMU(DualMassOscillator.System1, version="2.0", fmuType="cs", fileNamePrefix="DualMassOscillator.System1", platforms={"static"}); getErrorString(); +buildModelFMU(DualMassOscillator.System2, version="2.0", fmuType="cs", fileNamePrefix="DualMassOscillator.System2", platforms={"static"}); getErrorString(); writeFile("DualMassOscillator_cs.lua", " oms_setCommandLineOption(\"--suppressPath=true\") diff --git a/testsuite/omsimulator/DualMassOscillator_me.mos b/testsuite/omsimulator/DualMassOscillator_me.mos index 1c6e4b31fad..a03a2f1d17d 100644 --- a/testsuite/omsimulator/DualMassOscillator_me.mos +++ b/testsuite/omsimulator/DualMassOscillator_me.mos @@ -4,8 +4,8 @@ loadFile("DualMassOscillator.mo"); getErrorString(); -buildModelFMU(DualMassOscillator.System1, version="2.0", fmuType="me", platforms={"static"}); getErrorString(); -buildModelFMU(DualMassOscillator.System2, version="2.0", fmuType="me", platforms={"static"}); getErrorString(); +buildModelFMU(DualMassOscillator.System1, version="2.0", fmuType="me", fileNamePrefix="DualMassOscillator.System1", platforms={"static"}); getErrorString(); +buildModelFMU(DualMassOscillator.System2, version="2.0", fmuType="me", fileNamePrefix="DualMassOscillator.System2", platforms={"static"}); getErrorString(); writeFile("DualMassOscillator_me.lua", " oms_setCommandLineOption(\"--suppressPath=true\") diff --git a/testsuite/omsimulator/Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum.mos b/testsuite/omsimulator/Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum.mos index 150e3bc520a..2052e6950e7 100644 --- a/testsuite/omsimulator/Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum.mos +++ b/testsuite/omsimulator/Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum.mos @@ -3,7 +3,7 @@ // teardown_command: rm -rf Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum.fmu Modelica_Mechanics_MultiBody_Examples_Elementary_Pendulum.log Pendulum_systemCall.log modelDescription.xml model_res.mat loadModel(Modelica); getErrorString(); -buildModelFMU(Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum, version="2.0", fmuType="me_cs", platforms={"static"}); getErrorString(); +buildModelFMU(Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum, version="2.0", fmuType="me_cs", fileNamePrefix="Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum", platforms={"static"}); getErrorString(); system(getInstallationDirectoryPath() + "/bin/OMSimulator Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum.fmu", "Pendulum_systemCall.log"); readFile("Pendulum_systemCall.log"); diff --git a/testsuite/omsimulator/cmakeFMU.mos b/testsuite/omsimulator/cmakeFMU.mos index 0ca5d3f28e5..585413e236c 100644 --- a/testsuite/omsimulator/cmakeFMU.mos +++ b/testsuite/omsimulator/cmakeFMU.mos @@ -4,7 +4,7 @@ // teardown_command: rm -rf DualMassOscillator.System1.fmu DualMassOscillator.System1_FMU* DualMassOscillator_System1_systemCall.log loadFile("DualMassOscillator.mo"); getErrorString(); -buildModelFMU(DualMassOscillator.System1, platforms={"dynamic"}); getErrorString(); +buildModelFMU(DualMassOscillator.System1, fileNamePrefix="DualMassOscillator.System1", platforms={"dynamic"}); getErrorString(); system(getInstallationDirectoryPath() + "/bin/OMSimulator DualMassOscillator.System1.fmu", "DualMassOscillator_System1_systemCall.log"); readFile("DualMassOscillator_System1_systemCall.log"); diff --git a/testsuite/omsimulator/resetWithLoops.mos b/testsuite/omsimulator/resetWithLoops.mos index bce22ba8fb6..53c2ce26e5c 100644 --- a/testsuite/omsimulator/resetWithLoops.mos +++ b/testsuite/omsimulator/resetWithLoops.mos @@ -6,7 +6,7 @@ loadModel(Modelica, {"3.2.3"}); getErrorString(); system("mkdir -p resetWithLoops-fmu"); echo(false); cd("resetWithLoops-fmu"); echo(true); -buildModelFMU(Modelica.Electrical.Analog.Examples.Rectifier); getErrorString(); +buildModelFMU(Modelica.Electrical.Analog.Examples.Rectifier, fileNamePrefix="Modelica.Electrical.Analog.Examples.Rectifier"); getErrorString(); echo(false); cd(".."); echo(true); writeFile("resetWithLoops.lua"," diff --git a/testsuite/omsimulator/testDirectionalDerivatives.mos b/testsuite/omsimulator/testDirectionalDerivatives.mos index 31ff3a8d02f..c6439525112 100644 --- a/testsuite/omsimulator/testDirectionalDerivatives.mos +++ b/testsuite/omsimulator/testDirectionalDerivatives.mos @@ -12,7 +12,7 @@ setCommandLineOptions("-d=newInst,-disableDirectionalDerivatives"); getErrorString(); // Build 2.0 FMU -buildModelFMU(Modelica.Electrical.Analog.Examples.CauerLowPassAnalog, version="2.0", fmuType="me_cs", platforms={"static"}); +buildModelFMU(Modelica.Electrical.Analog.Examples.CauerLowPassAnalog, version="2.0", fmuType="me_cs", fileNamePrefix="Modelica.Electrical.Analog.Examples.CauerLowPassAnalog", platforms={"static"}); getErrorString(); // Simulate with OMSimulator diff --git a/testsuite/omsimulator/testLoopsOverFMUs.mos b/testsuite/omsimulator/testLoopsOverFMUs.mos index 1e0f7feba68..a07e3b808df 100644 --- a/testsuite/omsimulator/testLoopsOverFMUs.mos +++ b/testsuite/omsimulator/testLoopsOverFMUs.mos @@ -55,10 +55,10 @@ package loopsOverFMUs end loopsOverFMUs; "); getErrorString(); -buildModelFMU(loopsOverFMUs.A, fmuType="me"); -buildModelFMU(loopsOverFMUs.B, fmuType="me"); -buildModelFMU(loopsOverFMUs.C, fmuType="me"); -buildModelFMU(loopsOverFMUs.D, fmuType="me"); +buildModelFMU(loopsOverFMUs.A, fmuType="me", fileNamePrefix="loopsOverFMUs.A"); +buildModelFMU(loopsOverFMUs.B, fmuType="me", fileNamePrefix="loopsOverFMUs.B"); +buildModelFMU(loopsOverFMUs.C, fmuType="me", fileNamePrefix="loopsOverFMUs.C"); +buildModelFMU(loopsOverFMUs.D, fmuType="me", fileNamePrefix="loopsOverFMUs.D"); writeFile("loopsOverFMUs.lua"," diff --git a/testsuite/omsimulator/testSynchronousFMU_01.mos b/testsuite/omsimulator/testSynchronousFMU_01.mos index 29d7f82f684..ca95df57f40 100644 --- a/testsuite/omsimulator/testSynchronousFMU_01.mos +++ b/testsuite/omsimulator/testSynchronousFMU_01.mos @@ -18,7 +18,7 @@ echo(true); simulate(Modelica_Synchronous.Examples.Elementary.ClockSignals.SubSample, stopTime=0.25, outputFormat="csv"); getErrorString(); // Build FMU with Synchronous features -buildModelFMU(Modelica_Synchronous.Examples.Elementary.ClockSignals.SubSample, version="2.0", fmuType="me"); getErrorString(); +buildModelFMU(Modelica_Synchronous.Examples.Elementary.ClockSignals.SubSample, version="2.0", fmuType="me", fileNamePrefix="Modelica_Synchronous.Examples.Elementary.ClockSignals.SubSample"); getErrorString(); // Simulate FMU with OMSimulator system(getInstallationDirectoryPath() + "/bin/OMSimulator Modelica_Synchronous.Examples.Elementary.ClockSignals.SubSample.fmu" diff --git a/testsuite/omsimulator/testSynchronousFMU_02.mos b/testsuite/omsimulator/testSynchronousFMU_02.mos index b769d9362e5..78ba29bcad9 100644 --- a/testsuite/omsimulator/testSynchronousFMU_02.mos +++ b/testsuite/omsimulator/testSynchronousFMU_02.mos @@ -11,11 +11,11 @@ echo(false); mkdir("tempSynchronous02/"); cd("tempSynchronous02/"); echo(true); -// Refernce results without FMU +// Reference results without FMU simulate(Modelica.Clocked.Examples.CascadeControlledDrive.AbsoluteClocks, stopTime=4, outputFormat="csv"); getErrorString(); // Build FMU with Synchronous features -buildModelFMU(Modelica.Clocked.Examples.CascadeControlledDrive.AbsoluteClocks, version="2.0", fmuType="me"); getErrorString(); +buildModelFMU(Modelica.Clocked.Examples.CascadeControlledDrive.AbsoluteClocks, version="2.0", fmuType="me", fileNamePrefix="Modelica.Clocked.Examples.CascadeControlledDrive.AbsoluteClocks"); getErrorString(); // Simulate FMU with OMSimulator system(getInstallationDirectoryPath() + "/bin/OMSimulator Modelica.Clocked.Examples.CascadeControlledDrive.AbsoluteClocks.fmu" diff --git a/testsuite/openmodelica/cppruntime/fmu/modelExchange/1.0/Crane_FMU1_CPP.mos b/testsuite/openmodelica/cppruntime/fmu/modelExchange/1.0/Crane_FMU1_CPP.mos index 11279d0f547..28e41c4b00c 100644 --- a/testsuite/openmodelica/cppruntime/fmu/modelExchange/1.0/Crane_FMU1_CPP.mos +++ b/testsuite/openmodelica/cppruntime/fmu/modelExchange/1.0/Crane_FMU1_CPP.mos @@ -8,7 +8,7 @@ loadModel(Modelica, {"3.2.2"}); getErrorString(); setCommandLineOptions("+simCodeTarget=Cpp"); getErrorString(); loadFile("cranes.mo"); getErrorString(); -buildModelFMU(cranes.crane, version="1.0"); getErrorString(); +buildModelFMU(cranes.crane, version="1.0", fileNamePrefix="cranes.crane"); getErrorString(); setCommandLineOptions("+simCodeTarget=C"); getErrorString(); //importFMU("cranes_crane.fmu", "", 6, false, true); getErrorString(); diff --git a/testsuite/openmodelica/cppruntime/fmu/modelExchange/2.0/exposeLocalIOs.mos b/testsuite/openmodelica/cppruntime/fmu/modelExchange/2.0/exposeLocalIOs.mos index 0986a9115b0..c1a088438c1 100644 --- a/testsuite/openmodelica/cppruntime/fmu/modelExchange/2.0/exposeLocalIOs.mos +++ b/testsuite/openmodelica/cppruntime/fmu/modelExchange/2.0/exposeLocalIOs.mos @@ -82,7 +82,7 @@ end LocalIOs; "); getErrorString(); -buildModelFMU(LocalIOs.System, version="2.0"); getErrorString(); +buildModelFMU(LocalIOs.System, version="2.0", fileNamePrefix="LocalIOs.System"); getErrorString(); // unzip to console, quiet, extra quiet system("unzip -cqq LocalIOs.System.fmu modelDescription.xml | grep -v guid | grep -v generationDateAndTime | grep -v generationTool > modelDescription.tmp.xml"); diff --git a/testsuite/openmodelica/fmi/CoSimulation/2.0/RecompileSourceCodeFMU.mos b/testsuite/openmodelica/fmi/CoSimulation/2.0/RecompileSourceCodeFMU.mos index 569c9459e4f..66584a3f7c8 100644 --- a/testsuite/openmodelica/fmi/CoSimulation/2.0/RecompileSourceCodeFMU.mos +++ b/testsuite/openmodelica/fmi/CoSimulation/2.0/RecompileSourceCodeFMU.mos @@ -22,7 +22,7 @@ end Test; "); getErrorString(); setCommandLineOptions("--fmiFlags=s:cvode"); getErrorString(); -buildModelFMU(Test.SinSource, version="2.0", fmuType ="cs", platforms={"static"}); getErrorString(); +buildModelFMU(Test.SinSource, version="2.0", fmuType ="cs", fileNamePrefix="Test.SinSource", platforms={"static"}); getErrorString(); // Check if CMake can re-compile a static library system("rm -rf Test_SinSource_FMU && unzip -qq Test.SinSource.fmu -d Test_SinSource_FMU && mkdir Test_SinSource_FMU/sources/build_cmake", outputFile="reCompile.log"); getErrorString(); diff --git a/testsuite/openmodelica/fmi/CoSimulation/2.0/issue10523.mos b/testsuite/openmodelica/fmi/CoSimulation/2.0/issue10523.mos index f0f7f957350..ada341f9134 100644 --- a/testsuite/openmodelica/fmi/CoSimulation/2.0/issue10523.mos +++ b/testsuite/openmodelica/fmi/CoSimulation/2.0/issue10523.mos @@ -6,7 +6,7 @@ loadModel(Modelica); getErrorString(); -buildModelFMU(Modelica.Blocks.Sources.IntegerConstant, version="2.0", fmuType="cs"); +buildModelFMU(Modelica.Blocks.Sources.IntegerConstant, version="2.0", fmuType="cs", fileNamePrefix="Modelica.Blocks.Sources.IntegerConstant"); getErrorString(); diff --git a/testsuite/openmodelica/fmi/ModelExchange/2.0/FMUResourceTest.mos b/testsuite/openmodelica/fmi/ModelExchange/2.0/FMUResourceTest.mos index 8a7dfdfe555..80f3b11ec67 100644 --- a/testsuite/openmodelica/fmi/ModelExchange/2.0/FMUResourceTest.mos +++ b/testsuite/openmodelica/fmi/ModelExchange/2.0/FMUResourceTest.mos @@ -12,7 +12,7 @@ mkdir("@"); echo(false); cd("@"); echo(true); -buildModelFMU(FMUResourceTest.TestResource, version="2.0"); getErrorString(); +buildModelFMU(FMUResourceTest.TestResource, version="2.0", fileNamePrefix="FMUResourceTest.TestResource"); getErrorString(); importFMU("FMUResourceTest.TestResource.fmu"); getErrorString(); loadFile("FMUResourceTest_TestResource_me_FMU.mo"); getErrorString(); echo(false); diff --git a/testsuite/openmodelica/fmi/ModelExchange/2.0/testBug5673.mos b/testsuite/openmodelica/fmi/ModelExchange/2.0/testBug5673.mos index dbaede32576..b1408a24c78 100644 --- a/testsuite/openmodelica/fmi/ModelExchange/2.0/testBug5673.mos +++ b/testsuite/openmodelica/fmi/ModelExchange/2.0/testBug5673.mos @@ -36,7 +36,7 @@ system("sed -n \"//,/<\\/ModelVariables>/p\" aliasCheck.test2_in readFile("Bug5673.xml"); getErrorString(); -buildModelFMU(aliasCheck.test2,version="2.0"); +buildModelFMU(aliasCheck.test2,version="2.0", fileNamePrefix="aliasCheck.test2"); getErrorString(); // unzip to console, quiet, extra quiet diff --git a/testsuite/special/FmuExportCrossCompile/CMakeCrossCompile.mos b/testsuite/special/FmuExportCrossCompile/CMakeCrossCompile.mos index 113299da2f6..32a3ead271f 100644 --- a/testsuite/special/FmuExportCrossCompile/CMakeCrossCompile.mos +++ b/testsuite/special/FmuExportCrossCompile/CMakeCrossCompile.mos @@ -25,5 +25,5 @@ platforms := { "i686-linux-gnu docker run docker.openmodelica.org/build-deps:v1.13-i386", "x86_64-w64-mingw32 docker run multiarch/crossbuild", "i686-w64-mingw32 docker run multiarch/crossbuild"}; -buildModelFMU(Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum, version="2.0", fmuType="me_cs", platforms=platforms); getErrorString(); +buildModelFMU(Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum, version="2.0", fmuType="me_cs", fileNamePrefix="Modelica.Mechanics.MultiBody.Examples.Elementary.Pendulum", platforms=platforms); getErrorString();