Skip to content

Commit

Permalink
Run install before zipping FMU (#10729)
Browse files Browse the repository at this point in the history
* Run install before zipping FMU

  - Renamed FMU custom target `create_zip` to `create_fmu`
  - Ensure that target install is executed before generating zip
  - Test `create_fmu` target
  • Loading branch information
AnHeuermann committed May 24, 2023
1 parent 157f31f commit ef47e87
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 12 deletions.
5 changes: 3 additions & 2 deletions OMCompiler/Compiler/SimCode/SimCode.mo
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,9 @@ uniontype SimCode
SpatialDistributionInfo spatialInfo;
list<JacobianMatrix> jacobianMatrices;
Option<SimulationSettings> simulationSettingsOpt;
String fileNamePrefix, fullPathPrefix "Used in FMI where files are generated in a special directory";
String fmuTargetName;
String fileNamePrefix "Prefix for all enerated C files. Usually the model name with dots replaced by underscores.";
String fullPathPrefix "Used in FMI where files are generated in a special directory";
String fmuTargetName "Name of FMU file <fmuTargetName>.fmu";
HpcOmSimCode.HpcOmData hpcomData;
AvlTreeCRToInt.Tree valueReferences "Used in FMI";
//maps each variable to an array of storage indices (with this information, arrays must not be unrolled) and a list for the array-dimensions
Expand Down
3 changes: 2 additions & 1 deletion OMCompiler/Compiler/SimCode/SimCodeMain.mo
Original file line number Diff line number Diff line change
Expand Up @@ -926,7 +926,8 @@ algorithm
System.copyFile(source = install_share_buildproject_dir + "CMakeLists.txt.in",
destination = fmu_tmp_sources_dir + "CMakeLists.txt");
cmakelistsStr := System.readFile(fmu_tmp_sources_dir + "CMakeLists.txt");
cmakelistsStr := System.stringReplace(cmakelistsStr, "@FMU_NAME_IN@", simCode.fileNamePrefix);
cmakelistsStr := System.stringReplace(cmakelistsStr, "@FMU_NAME_IN@", simCode.fileNamePrefix); // Name with underscored instead of dots
cmakelistsStr := System.stringReplace(cmakelistsStr, "@FMU_TARGET_NAME@", simCode.fmuTargetName); // Name with dots

// Set CMake runtime dependencies level
_ := match (Flags.getConfigString(Flags.FMU_RUNTIME_DEPENDS))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,10 +181,11 @@ else()
endif()

# Zip target creating modelname.fmu
add_custom_target(create_zip COMMAND
${CMAKE_COMMAND} -E tar "cfv" "../${CMAKE_PROJECT_NAME}.fmu" --format=zip
"binaries/"
"resources/"
"sources/"
"modelDescription.xml"
add_custom_target(create_fmu
COMMAND "${CMAKE_COMMAND}" --build ${CMAKE_BINARY_DIR} --target install
COMMAND "${CMAKE_COMMAND}" -E tar "cfv" "../@FMU_TARGET_NAME@.fmu" --format=zip
"binaries/"
"resources/"
"sources/"
"modelDescription.xml"
WORKING_DIRECTORY "${CMAKE_CURRENT_SOURCE_DIR}/../")
4 changes: 2 additions & 2 deletions doc/UsersGuide/source/fmitlm.rst
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ The CMake compilation accepts the following settings:


Then use CMake to configure, build and install the FMU.
To repack the FMU after installation use custom target ``create_zip``.
To repack the FMU after installation use custom target ``create_fmu``.

For example to re-compile the FMU with cmake and runtime dependencies use:

Expand All @@ -176,7 +176,7 @@ For example to re-compile the FMU with cmake and runtime dependencies use:
$ cmake -S . -B build_cmake \
-D RUNTIME_DEPENDENCIES_LEVEL=modelica \
-D CMAKE_C_COMPILER=clang -D CMAKE_CXX_COMPILER=clang++
$ cmake --build build_cmake --target install create_zip --parallel
$ cmake --build build_cmake --target create_fmu --parallel
.. _fmitlm-export-options :

Expand Down
11 changes: 11 additions & 0 deletions testsuite/omsimulator/.gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
*.bin
*.c
*.fmu
*.fmutmp
*.h
*.libs
*.log
*.lua
*.makefile
*.mat
*.xml
DualMassOscillator.CoupledSystem
temp-*/
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// name: RecompileSourceCodeFMU
// keywords: fmu export simulation flags
// status: correct
// teardown_command: rm -rf Test_SinSource* reCompile.log Test.SinSource.fmu
// teardown_command: rm -rf Test_SinSource* Test.SinSource* reCompile.log Test.SinSource.fmu
//
// Export SinSource as 2.0 CS FMU with CVODE solver and re-compile FMU with static library

Expand Down Expand Up @@ -34,6 +34,11 @@ system("cd Test_SinSource_FMU/sources/build_cmake && cmake .. -DBUILD_SHARED_LIB
// Has to return "Test_SinSource_fmi2GetReal"
system("nm Test_SinSource_FMU/binaries/linux64/Test_SinSource.a | grep -wo Test_SinSource_fmi2GetReal"); getErrorString();

// Repack Test.SinSource.fmu
system("rm -rf Test.SinSource.fmu && cd Test_SinSource_FMU/sources/build_cmake && cmake --build . && make create_fmu", outputFile="reCompile.log"); getErrorString();
//readFile("reCompile.log");
regularFileExists("Test.SinSource.fmu"); getErrorString();

// Result:
// true
// ""
Expand All @@ -50,4 +55,8 @@ system("nm Test_SinSource_FMU/binaries/linux64/Test_SinSource.a | grep -wo Test_
// Test_SinSource_fmi2GetReal
// 0
// ""
// 0
// ""
// true
// ""
// endResult

0 comments on commit ef47e87

Please sign in to comment.