Skip to content

Commit

Permalink
- export fmu generated with +target=msvc
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@14879 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Jan 22, 2013
1 parent 3b3c2df commit bf99066
Showing 1 changed file with 83 additions and 2 deletions.
85 changes: 83 additions & 2 deletions Compiler/Template/CodegenFMU.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ template translateModel(SimCode simCode)
match simCode
case SIMCODE(modelInfo=modelInfo as MODELINFO(__)) then
let guid = getUUIDStr()
let target = simulationCodeTarget()
let()= textFile(simulationFunctionsHeaderFile(fileNamePrefix, modelInfo.functions, recordDecls), '<%fileNamePrefix%>_functions.h')
let()= textFile(simulationFunctionsFile(fileNamePrefix, modelInfo.functions, literals), '<%fileNamePrefix%>_functions.c')
let()= textFile(recordsFile(fileNamePrefix, recordDecls), '<%fileNamePrefix%>_records.c')
Expand All @@ -65,7 +66,7 @@ case SIMCODE(modelInfo=modelInfo as MODELINFO(__)) then
let()= textFile(fmumodel_identifierFile(simCode,guid), '<%fileNamePrefix%>_FMU.c')
let()= textFile(fmuModelDescriptionFile(simCode,guid), 'modelDescription.xml')
let()= textFile(fmudeffile(simCode), '<%fileNamePrefix%>.def')
let()= textFile(fmuMakefile(simCode), '<%fileNamePrefix%>_FMU.makefile')
let()= textFile(fmuMakefile(target,simCode), '<%fileNamePrefix%>_FMU.makefile')
"" // Return empty result since result written to files directly
end translateModel;

Expand Down Expand Up @@ -1016,9 +1017,86 @@ match platform
>>
end getPlatformString2;

template fmuMakefile(SimCode simCode)
template fmuMakefile(String target, SimCode simCode)
"Generates the contents of the makefile for the simulation case. Copy libexpat & correct linux fmu"
::=
match target
case "msvc" then
match simCode
case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simulationSettingsOpt = sopt) then
let dirExtra = if modelInfo.directory then '-L"<%modelInfo.directory%>"' //else ""
let libsStr = (makefileParams.libs |> lib => lib ;separator=" ")
let libsPos1 = if not dirExtra then libsStr //else ""
let libsPos2 = if dirExtra then libsStr // else ""
let extraCflags = match sopt case SOME(s as SIMULATION_SETTINGS(__)) then
'<%if s.measureTime then "-D_OMC_MEASURE_TIME "%> <%match s.method
case "inline-euler" then "-D_OMC_INLINE_EULER"
case "inline-rungekutta" then "-D_OMC_INLINE_RK"%>'
let compilecmds = getPlatformString2(makefileParams.platform, fileNamePrefix, dirExtra, libsPos1, libsPos2, makefileParams.omhome)
<<
# Makefile generated by OpenModelica

# Simulations use -O3 by default
SIM_OR_DYNLOAD_OPT_LEVEL=
MODELICAUSERCFLAGS=
CXX=cl
EXEEXT=.exe
DLLEXT=.dll
FMUEXT=.fmu
PLATLINUX = linux32
PLATWIN32 = win32

# /Od - Optimization disabled
# /EHa enable C++ EH (w/ SEH exceptions)
# /fp:except - consider floating-point exceptions when generating code
# /arch:SSE2 - enable use of instructions available with SSE2 enabled CPUs
# /I - Include Directories
# /DNOMINMAX - Define NOMINMAX (does what it says)
# /TP - Use C++ Compiler
CFLAGS=/Od /ZI /EHa /fp:except /I"<%makefileParams.omhome%>/include/omc" /I. /DNOMINMAX /TP /DNO_INTERACTIVE_DEPENDENCY

# /ZI enable Edit and Continue debug info
CDFLAGS = /ZI

