@@ -3164,6 +3164,83 @@ algorithm
31643164 end match;
31653165end translateModelCPP;*/
31663166
3167+ protected function configureFMU
3168+ input String platform;
3169+ input String fmutmp;
3170+ input String logfile;
3171+ input Boolean isWindows;
3172+ protected
3173+ String CC , CFLAGS , LDFLAGS , makefileStr,
3174+ dir= fmutmp+ "/sources/" , cmd= "" ,
3175+ quote= "'" ,
3176+ dquote = if isWindows then " \" " else "'" ;
3177+ algorithm
3178+ CC := System . getCCompiler();
3179+ CFLAGS := System . stringReplace(System . getCFlags(),"${MODELICAUSERCFLAGS}" ,"" );
3180+ LDFLAGS := ("-L" + dquote+ Settings . getInstallationDirectoryPath()+ "/lib/" + System . getTriple()+ "/omc" + dquote+ " " +
3181+ "-Wl,-rpath," + dquote+ Settings . getInstallationDirectoryPath()+ "/lib/" + System . getTriple()+ "/omc" + dquote+ " " +
3182+ System . getLDFlags()+ " " );
3183+ if System . regularFileExists(dir + logfile) then
3184+ System . removeFile(dir + logfile);
3185+ end if ;
3186+ _ := match platform
3187+ case "dynamic"
3188+ algorithm
3189+ makefileStr := System . readFile(dir + "Makefile.in" );
3190+ // replace @XX@ variables in the Makefile
3191+ makefileStr := System . stringReplace(makefileStr, "@CC@" , CC );
3192+ makefileStr := System . stringReplace(makefileStr, "@CFLAGS@" , CFLAGS );
3193+ makefileStr := System . stringReplace(makefileStr, "@LDFLAGS@" , LDFLAGS + System . getRTLibsSim());
3194+ makefileStr := System . stringReplace(makefileStr, "@LIBS@" , "" );
3195+ makefileStr := System . stringReplace(makefileStr, "@DLLEXT@" , System . getDllExt());
3196+ makefileStr := System . stringReplace(makefileStr, "@NEED_RUNTIME@" , "" );
3197+ makefileStr := System . stringReplace(makefileStr, "@NEED_DGESV@" , "" );
3198+ makefileStr := System . stringReplace(makefileStr, "@FMIPLATFORM@" , System . modelicaPlatform());
3199+ makefileStr := System . stringReplace(makefileStr, "@CPPFLAGS@" , "" );
3200+ makefileStr := System . stringReplace(makefileStr, "@LIBTYPE_DYNAMIC@" , "1" );
3201+ makefileStr := System . stringReplace(makefileStr, " \r\n " , " \n " );
3202+ System . writeFile(dir + "Makefile" , makefileStr);
3203+ System . writeFile(dir + "config.log" , "Using cached values for dynamic platform" );
3204+ cmd := "cached values" ;
3205+ then ();
3206+ case "static"
3207+ algorithm
3208+ makefileStr := System . readFile(dir + "Makefile.in" );
3209+ // replace @XX@ variables in the Makefile
3210+ makefileStr := System . stringReplace(makefileStr, "@CC@" , CC );
3211+ makefileStr := System . stringReplace(makefileStr, "@CFLAGS@" , CFLAGS );
3212+ makefileStr := System . stringReplace(makefileStr, "@LDFLAGS@" , LDFLAGS + System . getRTLibsFMU());
3213+ makefileStr := System . stringReplace(makefileStr, "@LIBS@" , "" );
3214+ makefileStr := System . stringReplace(makefileStr, "@DLLEXT@" , System . getDllExt());
3215+ makefileStr := System . stringReplace(makefileStr, "@NEED_RUNTIME@" , "1" );
3216+ makefileStr := System . stringReplace(makefileStr, "@NEED_DGESV@" , "" );
3217+ makefileStr := System . stringReplace(makefileStr, "@FMIPLATFORM@" , System . modelicaPlatform());
3218+ makefileStr := System . stringReplace(makefileStr, "@CPPFLAGS@" , "-DOMC_MINIMAL_RUNTIME=1 -DCMINPACK_NO_DLL=1" );
3219+ makefileStr := System . stringReplace(makefileStr, "@LIBTYPE_DYNAMIC@" , "1" );
3220+ makefileStr := System . stringReplace(makefileStr, " \r\n " , " \n " );
3221+ System . writeFile(dir + "Makefile" , makefileStr);
3222+ System . writeFile(dir + "config.log" , "Using cached values for static platform" );
3223+ cmd := "cached values" ;
3224+ then ();
3225+ else
3226+ algorithm
3227+ cmd := "cd \" " + fmutmp + "/sources \" && ./configure --host=" + quote+ platform+ quote+ " CFLAGS=" + quote+ "-Os -flto" + quote+ " LDFLAGS=-flto" ;
3228+ if 0 <> System . systemCall(cmd, outFile= logfile) then
3229+ Error . addMessage(Error . SIMULATOR_BUILD_ERROR , {System . readFile(logfile)});
3230+ System . removeFile(dir + logfile);
3231+ fail();
3232+ end if ;
3233+ then ();
3234+ end match;
3235+ if not isWindows then
3236+ if 0 <> System . systemCall("cd " + dir + " && make clean > /dev/null 2>&1" ) then
3237+ Error . addMessage(Error . SIMULATOR_BUILD_ERROR , {"Failed to make clean" });
3238+ fail();
3239+ end if ;
3240+ end if ;
3241+ ExecStat . execStat("buildModelFMU: configured platform " + platform + " using " + cmd);
3242+ end configureFMU;
3243+
31673244protected function buildModelFMU " author: Frenkel TUD
31683245 translates a model into cpp code and writes also a makefile"
31693246 input FCore . Cache inCache;
@@ -3180,8 +3257,8 @@ protected function buildModelFMU " author: Frenkel TUD
31803257 output GlobalScript . SymbolTable st;
31813258protected
31823259 Boolean staticSourceCodeFMU;
3183- String filenameprefix, quote, dquote, fmutmp, thisplatform, cmd, logfile,
3184- makefileStr, CC , CFLAGS , LDFLAGS , LIBS , dir;
3260+ String filenameprefix, fmutmp, thisplatform, cmd, logfile,
3261+ makefileStr, LIBS , dir;
31853262 GlobalScript . SimulationOptions defaulSimOpt;
31863263 SimCode . SimulationSettings simSettings;
31873264 list< String > libs;
@@ -3221,9 +3298,6 @@ algorithm
32213298 System . realtimeTick(ClockIndexes . RT_CLOCK_BUILD_MODEL );
32223299
32233300 isWindows := System . os() == "Windows_NT" ;
3224- // compile
3225- quote := if isWindows then "" else "'" ;
3226- dquote := if isWindows then " \" " else "'" ;
32273301
32283302 if Config . simCodeTarget() == "Cpp" then
32293303 System . removeDirectory("binaries" );
@@ -3234,79 +3308,30 @@ algorithm
32343308 CevalScript . compileModel(filenameprefix + "_FMU" , libs,
32353309 makeVars= {"TARGET_TRIPLET=" + platform});
32363310 end if ;
3311+ ExecStat . execStat("buildModelFMU: Generate C++ for platform " + platform);
32373312 end for ;
32383313 return ;
32393314 end if ;
32403315
32413316 CevalScript . compileModel(filenameprefix+ "_FMU" , libs);
3242- fmutmp := filenameprefix + ".fmutmp" ;
3243- logfile := filenameprefix + ".log" ;
32443317
3245- CC := quote+ System . getCCompiler()+ quote;
3246- CFLAGS := quote+ System . stringReplace(System . getCFlags(),"${MODELICAUSERCFLAGS}" ,"" )+ quote;
3247- LDFLAGS := quote+ ("-L" + dquote+ Settings . getInstallationDirectoryPath()+ "/lib/" + System . getTriple()+ "/omc" + dquote+ " " +
3248- "-Wl,-rpath," + dquote+ Settings . getInstallationDirectoryPath()+ "/lib/" + System . getTriple()+ "/omc" + dquote+ " " +
3249- System . getLDFlags()+ " " );
3318+ ExecStat . execStat("buildModelFMU: Generate the FMI files" );
32503319
3251- if isWindows then
3252- dir := fmutmp + "/sources/" ;
3253- makefileStr := System . readFile(dir + "Makefile.in" );
3254- // replace @XX@ variables in the Makefile
3255- makefileStr := System . stringReplace(makefileStr, "@CC@" , CC );
3256- makefileStr := System . stringReplace(makefileStr, "@CFLAGS@" , CFLAGS );
3257- makefileStr := System . stringReplace(makefileStr, "@LDFLAGS@" , LDFLAGS + System . getRTLibsSim()+ quote);
3258- makefileStr := System . stringReplace(makefileStr, "@LIBS@" , "" );
3259- makefileStr := System . stringReplace(makefileStr, "@DLLEXT@" , ".dll" );
3260- makefileStr := System . stringReplace(makefileStr, "@NEED_RUNTIME@" , "" );
3261- makefileStr := System . stringReplace(makefileStr, "@NEED_DGESV@" , "" );
3262- makefileStr := System . stringReplace(makefileStr, "@FMIPLATFORM@" , System . modelicaPlatform());
3263- makefileStr := System . stringReplace(makefileStr, "@CPPFLAGS@" , "" );
3264- makefileStr := System . stringReplace(makefileStr, " \r\n " , " \n " );
3265- System . writeFile(dir + "Makefile" , makefileStr);
3266- if System . regularFileExists(dir + logfile) then
3267- System . removeFile(dir + logfile);
3268- end if ;
3269- try
3270- CevalScript . compileModel(filenameprefix, libs, workingDir= dir, makeVars= {});
3271- else
3272- outValue := Values . STRING ("" );
3273- return ;
3274- end try ;
3275- System . removeDirectory(fmutmp);
3276- return ;
3277- end if ;
3278-
3279- thisplatform := " CC=" + CC +
3280- " CFLAGS=" + CFLAGS +
3281- " LDFLAGS=" + LDFLAGS ;
3320+ fmutmp := filenameprefix + ".fmutmp" ;
3321+ logfile := filenameprefix + ".log" ;
3322+ dir := fmutmp+ "/sources/" ;
32823323
32833324 for platform in platforms loop
3284- cmd := "cd \" " + fmutmp + "/sources \" && ./configure " +
3285- (if platform == "dynamic" then
3286- " --with-dynamic-om-runtime" + thisplatform+ System . getRTLibsSim()+ quote
3287- elseif platform == "static" then
3288- thisplatform+ quote
3289- else
3290- (
3291- " --host=" + quote+ platform+ quote+
3292- " CFLAGS=" + quote+ "-Os -flto" + quote+ " LDFLAGS=-flto"
3293- )
3294- ) + " && make clean" ;
3295- if System . regularFileExists(logfile) then
3296- System . removeFile(logfile);
3297- end if ;
3298- if 0 <> System . systemCall(cmd, outFile= logfile) then
3299- outValue := Values . STRING ("" );
3300- Error . addMessage(Error . SIMULATOR_BUILD_ERROR , {System . readFile(logfile)});
3301- return ;
3302- end if ;
3325+ configureFMU(platform, fmutmp, logfile, isWindows);
33033326 try
3304- CevalScript . compileModel(filenameprefix, libs, workingDir= fmutmp + "/sources" , makeVars= {});
3327+ CevalScript . compileModel(filenameprefix, libs, workingDir= dir , makeVars= {});
33053328 else
33063329 outValue := Values . STRING ("" );
33073330 Error . addMessage(Error . SIMULATOR_BUILD_ERROR , {System . readFile(logfile)});
3331+ ExecStat . execStat("buildModelFMU failed for platform " + platform);
33083332 return ;
33093333 end try ;
3334+ ExecStat . execStat("buildModelFMU: Generate platform " + platform);
33103335 end for ;
33113336
33123337 System . removeDirectory(fmutmp);
0 commit comments