Skip to content

Commit

Permalink
fix windows build and source fmu test on gcc
Browse files Browse the repository at this point in the history
  • Loading branch information
adrpo committed Oct 11, 2015
1 parent fb7644b commit fb0df34
Show file tree
Hide file tree
Showing 9 changed files with 56 additions and 41 deletions.
2 changes: 1 addition & 1 deletion Compiler/Script/CevalScript.mo
Expand Up @@ -243,7 +243,7 @@ algorithm
// to the environment variable! Don't ask me why, ask Microsoft.
omhome := "set OPENMODELICAHOME=\"" + System.stringReplace(omhome_1, "/", "\\") + "\"&& ";
setMakeVars := sum("set "+var+"&& " for var in makeVarsNoBinding);
cdWorkingDir := if stringLength(workingDir) == 0 then "" else ("cd \"" + workingDir + "\"");
cdWorkingDir := if stringLength(workingDir) == 0 then "" else ("cd \"" + workingDir + "\"&& ");
winCompileMode := if Config.getRunningTestsuite() then "serial" else "parallel";
s_call := stringAppendList({omhome,cdWorkingDir,setMakeVars,"\"",omhome_1,pd,"share",pd,"omc",pd,"scripts",pd,"Compile","\""," ",fileprefix," ",Config.simulationCodeTarget()," ", winCompileMode});
else
Expand Down
10 changes: 6 additions & 4 deletions Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -2621,13 +2621,15 @@ algorithm
GlobalScript.SymbolTable st;
list<String> libs;
Values.Value outValMsg;
String file_dir, FMUVersion, FMUType, fileNamePrefix, str, fmutmp;
String file_dir, FMUVersion, FMUType, fileNamePrefix, str, fmutmp, quote;
Boolean isWindows = System.os() == "Windows_NT";
case (cache,env,_,st,FMUVersion,FMUType,fileNamePrefix,_,_) /* mo file directory */
equation
(cache, outValMsg, st,_, libs,_, _) =
SimCodeMain.translateModelFMU(cache,env,className,st,FMUVersion,FMUType,fileNamePrefix,addDummy,inSimSettingsOpt);

// compile
quote = if isWindows then "" else "'";
CevalScript.compileModel(fileNamePrefix+"_FMU" , libs);
if Config.simCodeTarget() <> "Cpp" then
fmutmp = fileNamePrefix + ".fmutmp";
Expand All @@ -2640,12 +2642,12 @@ algorithm
// CevalScript.compileModel(fileNamePrefix , libs, workingDir=fmutmp+"/sources", makeVars={"CC=arm-linux-gnueabi-gcc","FMIPLATFORM=arm-linux-gnueabi","DLLEXT=.so"});
CevalScript.compileModel(fileNamePrefix , libs, workingDir=fmutmp+"/sources", makeVars={
"CC="+System.getCCompiler(),
"'CFLAGS="+System.getCFlags()+"'",
"CFLAGS="+quote+System.getCFlags()+quote,
"CPPFLAGS=",
"'LDFLAGS="+System.getLDFlags()+" "+(if staticSourceCodeFMU then System.getRTLibsFMU() /*TODO: Should not be needed, once we remove the need for lapack/expat*/ else System.getRTLibsSim())+"'",
"LDFLAGS="+quote+System.getLDFlags()+" "+(if staticSourceCodeFMU then System.getRTLibsFMU() /*TODO: Should not be needed, once we remove the need for lapack/expat*/ else System.getRTLibsSim()) + quote,
"FMIPLATFORM="+System.modelicaPlatform(),
"DLLEXT="+System.getDllExt(),
"'LD="+System.getLinker()+"'",
"LD="+quote+System.getLinker()+quote,
if staticSourceCodeFMU then "OPENMODELICA_DYNAMIC=" else "OPENMODELICA_DYNAMIC=1"
});
// CevalScript.compileModel(fileNamePrefix , libs, workingDir=fmutmp+"/sources", makeVars={});
Expand Down
63 changes: 34 additions & 29 deletions Compiler/Template/CodegenFMU.tpl
Expand Up @@ -78,7 +78,7 @@ case sc as SIMCODE(modelInfo=modelInfo as MODELINFO(__)) then
let x = covertTextFileToCLiteral('<%fileNamePrefixTmpDir%>_init.xml','<%fileNamePrefixTmpDir%>_init.c')
let()= textFile(fmumodel_identifierFile(simCode,guid,FMUVersion), '<%fileNamePrefixTmpDir%>_FMU.c')
let()= textFile(fmuModelDescriptionFile(simCode,guid,FMUVersion,FMUType), '<%fileNamePrefix%>.fmutmp/modelDescription.xml')
let()= textFile(fmudeffile(simCode,FMUVersion), '<%fileNamePrefix%>.fmutmp/<%fileNamePrefix%>.def')
let()= textFile(fmudeffile(simCode,FMUVersion), '<%fileNamePrefix%>.fmutmp/sources/<%fileNamePrefix%>.def')
let()= textFile(fmuMakefile(target,simCode,FMUVersion), '<%fileNamePrefix%>.fmutmp/sources/Makefile')
let()= textFile('# Dummy file so OMDEV Compile.bat works<%\n%>include Makefile<%\n%>', '<%fileNamePrefix%>.fmutmp/sources/<%fileNamePrefix%>.makefile')
let()= textFile(fmuSourceMakefile(simCode,FMUVersion), '<%fileNamePrefix%>_FMU.makefile')
Expand Down Expand Up @@ -985,28 +985,19 @@ let fmudirname = '<%fileNamePrefix%>.fmutmp'
match platform
case "win32" then
<<
<%fileNamePrefix%>_FMU: $(MAINOBJ) <%fileNamePrefix%>_functions.h <%fileNamePrefix%>_literals.h $(OFILES)
<%\t%>$(CXX) -shared -I. -o <%modelNamePrefix%>$(DLLEXT) $(MAINOBJ) $(OFILES) $(CPPFLAGS) <%dirExtra%> <%libsPos1%> <%libsPos2%> $(CFLAGS) $(LDFLAGS) -Wl,-Bstatic -lf2c -Wl,-Bdynamic -llis -Wl,--kill-at