# /MD - link with MSVCRT.LIB
# /link - [linker options and libraries]
# /LIBPATH: - Directories where libs can be found
LDFLAGS=/MD /link /debug /pdb:"<%fileNamePrefix%>.pdb" /LIBPATH:"<%makefileParams.omhome%>/lib/omc/msvc/" /LIBPATH:"<%makefileParams.omhome%>/lib/omc/msvc/release/" <%dirExtra%> <%libsPos1%> <%libsPos2%> f2c.lib initialization.lib libexpat.lib math-support.lib meta.lib ModelicaExternalC.lib results.lib simulation.lib solver.lib sundials_kinsol.lib sundials_nvecserial.lib util.lib lapack_win32_MT.lib

# /MDd link with MSVCRTD.LIB debug lib
# lib names should not be appended with a d just switch to lib/omc/msvc/debug


FILEPREFIX=<%fileNamePrefix%>
MAINFILE=$(FILEPREFIX).c
MAINOBJ=$(FILEPREFIX).obj
GENERATEDFILES=$(MAINFILE) $(FILEPREFIX)_functions.c $(FILEPREFIX)_functions.h $(FILEPREFIX)_records.c $(FILEPREFIX).makefile

$(FILEPREFIX)$(FMUEXT): $(FILEPREFIX)$(DLLEXT) modelDescription.xml
if not exist <%fileNamePrefix%>\binaries\$(PLATWIN32) mkdir <%fileNamePrefix%>\binaries\$(PLATWIN32)
if not exist <%fileNamePrefix%>\sources mkdir <%fileNamePrefix%>\sources

copy <%fileNamePrefix%>.dll <%fileNamePrefix%>\binaries\$(PLATWIN32)
copy <%fileNamePrefix%>.lib <%fileNamePrefix%>\binaries\$(PLATWIN32)
copy <%fileNamePrefix%>.pdb <%fileNamePrefix%>\binaries\$(PLATWIN32)
copy <%fileNamePrefix%>.c <%fileNamePrefix%>\sources\<%fileNamePrefix%>.c
copy _<%fileNamePrefix%>.h <%fileNamePrefix%>\sources\_<%fileNamePrefix%>.h
copy <%fileNamePrefix%>_FMU.c <%fileNamePrefix%>\sources\<%fileNamePrefix%>_FMU.c
copy <%fileNamePrefix%>_functions.c <%fileNamePrefix%>\sources\<%fileNamePrefix%>_functions.c
copy <%fileNamePrefix%>_functions.h <%fileNamePrefix%>\sources\<%fileNamePrefix%>_functions.h
copy <%fileNamePrefix%>_records.c <%fileNamePrefix%>\sources\<%fileNamePrefix%>_records.c
copy modelDescription.xml <%fileNamePrefix%>\modelDescription.xml
copy <%stringReplace(makefileParams.omhome,"/","\\")%>\lib\omc\libexec\gnuplot\binary\libexpat-1.dll <%fileNamePrefix%>\binaries\$(PLATWIN32)
cd <%fileNamePrefix%>
zip -r ../<%fileNamePrefix%>.fmu *
cd ..
rmdir /S /Q <%fileNamePrefix%>

$(FILEPREFIX)$(DLLEXT): $(MAINOBJ) $(FILEPREFIX)_records.c $(FILEPREFIX)_functions.c $(FILEPREFIX)_functions.h
$(CXX) /Fe$(FILEPREFIX)$(DLLEXT) $(MAINFILE) $(FILEPREFIX)_FMU.c $(FILEPREFIX)_records.c $(CFLAGS) $(LDFLAGS)
>>
end match
case "gcc" then
match simCode
case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simulationSettingsOpt = sopt) then
let dirExtra = if modelInfo.directory then '-L"<%modelInfo.directory%>"' //else ""
Expand Down Expand Up @@ -1061,6 +1139,9 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
clean:
<%\t%> @rm -f <%fileNamePrefix%>_records.o $(MAINOBJ) <%fileNamePrefix%>_FMU.o <%fileNamePrefix%>.o
>>
end match
else
error(sourceInfo(), 'target <%target%> is not handled!')
end fmuMakefile;

template fmudeffile(SimCode simCode)
Expand Down

0 comments on commit bf99066

Please sign in to comment.