Skip to content

Commit e21c945

Browse files
authored
copy external modelicaStandardTable sources to fmu (#13846) (#13885)
1 parent cdf30f0 commit e21c945

File tree

5 files changed

+96
-3
lines changed

5 files changed

+96
-3
lines changed

OMCompiler/Compiler/SimCode/SimCodeMain.mo

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -756,7 +756,7 @@ algorithm
756756
String fileprefix, fileNamePrefixHash;
757757
String install_include_omc_dir, install_include_omc_c_dir, install_share_buildproject_dir, install_fmu_sources_dir, fmu_tmp_sources_dir;
758758
String cmakelistsStr, needCvode, cvodeDirectory;
759-
list<String> sourceFiles, model_desc_src_files, fmi2HeaderFiles;
759+
list<String> sourceFiles, model_desc_src_files, fmi2HeaderFiles, modelica_standard_table_sources;
760760
list<String> dgesv_sources, cminpack_sources, simrt_c_sundials_sources, simrt_linear_solver_sources, simrt_non_linear_solver_sources;
761761
list<String> simrt_mixed_solver_sources, fmi_export_files, model_gen_files, model_all_gen_files, shared_source_files;
762762
SimCode.VarInfo varInfo;
@@ -908,6 +908,18 @@ algorithm
908908
*/
909909
fmi2HeaderFiles := {"fmi/fmi2Functions.h","fmi/fmi2FunctionTypes.h", "fmi/fmi2TypesPlatform.h", "fmi/fmiModelFunctions.h", "fmi/fmiModelTypes.h"};
910910
copyFiles(fmi2HeaderFiles, source=install_include_omc_c_dir, destination=fmu_tmp_sources_dir);
911+
/*
912+
* fix issue fhttps://github.com/OpenModelica/OpenModelica/issues/13260
913+
* Check if modelicaStandardTables source files are needed
914+
* this is not clear as of now, may be we should copy all the external C sources by default
915+
*/
916+
if not listEmpty(simCode.makefileParams.libs) and listMember("-lModelicaStandardTables", simCode.makefileParams.libs) then
917+
copyFiles(RuntimeSources.modelica_external_c_sources, source=install_include_omc_c_dir, destination=fmu_tmp_sources_dir);
918+
copyFiles(RuntimeSources.modelica_external_c_headers, source=install_include_omc_c_dir, destination=fmu_tmp_sources_dir);
919+
modelica_standard_table_sources := RuntimeSources.modelica_external_c_sources;
920+
else
921+
modelica_standard_table_sources := {};
922+
end if;
911923

912924
System.writeFile(fmutmp+"/sources/isfmi" + (if FMUVersion=="1.0" then "1" else "2"), "");
913925

@@ -928,7 +940,8 @@ algorithm
928940
shared_source_files,
929941
dgesv_sources,
930942
cminpack_sources,
931-
simrt_c_sundials_sources
943+
simrt_c_sundials_sources,
944+
modelica_standard_table_sources
932945
});
933946
end if;
934947

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/* ModelicaStandardTablesDummyUsertab.c - A dummy usertab function
2+
3+
Copyright (C) 2013-2020, Modelica Association and contributors
4+
All rights reserved.
5+
6+
Redistribution and use in source and binary forms, with or without
7+
modification, are permitted provided that the following conditions are met:
8+
9+
1. Redistributions of source code must retain the above copyright notice,
10+
this list of conditions and the following disclaimer.
11+
12+
2. Redistributions in binary form must reproduce the above copyright
13+
notice, this list of conditions and the following disclaimer in the
14+
documentation and/or other materials provided with the distribution.
15+
16+
3. Neither the name of the copyright holder nor the names of its
17+
contributors may be used to endorse or promote products derived from
18+
this software without specific prior written permission.
19+
20+
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
21+
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
22+
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23+
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24+
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25+
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26+
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27+
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28+
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29+
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30+
*/
31+
32+
/* The usertab function needs to be in a separate object or clang/gcc
33+
optimize the code in such a way that the user-defined usertab gets
34+
sent the wrong input.
35+
36+
NOTE: If a dummy usertab is included in your code, you may be unable
37+
to also provide a user-defined usertab. If you use dynamic linking
38+
this is sometimes possible: when the simulation executable provides
39+
a usertab object, it will be part of the table of loaded objects and
40+
when later loading the shared object version of ModelicaStandardTables,
41+
the dummy usertab will not be loaded by the dynamic linker; this is
42+
what can confuse C-compilers and why this function is in a separate
43+
file).
44+
45+
The interface of usertab is defined in ModelicaStandardTables.c
46+
*/
47+
48+
/*
49+
when compiling from the sources we need to have the usertab() function defined
50+
otherwise we get unresolved symbols and linking errors from ModelicaStandardTables.c
51+
The below function does not check anything and this function can be overridden.
52+
*/
53+
int usertab(char* tableName, int nipo, int dim[], int* colWise, double** table) {
54+
return 0;
55+
}