<%\t%>mkdir.exe -p <%fmudirname%>
<%\t%>mkdir.exe -p <%fmudirname%>/binaries
<%\t%>mkdir.exe -p <%fmudirname%>/binaries/<%platform%>
<%\t%>mkdir.exe -p <%fmudirname%>/sources/include

<%fileNamePrefix%>_FMU: $(MAINOBJ) <%fileNamePrefix%>_functions.h <%fileNamePrefix%>_literals.h $(OFILES) $(RUNTIMEFILES)
<%\t%>$(CXX) -shared -I. -o <%modelNamePrefix%>$(DLLEXT) $(MAINOBJ) $(RUNTIMEFILES) $(OFILES) $(CPPFLAGS) <%dirExtra%> <%libsPos1%> <%libsPos2%> $(CFLAGS) $(LDFLAGS) -Wl,-Bstatic -lf2c -Wl,-Bdynamic -llis -Wl,--kill-at
<%\t%>mkdir.exe -p ../binaries/<%platform%>
<%\t%>dlltool -d <%fileNamePrefix%>.def --dllname <%fileNamePrefix%>$(DLLEXT) --output-lib <%fileNamePrefix%>.lib --kill-at
<%\t%>cp <%fileNamePrefix%>$(DLLEXT) <%fmudirname%>/binaries/<%platform%>/
<%\t%>cp <%fileNamePrefix%>.lib <%fmudirname%>/binaries/<%platform%>/
<%\t%>cp $(GENERATEDFILES) <%fmudirname%>/sources/
<%\t%>cp -a <%omhome%>/include/omc/c/* <%fmudirname%>/sources/include
<%\t%>cp modelDescription.xml <%fmudirname%>/modelDescription.xml
<%\t%>cp <%omhome%>/bin/libexpat.dll <%fmudirname%>/binaries/<%platform%>/
<%\t%>cp <%omhome%>/bin/pthreadGC2.dll <%fmudirname%>/binaries/<%platform%>/
<%\t%>cp <%omhome%>/bin/libgfortran-3.dll <%fmudirname%>/binaries/<%platform%>/
<%\t%>cp <%omhome%>/bin/libsundials_kinsol.dll <%fmudirname%>/binaries/<%platform%>/
<%\t%>cp <%omhome%>/bin/libsundials_nvecserial.dll <%fmudirname%>/binaries/<%platform%>/
<%\t%>cd <%fmudirname%>&& rm -f ../<%fileNamePrefix%>.fmu&& zip -r ../<%fileNamePrefix%>.fmu *
<%\t%>rm -rf <%fmudirname%>
<%\t%>rm -f <%fileNamePrefix%>.def <%fileNamePrefix%>.o <%fileNamePrefix%>.so <%fileNamePrefix%>_*.o
<%\t%>cp <%fileNamePrefix%>$(DLLEXT) <%fileNamePrefix%>.lib <%fileNamePrefix%>_FMU.libs ../binaries/<%platform%>/
<%\t%>cp <%omhome%>/bin/libexpat.dll ../binaries/<%platform%>/
<%\t%>cp <%omhome%>/bin/pthreadGC2.dll ../binaries/<%platform%>/
<%\t%>cp <%omhome%>/bin/libgfortran-3.dll ../binaries/<%platform%>/
<%\t%>cp <%omhome%>/bin/libsundials_kinsol.dll ../binaries/<%platform%>/
<%\t%>cp <%omhome%>/bin/libsundials_nvecserial.dll ../binaries/<%platform%>/
<%\t%>rm -f <%fileNamePrefix%>.def <%fileNamePrefix%>.o <%fileNamePrefix%>$(DLLEXT) $(OFILES) $(RUNTIMEFILES)
<%\t%>cd .. && rm -f ../<%fileNamePrefix%>.fmu && zip -r ../<%fileNamePrefix%>.fmu *

>>
else
<<
Expand Down Expand Up @@ -1059,6 +1050,7 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
case "inline-euler" then "-D_OMC_INLINE_EULER"
case "inline-rungekutta" then "-D_OMC_INLINE_RK"%>'
let compilecmds = getPlatformString2(modelNamePrefix(simCode), makefileParams.platform, fileNamePrefix, dirExtra, libsPos1, libsPos2, makefileParams.omhome, FMUVersion)
let mkdir = match makefileParams.platform case "win32" then '"mkdir.exe"' else 'mkdir'
<<
# Makefile generated by OpenModelica

Expand Down Expand Up @@ -1095,8 +1087,8 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
<%common%>

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

copy <%fileNamePrefix%>.dll <%fmudirname%>\binaries\$(PLATWIN32)
copy <%fileNamePrefix%>.lib <%fmudirname%>\binaries\$(PLATWIN32)
Expand Down Expand Up @@ -1142,7 +1134,8 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
# Note: Simulation of the fmu with dymola does not work with -finline-small-functions (enabled by most optimization levels)
override CPPFLAGS += -Iinclude/ -Iinclude/fmi<%if isFMIVersion20(FMUVersion) then "2" else "1"%> -I. <%makefileParams.includes ; separator=" "%>
ifeq ($(OPENMODELICA_DYNAMIC),)
override CPPFLAGS += -DOMC_MINIMAL_RUNTIME=1
override CPPFLAGS += -DOMC_MINIMAL_RUNTIME=1 -DCMINPACK_NO_DLL=1
override LDFLAGS += -L"<%makefileParams.omhome%>/lib/<%getTriple()%>/omc"
else
override LDFLAGS += -L"<%makefileParams.omhome%>/lib/<%getTriple()%>/omc" -Wl,-rpath,'<%makefileParams.omhome%>/lib/<%getTriple()%>/omc' <%makefileParams.ldflags%> <%makefileParams.runtimelibs%> <%dirExtra%>
endif
Expand Down Expand Up @@ -1176,20 +1169,20 @@ template fmuSourceMakefile(SimCode simCode, String FMUVersion)
match simCode
case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simulationSettingsOpt = sopt) then
let includedir = '<%fileNamePrefix%>.fmutmp/sources/include/'
let mkdir = match makefileParams.platform case "win32" then '"mkdir.exe"' else 'mkdir'
<<
# FIXME: before you push into master...
RUNTIMEDIR=<%makefileParams.omhome%>/include/omc/c/
OMC_MINIMAL_RUNTIME=1
OMC_FMI_RUNTIME=1
include $(RUNTIMEDIR)/Makefile.objs
COPY_RUNTIMEFILES=$(FMI_ME_OBJS:%= && (OMCFILE=% && cp $(RUNTIMEDIR)/$$OMCFILE.c $$OMCFILE.c))
#COPY_RUNTIMEFILES=$(FMI_ME_OBJS:%= && (OMCFILE=% && cp $(RUNTIMEDIR)/$$OMCFILE.c $$OMCFILE.c))

fmu:
<%\t%>(cd <%includedir%> && mkdir -p $(ALL_PATHS))
<%\t%>rm -f <%fileNamePrefix%>.fmutmp/sources/<%fileNamePrefix%>_init.xml<%/*Already translated to .c*/%>
<%\t%>cp -a <%makefileParams.omhome%>/include/omc/c/* <%includedir%>
<%\t%>cp -pur <%makefileParams.omhome%>/include/omc/c/* <%includedir%>
<%\t%>cp -a <%fileNamePrefix%>_FMU.libs <%fileNamePrefix%>.fmutmp/sources/
<%\t%>cd <%includedir%> $(COPY_RUNTIMEFILES)
<%\n%>
>>
end fmuSourceMakefile;

Expand Down Expand Up @@ -1242,6 +1235,18 @@ case SIMCODE(modelInfo=MODELINFO(__), makefileParams=MAKEFILE_PARAMS(__), simula
<%fileNamePrefix%>_fmiGetEventIndicators @33
<%fileNamePrefix%>_fmiGetContinuousStates @34
<%fileNamePrefix%>_fmiGetNominalsOfContinuousStates @35
;***************************************************
;Functions for FMI for Co-Simulation
;****************************************************
<%fileNamePrefix%>_fmiSetRealInputDerivatives @36
<%fileNamePrefix%>_fmiGetRealOutputDerivatives @37
<%fileNamePrefix%>_fmiDoStep @38
<%fileNamePrefix%>_fmiCancelStep @39
<%fileNamePrefix%>_fmiGetStatus @40
<%fileNamePrefix%>_fmiGetRealStatus @41
<%fileNamePrefix%>_fmiGetIntegerStatus @42
<%fileNamePrefix%>_fmiGetBooleanStatus @43
<%fileNamePrefix%>_fmiGetStringStatus @44
>>
else
<<
Expand Down
2 changes: 0 additions & 2 deletions SimulationRuntime/c/meta/CMakeLists.txt
@@ -1,6 +1,5 @@
# Sources and Headers
SET(META_SRC meta_modelica_builtin.c
meta_modelica_string_lit.c
realString.c
meta_modelica_catch.c
meta_modelica.c
Expand All @@ -10,7 +9,6 @@ SET(META_SRC meta_modelica_builtin.c
SET(META_HFILES meta_modelica_builtin.h
meta_modelica_builtin_boxptr.h
meta_modelica_segv.h
meta_modelica_string_lit.h
meta_modelica.h
gc/mmc_gc.h)

Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/c/meta/meta_modelica_builtin_boxptr.h
Expand Up @@ -56,7 +56,7 @@
#define boxptr_wrapper1Arg(boxptr,name) modelica_metatype boxptr(threadData_t *, void*);
#endif

#if !defined(OMC_MINIMAL_RUNTIME) || !defined(OMC_FMI_RUNTIME)
#if !(defined(OMC_MINIMAL_RUNTIME) || defined(OMC_FMI_RUNTIME))

boxptr_unOp(boxptr_boolNot,mmc_mk_bcon,mmc_unbox_boolean,!)
boxptr_binOp(boxptr_boolAnd,mmc_mk_bcon,mmc_unbox_boolean,&&)
Expand Down Expand Up @@ -143,6 +143,6 @@ boxptr_wrapper2Args(boxptr_cons,mmc_mk_cons)
#undef boxptr_wrapper2Args
#undef boxptr_fn2ArgsThreadData

#endif /* #if !defined(OMC_MINIMAL_RUNTIME) || !defined(OMC_FMI_RUNTIME) */
#endif /* #if !(defined(OMC_MINIMAL_RUNTIME) || defined(OMC_FMI_RUNTIME)) */

