Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 15ba583

Browse files
sjoelundOpenModelica-Hudson
authored andcommitted
Fix generated C++ FMU filenames
Previously, the API reported dots were used, but underscores were actually being used. The problem is that the FMI templates changed the meaning of the fileNamePrefix (from the OM API user's perspective).
1 parent bacaf03 commit 15ba583

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

Compiler/Script/CevalScriptBackend.mo

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3285,6 +3285,8 @@ algorithm
32853285
Error.addMessage(Error.FMU_EXPORT_NOT_SUPPORTED_CPP, {FMUType});
32863286
FMUType := "me";
32873287
end if;
3288+
// NOTE: The FMUs use fileNamePrefix for the internal name when it would be expected to be fileNamePrefix that decides the .fmu filename
3289+
// The scripting environment from a user's perspective is like that. fmuTargetName is the name of the .fmu in the templates, etc.
32883290
filenameprefix := Util.stringReplaceChar(if inFileNamePrefix == "<default>" then Absyn.pathString(className) else inFileNamePrefix, ".", "_");
32893291
fmuTargetName := if FMUVersion == "1.0" then filenameprefix else (if inFileNamePrefix == "<default>" then Absyn.pathString(className) else inFileNamePrefix);
32903292
defaulSimOpt := buildSimulationOptionsFromModelExperimentAnnotation(st, className, filenameprefix, SOME(defaultSimulationOptions));

Compiler/Template/CodegenFMUCpp.tpl

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -648,8 +648,6 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
648648
let ParModelicaLibs = if acceptParModelicaGrammar() then '-lOMOCLRuntime -lOpenCL' // else ""
649649
let extraCflags = match sopt case SOME(s as SIMULATION_SETTINGS(__)) then
650650
match s.method case "dassljac" then "-D_OMC_JACOBIAN "
651-
// Note: FMI 1.0 did not distinguish modelIdentifier from fileNamePrefix
652-
let modelName = if isFMIVersion10(FMUVersion) then fileNamePrefix else dotPath(modelInfo.name)
653651
<<
654652
# Makefile generated by OpenModelica
655653
# run with nmake from Visual Studio Command Prompt
@@ -681,16 +679,15 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
681679
LDFLAGS=/link /DLL /NOENTRY /LIBPATH:"<%makefileParams.omhome%>/lib/omc/cpp/msvc" /LIBPATH:"<%makefileParams.omhome%>/bin" OMCppSystem_static.lib OMCppMath_static.lib OMCppExtensionUtilities_static.lib OMCppFMU_static.lib $(OMCPP_SOLVER_LIBS) ModelicaExternalC.lib ModelicaStandardTables.lib OMCppModelicaUtilities_static.lib $(EXTRA_LIBS)
682680
PLATFORM="<%makefileParams.platform%>"
683681

684-
MODEL_NAME=<%modelName%>
685682
MODELICA_SYSTEM_LIB=<%fileNamePrefix%>
686683
CALCHELPERMAINFILE=OMCpp$(MODELICA_SYSTEM_LIB)CalcHelperMain.cpp
687684

688-
$(MODELICA_SYSTEM_LIB).fmu: $(MODELICA_SYSTEM_LIB)$(DLLEXT)
685+
<%fmuTargetName%>.fmu: $(MODELICA_SYSTEM_LIB)$(DLLEXT)
689686
<%\t%>rm -rf binaries
690687
<%\t%>mkdir -p "binaries/$(PLATFORM)"
691688
<%\t%>mv $(MODELICA_SYSTEM_LIB)$(DLLEXT) "binaries/$(PLATFORM)/"
692689
<%\t%>rm -f $(MODELICA_SYSTEM_LIB).fmu
693-
<%\t%>zip -r "$(MODELICA_SYSTEM_LIB).fmu" modelDescription.xml binaries
690+
<%\t%>zip -r "<%fmuTargetName%>.fmu" modelDescription.xml binaries
694691
<%\t%>rm -rf binaries
695692

696693
$(MODELICA_SYSTEM_LIB)$(DLLEXT):
@@ -704,7 +701,6 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
704701
let libsExtra = (makefileParams.libs |> lib => lib ;separator=" ")
705702
let extraCflags = match sopt case SOME(s as SIMULATION_SETTINGS(__)) then ""
706703
// Note: FMI 1.0 did not distinguish modelIdentifier from fileNamePrefix
707-
let modelName = if isFMIVersion10(FMUVersion) then fileNamePrefix else dotPath(modelInfo.name)
708704
let platformstr = match makefileParams.platform case "i386-pc-linux" then 'linux32' case "x86_64-linux" then 'linux64' else '<%makefileParams.platform%>'
709705
let omhome = makefileParams.omhome
710706
let platformbins = match platformstr case "win32" case "win64" then '<%omhome%>/bin/libgcc_s_*.dll <%omhome%>/bin/libstdc++-6.dll <%omhome%>/bin/libwinpthread-1.dll' else ''
@@ -800,9 +796,9 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
800796
CPPFILES=$(CALCHELPERMAINFILE)
801797
OFILES=$(CPPFILES:.cpp=.o)
802798

803-
.PHONY: <%modelName%>.fmu $(CPPFILES) clean
799+
.PHONY: <%fmuTargetName%>.fmu $(CPPFILES) clean
804800

805-
<%fileNamePrefix%>.fmu: $(OFILES)
801+
<%fmuTargetName%>.fmu: $(OFILES)
806802
<%\t%>$(CXX) -shared -o <%fileNamePrefix%>$(DLLEXT) $(OFILES) $(LDFLAGS) $(LIBS)
807803
<%\t%><%mkdir%> -p "binaries/$(PLATFORM)"
808804
<%\t%>cp $(BINARIES) "binaries/$(PLATFORM)/"
@@ -812,12 +808,12 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
812808
<%\t%>cp $(SUNDIALS_LIBRARIES_KINSOL) "binaries/$(PLATFORM)/"
813809
<%\t%>cp $(OMHOME)/share/omc/runtime/cpp/licenses/sundials.license "documentation/"
814810
endif
815-
<%\t%>rm -f <%fileNamePrefix%>.fmu
811+
<%\t%>rm -f <%fmuTargetName%>.fmu
816812
ifeq ($(USE_FMU_SUNDIALS),ON)
817-
<%\t%>zip -r "<%fileNamePrefix%>.fmu" modelDescription.xml binaries documentation
813+
<%\t%>zip -r "<%fmuTargetName%>.fmu" modelDescription.xml binaries documentation
818814
<%\t%>rm -rf documentation
819815
else
820-
<%\t%>zip -r "<%fileNamePrefix%>.fmu" modelDescription.xml binaries
816+
<%\t%>zip -r "<%fmuTargetName%>.fmu" modelDescription.xml binaries
821817
endif
822818

823819
clean:

0 commit comments

Comments
 (0)