OMCompiler/SimulationRuntime/c/Makefile.common

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,11 +356,14 @@ clean:
356356
(! test -f $(EXTERNALCBUILDDIR)/Makefile) || make -C $(EXTERNALCBUILDDIR) clean
357357
(! test -f $(EXTERNALCBUILDDIR)/Makefile) || make -C $(EXTERNALCBUILDDIR) distclean
358358

359-
sourcedist: sourcedist1 sourcedist2
359+
sourcedist: sourcedist1 sourcedist2 sourcedist3
360360
sourcedist1:
361361
$(MAKE) -f $(LIBMAKEFILE) OMC_MINIMAL_RUNTIME=1 OMC_FMI_RUNTIME=1 sourcedist_internal
362362
sourcedist2:
363363
$(MAKE) -C ../fmi/export/buildproject -f $(defaultMakefileTarget)
364+
sourcedist3:
365+
mkdir -p $(builddir_inc)/c/ModelicaExternalC
366+
cp -p ../ModelicaExternalC/C-Sources/*.h ../ModelicaExternalC/C-Sources/*.c $(builddir_inc)/c/ModelicaExternalC
364367

365368
# Copied files need to preserve the time-stamp or the external solvers builds
366369
# over and over again

OMCompiler/SimulationRuntime/c/RuntimeSources.mo.cmake

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ encapsulated package RuntimeSources
3030

3131
constant list<String> simrt_c_sundials_sources={@SOURCE_FMU_CVODE_RUNTIME_FILES@};
3232

33+
constant list<String> modelica_external_c_sources={"ModelicaExternalC/ModelicaStandardTables.c",
34+
"ModelicaExternalC/ModelicaMatIO.c",
35+
"ModelicaExternalC/ModelicaIO.c",
36+
"ModelicaExternalC/ModelicaStandardTablesDummyUsertab.c"};
37+
38+
constant list<String> modelica_external_c_headers={"ModelicaExternalC/ModelicaStandardTables.h",
39+
"ModelicaExternalC/ModelicaMatIO.h",
40+
"ModelicaExternalC/ModelicaIO.h",
41+
"ModelicaExternalC/safe-math.h",
42+
"ModelicaExternalC/read_data_impl.h"};
43+
3344
constant list<String> dgesv_headers={"./external_solvers/blaswrap.h", "./external_solvers/clapack.h", "./external_solvers/f2c.h"};
3445

3546
constant list<String> dgesv_sources={@SOURCE_FMU_DGESV_FILES@};

OMCompiler/SimulationRuntime/c/RuntimeSources.mo.tpl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,17 @@ encapsulated package RuntimeSources
2626
constant list<String> simrt_c_sundials_sources={"simulation/solver/cvode_solver.c",
2727
"simulation/solver/sundials_error.c"};
2828

29+
constant list<String> modelica_external_c_sources={"ModelicaExternalC/ModelicaStandardTables.c",
30+
"ModelicaExternalC/ModelicaMatIO.c",
31+
"ModelicaExternalC/ModelicaIO.c",
32+
"ModelicaExternalC/ModelicaStandardTablesDummyUsertab.c"};
33+
34+
constant list<String> modelica_external_c_headers={"ModelicaExternalC/ModelicaStandardTables.h",
35+
"ModelicaExternalC/ModelicaMatIO.h",
36+
"ModelicaExternalC/ModelicaIO.h",
37+
"ModelicaExternalC/safe-math.h",
38+
"ModelicaExternalC/read_data_impl.h"};
39+
2940
constant list<String> dgesv_headers={"./external_solvers/blaswrap.h", "./external_solvers/clapack.h", "./external_solvers/f2c.h"};
3041
constant list<String> dgesv_sources={DGESV_FILES};
3142

0 commit comments

Comments
 (0)