#endif
5 changes: 5 additions & 0 deletions SimulationRuntime/c/meta/meta_modelica_builtin_boxvar.h
@@ -1,4 +1,7 @@
/* Code generated by meta_modelica_gen_boxvar.py */

#if !(defined(OMC_MINIMAL_RUNTIME) || defined(OMC_FMI_RUNTIME))

static const MMC_DEFSTRUCTLIT(boxvar_lit_arrayAppend,2,0) {(modelica_metatype)boxptr_arrayAppend,0}};
#define boxvar_arrayAppend MMC_REFSTRUCTLIT(boxvar_lit_arrayAppend)
static const MMC_DEFSTRUCTLIT(boxvar_lit_arrayCopy,2,0) {(modelica_metatype)boxptr_arrayCopy,0}};
Expand Down Expand Up @@ -169,3 +172,5 @@ static const MMC_DEFSTRUCTLIT(boxvar_lit_valueEq,2,0) {(modelica_metatype)boxptr
#define boxvar_valueEq MMC_REFSTRUCTLIT(boxvar_lit_valueEq)
static const MMC_DEFSTRUCTLIT(boxvar_lit_valueHashMod,2,0) {(modelica_metatype)boxptr_valueHashMod,0}};
#define boxvar_valueHashMod MMC_REFSTRUCTLIT(boxvar_lit_valueHashMod)

