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

Commit a32b622

Browse files
adrpoOpenModelica-Hudson
authored andcommitted
Fix FMU build on Windows and other FMU fixes
- use fmuTargetName instead of fileNamePrefix to remove the fmu - use rm -f if System.removeDirectory doesn't work on Windows - compile with static libstdc++ and pthreads - don't add extra dlls to the binary directory - fix resource copy on Windows Belonging to [master]: - #2568
1 parent 8089bfd commit a32b622

File tree

7 files changed

+47
-30
lines changed

7 files changed

+47
-30
lines changed

Compiler/Script/CevalScriptBackend.mo

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3537,14 +3537,14 @@ algorithm
35373537
ExecStat.execStat("buildModelFMU: Generate platform " + platform);
35383538
end for;
35393539

3540-
cmd := "rm -f \"" + filenameprefix + ".fmu\" && cd \"" + fmutmp + "\" && zip -r \"../" + fmuTargetName + ".fmu\" *";
3540+
cmd := "rm -f \"" + fmuTargetName + ".fmu\" && cd \"" + fmutmp + "\" && zip -r \"../" + fmuTargetName + ".fmu\" *";
35413541
if 0 <> System.systemCall(cmd, outFile=logfile) then
35423542
Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {cmd + "\n\n" + System.readFile(logfile)});
35433543
ExecStat.execStat("buildModelFMU failed");
35443544
end if;
35453545

35463546
if not System.regularFileExists(fmuTargetName + ".fmu") then
3547-
Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {"Build commands returned success, but " + filenameprefix + ".fmu does not exist"});
3547+
Error.addMessage(Error.SIMULATOR_BUILD_ERROR, {"Build commands returned success, but " + fmuTargetName + ".fmu does not exist"});
35483548
fail();
35493549
end if;
35503550

Compiler/SimCode/SimCodeMain.mo

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -660,23 +660,28 @@ algorithm
660660
setGlobalRoot(Global.optionSimCode, SOME(simCode));
661661
_ := match (simCode,target)
662662
local
663-
String str, newdir, newpath, resourcesDir;
663+
String str, newdir, newpath, resourcesDir, dirname;
664664
String fmutmp;
665665
Boolean b;
666666
case (SimCode.SIMCODE(),"C")
667667
algorithm
668668
fmutmp := simCode.fileNamePrefix + ".fmutmp";
669669
if System.directoryExists(fmutmp) then
670670
if not System.removeDirectory(fmutmp) then
671-
print("Failed to remove directory: " + fmutmp + "\n");
671+
Error.addInternalError("Failed to remove directory: " + fmutmp, sourceInfo());
672672
fail();
673673
end if;
674674
end if;
675675
Util.createDirectoryTree(fmutmp + "/sources/include/");
676676
Util.createDirectoryTree(fmutmp + "/resources/");
677677
resourcesDir := fmutmp + "/resources/";
678678
for path in simCode.modelInfo.resourcePaths loop
679-
newdir := resourcesDir + System.dirname(path);
679+
dirname := System.dirname(path);
680+
// on windows, remove ":" from the path!
681+
if System.os() == "Windows_NT" then
682+
dirname := System.stringReplace(dirname, ":", "");
683+
end if;
684+
newdir := resourcesDir + dirname;
680685
newpath := resourcesDir + path;
681686
if System.regularFileExists(newpath) or System.directoryExists(newpath) then
682687
/* Already copied. Maybe one resource loaded a library and this one only a file in the directory */
@@ -685,7 +690,7 @@ algorithm
685690
Util.createDirectoryTree(newdir);
686691
// copy the file or directory
687692
if 0 <> System.systemCall("cp -rf \"" + path + "\" \"" + newdir + "/\"") then
688-
Error.addInternalError("Failed to copy path " + path + " to " + fmutmp + "/resources/" + System.dirname(path), sourceInfo());
693+
Error.addInternalError("Failed to copy path " + path + " to " + fmutmp + "/resources/" + dirname, sourceInfo());
689694
end if;
690695
end for;
691696
SerializeModelInfo.serialize(simCode, Flags.isSet(Flags.INFO_XML_OPERATIONS));

Compiler/Template/CodegenFMU.tpl

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1145,27 +1145,14 @@ match platform
11451145
case "win32"
11461146
case "win64" then
11471147
<<
1148-
<%fileNamePrefix%>_FMU: $(MAINOBJ) <%fileNamePrefix%>_functions.h <%fileNamePrefix%>_literals.h $(OFILES) $(RUNTIMEFILES)
1148+
<%fileNamePrefix%>_FMU: nozip
1149+
<%\t%>cd .. && rm -f ../<%fileNamePrefix%>.fmu && zip -r ../<%fmuTargetName%>.fmu *
1150+
nozip: $(MAINOBJ) <%fileNamePrefix%>_functions.h <%fileNamePrefix%>_literals.h $(OFILES) $(RUNTIMEFILES)
11491151
<%\t%>$(CXX) -shared -I. -o <%modelNamePrefix%>$(DLLEXT) $(MAINOBJ) $(RUNTIMEFILES) $(OFILES) $(CPPFLAGS) <%dirExtra%> <%libsPos1%> <%libsPos2%> $(CFLAGS) $(LDFLAGS) -llis -Wl,--kill-at
11501152
<%\t%>mkdir.exe -p ../binaries/<%platform%>
11511153
<%\t%>dlltool -d <%fileNamePrefix%>.def --dllname <%fileNamePrefix%>$(DLLEXT) --output-lib <%fileNamePrefix%>.lib --kill-at
11521154
<%\t%>cp <%fileNamePrefix%>$(DLLEXT) <%fileNamePrefix%>.lib <%fileNamePrefix%>_FMU.libs ../binaries/<%platform%>/
1153-
<%\t%>cp <%omhome%>/bin/libsundials_*.dll ../binaries/<%platform%>/
1154-
<%\t%>cp <%omhome%>/bin/libopenblas.dll ../binaries/<%platform%>/
1155-
<%\t%>cp <%omhome%>/bin/libexpat*.dll ../binaries/<%platform%>/
1156-
<%\t%>cp <%omhome%>/bin/libgfortran*.dll ../binaries/<%platform%>/
1157-
<%\t%>cp <%omhome%>/bin/libquadmath*.dll ../binaries/<%platform%>/
1158-
<%\t%>cp <%omhome%>/bin/libwinpthread*.dll ../binaries/<%platform%>/
1159-
<%\t%>cp <%omhome%>/bin/zlib*.dll ../binaries/<%platform%>/
1160-
<%\t%>cp <%omhome%>/bin/libszip*.dll ../binaries/<%platform%>/
1161-
<%\t%>cp <%omhome%>/bin/libhdf5*.dll ../binaries/<%platform%>/
1162-
<%\t%>cp <%omhome%>/bin/libsystre*.dll ../binaries/<%platform%>/
1163-
<%\t%>cp <%omhome%>/bin/libtre*.dll ../binaries/<%platform%>/
1164-
<%\t%>cp <%omhome%>/bin/libintl*.dll ../binaries/<%platform%>/
1165-
<%\t%>cp <%omhome%>/bin/libiconv*.dll ../binaries/<%platform%>/
1166-
<%\t%>cp <%omhome%>/bin/libgcc_s_*.dll ../binaries/<%platform%>/
1167-
<%\t%>cp <%omhome%>/bin/libstdc*.dll ../binaries/<%platform%>/
1168-
<%\t%>rm -f <%fileNamePrefix%>.def <%fileNamePrefix%>.o <%fileNamePrefix%>$(DLLEXT) $(OFILES) $(RUNTIMEFILES)
1155+
<%\t%>rm -f *.o <%fileNamePrefix%>$(DLLEXT) $(OFILES) $(RUNTIMEFILES)
11691156
<%\t%>cd .. && rm -f ../<%fileNamePrefix%>.fmu && zip -r ../<%fmuTargetName%>.fmu *
11701157

11711158
>>

Compiler/Util/System.mo

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -482,12 +482,27 @@ public function directoryExists
482482
external "C" outBool=SystemImpl__directoryExists(inString) annotation(Library = "omcruntime");
483483
end directoryExists;
484484

485+
485486
public function removeDirectory
486487
input String inString;
487488
output Boolean outBool;
488-
external "C" outBool=SystemImpl__removeDirectory(inString) annotation(Library = "omcruntime");
489+
algorithm
490+
outBool := System.removeDirectory_dispatch(inString);
491+
// oh Windows crap: stat fails on very long paths!
492+
if (not outBool) then
493+
if System.os() == "Windows_NT" then
494+
// try rm as that somehow works on long paths
495+
outBool := (0 == System.systemCall("rm -r " + inString));
496+
end if;
497+
end if;
489498
end removeDirectory;
490499

500+
protected function removeDirectory_dispatch
501+
input String inString;
502+
output Boolean outBool;
503+
external "C" outBool=SystemImpl__removeDirectory(inString) annotation(Library = "omcruntime");
504+
end removeDirectory_dispatch;
505+
491506
public function platform
492507
output String outString;
493508
external "C" outString=System_platform() annotation(Library = "omcruntime");

Compiler/runtime/omc_config.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@
8383
#define DEFAULT_MAKE "make"
8484

8585
/* adrpo: add -loleaut32 as is used by ExternalMedia */
86-
#define DEFAULT_LDFLAGS "-lregex -lexpat -lomcgc -lpthread -fopenmp -loleaut32 -limagehlp -lz -lhdf5"
86+
#define DEFAULT_LDFLAGS "-lregex -lexpat -lomcgc -Wl,-Bstatic -lpthread -Wl,-Bdynamic -fopenmp -loleaut32 -limagehlp -lz -lhdf5"
8787