#endif /* #if !(defined(OMC_MINIMAL_RUNTIME) || defined(OMC_FMI_RUNTIME)) */
5 changes: 5 additions & 0 deletions SimulationRuntime/c/meta/meta_modelica_gen_boxvar.py
Expand Up @@ -89,6 +89,11 @@
]

print '/* Code generated by meta_modelica_gen_boxvar.py */'
print '#if !(defined(OMC_MINIMAL_RUNTIME) || defined(OMC_FMI_RUNTIME))'
print ''
for f in functions:
print 'static const MMC_DEFSTRUCTLIT(boxvar_lit_%s,2,0) {(modelica_metatype)boxptr_%s,0}};' % (f,f)
print '#define boxvar_%s MMC_REFSTRUCTLIT(boxvar_lit_%s)' % (f,f)
print '#endif /* #if !(defined(OMC_MINIMAL_RUNTIME) || defined(OMC_FMI_RUNTIME)) */'
print ''

2 changes: 1 addition & 1 deletion SimulationRuntime/c/simulation/simulation_input_xml.c
Expand Up @@ -399,8 +399,8 @@ static void read_var_attribute_bool(omc_ScalarVariable *v, BOOLEAN_ATTRIBUTE *at

static void read_var_attribute_string(omc_ScalarVariable *v, STRING_ATTRIBUTE *attribute)
{
read_value_bool(findHashStringString(v,"useStart"), &attribute->useStart);
const char *start = NULL;
read_value_bool(findHashStringString(v,"useStart"), &attribute->useStart);
read_value_string(findHashStringStringEmpty(v,"start"), &start);
attribute->start = mmc_mk_scon_persist(start);

Expand Down
4 changes: 2 additions & 2 deletions SimulationRuntime/c/util/CMakeLists.txt
Expand Up @@ -3,14 +3,14 @@ SET(util_sources base_array.c boolean_array.c omc_error.c division.c index_spec
integer_array.c java_interface.c libcsv.c list.c memory_pool.c modelica_string.c
read_write.c read_matlab4.c read_csv.c real_array.c ringbuffer.c rational.c
rtclock.c simulation_options.c string_array.c utility.c varinfo.c omc_msvc.c OldModelicaTables.c cJSON.c omc_mmap.c
ModelicaUtilities.c)
ModelicaUtilities.c modelica_string_lit.c)


SET(util_headers base_array.h boolean_array.h division.h omc_error.h index_spec.h integer_array.h
java_interface.h jni.h jni_md.h jni_md_solaris.h jni_md_windows.h list.h memory_pool.h
modelica.h modelica_string.h read_write.h read_matlab4.h real_array.h rational.h
ringbuffer.h rtclock.h simulation_options.h string_array.h utility.h varinfo.h omc_mmap.h cJSON.h
../ModelicaUtilities.h)
../ModelicaUtilities.h modelica_string_lit.h)

if(MSVC)
INCLUDE_DIRECTORIES(${OMCTRUNCHOME}/OMCompiler/3rdParty/regex-0.12)
Expand Down

0 comments on commit fb0df34

Please sign in to comment.