8888

8989
#define CONFIG_WITH_OPENMP 1
@@ -96,10 +96,10 @@
9696
#endif
9797

9898
/* adrpo: add -loleaut32 as is used by ExternalMedia */
99-
#define BASIC_LDFLAGS_RT " -lomcgc -lexpat -lregex -static-libgcc -luuid -loleaut32 -lole32 -limagehlp -lws2_32 -llis -lumfpack -lklu -lcolamd -lbtf -lamd -lsundials_idas -lsundials_kinsol -lsundials_nvecserial -lipopt -lcoinmumps -lpthread -lm -lgfortranbegin -lgfortran -lmingw32 -lgcc_eh -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lopenblas -lcminpack"
99+
#define BASIC_LDFLAGS_RT " -lomcgc -lexpat -lregex -static-libgcc -luuid -loleaut32 -lole32 -limagehlp -lws2_32 -llis -lumfpack -lklu -lcolamd -lbtf -lamd -lsundials_idas -lsundials_kinsol -lsundials_nvecserial -lipopt -lcoinmumps -Wl,-Bstatic -lpthread -Wl,-Bdynamic -lm -lgfortranbegin -lgfortran -lmingw32 -lgcc_eh -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -lopenblas -lcminpack"
100100
#define LDFLAGS_RT " -lOpenModelicaRuntimeC" BASIC_LDFLAGS_RT
101-
#define LDFLAGS_RT_SIM " -lSimulationRuntimeC" BASIC_LDFLAGS_RT " -lwsock32 -lstdc++"
102-
#define LDFLAGS_RT_SOURCE_FMU " -lregex -static-libgcc -lpthread -lm -lgfortranbegin -lgfortran -lmingw32 -lgcc_eh -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -limagehlp -lopenblas -lz -lhdf5"
101+
#define LDFLAGS_RT_SIM " -lSimulationRuntimeC" BASIC_LDFLAGS_RT " -lwsock32 -static-libstdc++"
102+
#define LDFLAGS_RT_SOURCE_FMU " -lregex -static-libgcc -Wl,-Bstatic -lpthread -Wl,-Bdynamic -lm -lgfortranbegin -lgfortran -lmingw32 -lgcc_eh -lmoldname -lmingwex -lmsvcrt -luser32 -lkernel32 -ladvapi32 -lshell32 -limagehlp -lopenblas -lz -lhdf5"
103103
#define CONFIG_EXE_EXT ".exe"
104104
#define CONFIG_DLL_EXT ".dll"
105105
#define CONFIG_OS "Windows_NT"

SimulationRuntime/c/Makefile.common

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
# If you need to add files, etc, you modify Makefile.common - a common file
55
# for both UNIX/Linux and Windows platforms.
66

7+
BUILDPATH=build/c
8+
79
# Forces the generation of the dgesv sources
810
NEED_DGESV=1
911
include Makefile.objs
1012

1113
LIBSIMULATIONFMI=libSimulationRuntimeFMI.a
1214
OMC_MINIMAL_RUNTIME=
13-
BUILDPATH=build/c
1415

1516
CPPFLAGS = -I. -I$(top_builddir)/Compiler/runtime -I$(top_builddir)/3rdParty/gc/include -I$(top_builddir)/3rdParty/FMIL/install/include/ -I$(top_builddir)/3rdParty/lis-1.4.12/include/ -I$(top_builddir)/3rdParty/Ipopt/include/ -I$(builddir_inc)/c/sundials/ $(CONFIG_CPPFLAGS) -DGC_REDIRECT_TO_LOCAL -I$(builddir_inc)/c
1617
override CFLAGS += $(CPPFLAGS) $(CONFIG_CFLAGS) $(EXTRA_CFLAGS)

SimulationRuntime/c/Makefile.omdev.mingw

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,18 @@ CONFIG_H=$(top_builddir)/Compiler/runtime/config.h
3232
LIBSIMULATION=libSimulationRuntimeC.a
3333
LIBRUNTIME=libOpenModelicaRuntimeC.a
3434
LIBFMIRUNTIME=libOpenModelicaFMIRuntimeC.a
35-
OBJ_EXT=.o
3635
CMINPACK_NO_DLL=-DCMINPACK_NO_DLL
3736

37+
ifeq ($(OMC_MINIMAL_RUNTIME),)
38+
OBJ_EXT=.o
39+
else
40+
ifeq ($(OMC_FMI_RUNTIME),)
41+
OBJ_EXT=.minimal.o
42+
else
43+
OBJ_EXT=.o
44+
endif
45+
endif
46+
3847
defaultMakefileTarget = Makefile.omdev.mingw
3948

4049
include Makefile.common

0 commit comments

Comments
 (0)