Skip to content

Commit

Permalink
Update typedef element names and platform dir name for FMI3 (#58)
Browse files Browse the repository at this point in the history
  • Loading branch information
filip-stenstrom authored Jun 2, 2023
1 parent 79a98d0 commit 5bd9e46
Show file tree
Hide file tree
Showing 29 changed files with 440 additions and 385 deletions.
25 changes: 16 additions & 9 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,15 +236,22 @@ else(WIN32)
set(FMI_FILE_SEP "/")
endif(WIN32)

set(FMILIB_FMI_PLATFORM_DOC "FMI platform defines the subdirectory within FMU where binary is located")
set(FMILIB_FMI_PLATFORM ”unknown” CACHE STRING ${FMILIB_FMI_PLATFORM_DOC})
if(FMILIB_FMI_PLATFORM MATCHES ”unknown”)
include(fmiplatform)
fmi_platform(FMI_PLATFORM)
set(FMILIB_FMI_PLATFORM ${FMI_PLATFORM} CACHE STRING ${FMILIB_FMI_PLATFORM_DOC} FORCE)
else()
set(FMI_PLATFORM ${FMILIB_FMI_PLATFORM})
endif()
# Sets VARNAME to the user-configured platform name, or auto-detects it based on the
# current platform and provided FMI version.
macro(set_fmi_platform VARNAME FMI_VERSION)
set(FMILIB_FMI_PLATFORM_DOC "The subdirectory in the FMU's binaries directory where the shared library is located")
set(FMILIB_FMI${FMI_VERSION}_PLATFORM unknown CACHE STRING ${FMILIB_FMI_PLATFORM_DOC})
if(FMILIB_FMI${FMI_VERSION}_PLATFORM MATCHES unknown)
include(fmiplatform)
fmi_platform(${VARNAME} ${FMI_VERSION})
set(FMILIB_FMI${FMI_VERSION}_PLATFORM ${${VARNAME}} CACHE STRING ${FMILIB_FMI_PLATFORM_DOC} FORCE)
else()
set(${VARNAME} ${FMILIB_FMI${FMI_VERSION}_PLATFORM})
endif()
endmacro()
set_fmi_platform(FMI1_PLATFORM 1)
set_fmi_platform(FMI2_PLATFORM 2)
set_fmi_platform(FMI3_PLATFORM 3)

configure_file (
"${FMILibrary_SOURCE_DIR}/Config.cmake/config_fmilib.h.cmake"
Expand Down
48 changes: 27 additions & 21 deletions Config.cmake/config_fmilib.h.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,19 @@ It is redefined to "." for Makefile based build environments. Otherwise is set b
#endif

/** \brief Platform folder separator */
#define FMI_FILE_SEP "@FMI_FILE_SEP@"

/** \brief DLL file name suffix(.so, .dll, ...) */
#define FMI_DLL_EXT "@CMAKE_SHARED_LIBRARY_SUFFIX@"

/** \brief Folder name inside FMU in which the DLL is found for this platform */
#define FMI_PLATFORM "@FMI_PLATFORM@"
#define FMI_FILE_SEP "@FMI_FILE_SEP@"

/** \brief DLL file name suffix(.so, .dll, ...) */
#define FMI_DLL_EXT "@CMAKE_SHARED_LIBRARY_SUFFIX@"

/** \brief Folder name inside FMU in which the DLL is found for this platform for FMI 1 */
#define FMI1_PLATFORM "@FMI1_PLATFORM@"

/** \brief Folder name inside FMU in which the DLL is found for this platform for FMI 2 */
#define FMI2_PLATFORM "@FMI2_PLATFORM@"

/** \brief Folder name inside FMU in which the DLL is found for this platform for FMI 3 */
#define FMI3_PLATFORM "@FMI3_PLATFORM@"

/** \brief Folder name inside FMU where binaries are */
#define FMI_BINARIES "binaries"
Expand Down Expand Up @@ -90,20 +96,20 @@ It is redefined to "." for Makefile based build environments. Otherwise is set b
#else
#define FMILIB_EXPORT
#define FMILIB_PRIVATE
#endif
#endif
#else
#if __GNUC__ >= 4
#define FMILIB_EXPORT __attribute__ ((visibility ("default")))
#define FMILIB_PRIVATE __attribute__ ((visibility ("hidden")))
#else
#define FMILIB_EXPORT
#define FMILIB_PRIVATE
#endif
#endif

/** \def FMILIB_EXPORT
\brief Used to declare the public API of the library needed for dynamic linking.
#endif
#endif
#else
#if __GNUC__ >= 4
#define FMILIB_EXPORT __attribute__ ((visibility ("default")))
#define FMILIB_PRIVATE __attribute__ ((visibility ("hidden")))
#else
#define FMILIB_EXPORT
#define FMILIB_PRIVATE
#endif
#endif

/** \def FMILIB_EXPORT
\brief Used to declare the public API of the library needed for dynamic linking.
\def FMILIB_PRIVATE
\brief Intended for declaration of the private library functions.
*/
Expand Down
61 changes: 45 additions & 16 deletions Config.cmake/fmiplatform.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,56 @@
# fmi_platform(platform) sets platform to one of the by FMI defined platforms
# win32, win64, linux32, linux64, darwin32 or darwin64 depending on cmake
# generator
function(fmi_platform platform)
function(fmi_platform platform fmi_version)
if(fmi_version EQUAL 1 OR fmi_version EQUAL 2)
set(FMI_1_OR_2 TRUE)
else()
set(FMI_1_OR_2 FALSE)
endif()
if(CMAKE_HOST_WIN32) #Set to true when the host system is Windows and on cygwin.
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(${platform} win32 PARENT_SCOPE)
else(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(${platform} win64 PARENT_SCOPE)
endif(CMAKE_SIZEOF_VOID_P EQUAL 4)
elseif(CMAKE_HOST_APPLE) #Set to true when the host system is Apple OSX.
if(FMI_1_OR_2)
set(${platform} win32 PARENT_SCOPE)
else()
set(${platform} x86-windows PARENT_SCOPE)
endif()
else()
if(FMI_1_OR_2)
set(${platform} win64 PARENT_SCOPE)
else()
set(${platform} x86_64-windows PARENT_SCOPE)
endif()
endif()
elseif(CMAKE_HOST_APPLE)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(${platform} darwin32 PARENT_SCOPE)
else(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(${platform} darwin64 PARENT_SCOPE)
endif(CMAKE_SIZEOF_VOID_P EQUAL 4)
if(FMI_1_OR_2)
set(${platform} darwin32 PARENT_SCOPE)
else()
set(${platform} x86-darwin PARENT_SCOPE) # Not defined in spec
endif()
else()
if(FMI_1_OR_2)
set(${platform} darwin64 PARENT_SCOPE)
else()
set(${platform} x86_64-darwin PARENT_SCOPE)
endif()
endif()
elseif(CMAKE_HOST_UNIX) #Set to true when the host system is UNIX or UNIX like (i.e. APPLE and CYGWIN).
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(${platform} linux32 PARENT_SCOPE)
else(CMAKE_SIZEOF_VOID_P EQUAL 4)
set(${platform} linux64 PARENT_SCOPE)
endif(CMAKE_SIZEOF_VOID_P EQUAL 4)
else(CMAKE_HOST_WIN32)
if(FMI_1_OR_2)
set(${platform} linux32 PARENT_SCOPE)
else()
set(${platform} x86-linux PARENT_SCOPE)
endif()
else()
if(FMI_1_OR_2)
set(${platform} linux64 PARENT_SCOPE)
else()
set(${platform} x86_64-linux PARENT_SCOPE)
endif()
endif()
else()
message(SEND_ERROR "Target ${platform} is not supported by the tests")
set(${platform} not_supported)
set(${platform} not_supported PARENT_SCOPE)
endif()
endfunction()
10 changes: 5 additions & 5 deletions Config.cmake/runtime_test.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -93,17 +93,17 @@ endfunction()
# @TARGET_NAME_T: The target for building the shared library.
# @XML_PATH_T: The path to the modelDescription that will be zipped.
# @SHARED_LIBRARY_PATH_T: The path to the shared library produced by TARGET_NAME_T.
function(compress_fmu OUTPUT_FOLDER_T MODEL_IDENTIFIER_T FILE_NAME_CS_ME_EXT_T TARGET_NAME_T XML_PATH_T SHARED_LIBRARY_PATH_T)
function(compress_fmu OUTPUT_FOLDER_T MODEL_IDENTIFIER_T FILE_NAME_CS_ME_EXT_T TARGET_NAME_T XML_PATH_T SHARED_LIBRARY_PATH_T FMI_PLATFORM_T)
set(FMU_FILE_NAME_T ${MODEL_IDENTIFIER_T}_${FILE_NAME_CS_ME_EXT_T})
set(FMU_OUTPUT_FOLDER_T ${OUTPUT_FOLDER_T}/${FMU_FILE_NAME_T})
set(FMU_OUTPUT_SHARED_LIBRARY_PATH_T ${FMU_OUTPUT_FOLDER_T}/binaries/${FMI_PLATFORM}/${MODEL_IDENTIFIER_T}${CMAKE_SHARED_LIBRARY_SUFFIX})
set(FMU_OUTPUT_SHARED_LIBRARY_PATH_T ${FMU_OUTPUT_FOLDER_T}/binaries/${FMI_PLATFORM_T}/${MODEL_IDENTIFIER_T}${CMAKE_SHARED_LIBRARY_SUFFIX})

#Must create the FMU directory in a separate command..
if(NOT EXISTS ${FMU_OUTPUT_FOLDER_T}/binaries/${FMI_PLATFORM})
file(MAKE_DIRECTORY ${FMU_OUTPUT_FOLDER_T}/binaries/${FMI_PLATFORM})
if(NOT EXISTS ${FMU_OUTPUT_FOLDER_T}/binaries/${FMI_PLATFORM_T})
file(MAKE_DIRECTORY ${FMU_OUTPUT_FOLDER_T}/binaries/${FMI_PLATFORM_T})
endif()

file(TO_NATIVE_PATH binaries/${FMI_PLATFORM}/${MODEL_IDENTIFIER_T}${CMAKE_SHARED_LIBRARY_SUFFIX} FMU_OUTPUT_SHARED_LIBRARY_PATH_OUT_T)
file(TO_NATIVE_PATH binaries/${FMI_PLATFORM_T}/${MODEL_IDENTIFIER_T}${CMAKE_SHARED_LIBRARY_SUFFIX} FMU_OUTPUT_SHARED_LIBRARY_PATH_OUT_T)

#Move files to the FMU directories and compress # TODO: Why not compress to correct location right away?
add_custom_command(
Expand Down
8 changes: 4 additions & 4 deletions Config.cmake/test_fmi1.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,10 @@ to_native_c_path("\"${CMAKE_CURRENT_BINARY_DIR}/\" CMAKE_INTDIR \"/${CMAKE_SHARE
FMU1_DLL_CS_PATH)

#function(compress_fmu OUTPUT_FOLDER MODEL_IDENTIFIER FILE_NAME_CS_ME_EXT TARGET_NAME XML_PATH SHARED_LIBRARY_PATH)
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU_DUMMY_MF_MODEL_IDENTIFIER}" "mf" "fmu1_dll_me" "${XML_MF_PATH}" "${SHARED_LIBRARY_ME_PATH}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU_DUMMY_ME_MODEL_IDENTIFIER}" "me" "fmu1_dll_me" "${XML_ME_PATH}" "${SHARED_LIBRARY_ME_PATH}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU_DUMMY_CS_MODEL_IDENTIFIER}" "cs" "fmu1_dll_cs" "${XML_CS_PATH}" "${SHARED_LIBRARY_CS_PATH}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU_DUMMY_CS_MODEL_IDENTIFIER}" "cs_tc" "fmu1_dll_cs" "${XML_CS_TC_PATH}" "${SHARED_LIBRARY_CS_PATH}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU_DUMMY_MF_MODEL_IDENTIFIER}" "mf" "fmu1_dll_me" "${XML_MF_PATH}" "${SHARED_LIBRARY_ME_PATH}" "${FMI1_PLATFORM}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU_DUMMY_ME_MODEL_IDENTIFIER}" "me" "fmu1_dll_me" "${XML_ME_PATH}" "${SHARED_LIBRARY_ME_PATH}" "${FMI1_PLATFORM}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU_DUMMY_CS_MODEL_IDENTIFIER}" "cs" "fmu1_dll_cs" "${XML_CS_PATH}" "${SHARED_LIBRARY_CS_PATH}" "${FMI1_PLATFORM}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU_DUMMY_CS_MODEL_IDENTIFIER}" "cs_tc" "fmu1_dll_cs" "${XML_CS_TC_PATH}" "${SHARED_LIBRARY_CS_PATH}" "${FMI1_PLATFORM}")

add_executable(fmi1_variable_bad_type_variability_test ${FMIL_TEST_DIR}/FMI1/fmi1_variable_bad_type_variability_test.c)
target_link_libraries(fmi1_variable_bad_type_variability_test ${FMILIBFORTEST})
Expand Down
6 changes: 3 additions & 3 deletions Config.cmake/test_fmi2.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -61,9 +61,9 @@ set(SHARED_LIBRARY_CS_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${CMA
#Create FMU 2.0 ME/CS Model and generate library path

#function(compress_fmu OUTPUT_FOLDER MODEL_IDENTIFIER FILE_NAME_CS_ME_EXT TARGET_NAME XML_PATH SHARED_LIBRARY_PATH)
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU2_DUMMY_ME_MODEL_IDENTIFIER}" "me" "fmu2_dll_me" "${XML_ME_PATH}" "${SHARED_LIBRARY_ME_PATH}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU2_DUMMY_CS_MODEL_IDENTIFIER}" "cs" "fmu2_dll_cs" "${XML_CS_PATH}" "${SHARED_LIBRARY_CS_PATH}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU2_DUMMY_MF_MODEL_IDENTIFIER}" "mf" "fmu2_dll_cs" "${XML_MF_PATH}" "${SHARED_LIBRARY_CS_PATH}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU2_DUMMY_ME_MODEL_IDENTIFIER}" "me" "fmu2_dll_me" "${XML_ME_PATH}" "${SHARED_LIBRARY_ME_PATH}" "${FMI2_PLATFORM}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU2_DUMMY_CS_MODEL_IDENTIFIER}" "cs" "fmu2_dll_cs" "${XML_CS_PATH}" "${SHARED_LIBRARY_CS_PATH}" "${FMI2_PLATFORM}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "${FMU2_DUMMY_MF_MODEL_IDENTIFIER}" "mf" "fmu2_dll_cs" "${XML_MF_PATH}" "${SHARED_LIBRARY_CS_PATH}" "${FMI2_PLATFORM}")

to_native_c_path("${TEST_OUTPUT_FOLDER}/${FMU2_DUMMY_ME_MODEL_IDENTIFIER}_me.fmu" FMU2_ME_PATH)
to_native_c_path("${TEST_OUTPUT_FOLDER}/${FMU2_DUMMY_CS_MODEL_IDENTIFIER}_cs.fmu" FMU2_CS_PATH)
Expand Down
8 changes: 4 additions & 4 deletions Config.cmake/test_fmi3.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ set(SHARED_LIBRARY_SE_PATH ${CMAKE_CURRENT_BINARY_DIR}/${CMAKE_CFG_INTDIR}/${CMA
#Create FMU 3.0 ME/CS/SE Model and generate library path

#function(compress_fmu OUTPUT_FOLDER MODEL_IDENTIFIER FILE_NAME_CS_ME_EXT TARGET_NAME XML_PATH SHARED_LIBRARY_PATH)
compress_fmu("${TEST_OUTPUT_FOLDER}" "BouncingBall3" "me" "fmu3_dll_me" "${XML_ME_PATH}" "${SHARED_LIBRARY_ME_PATH}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "BouncingBall3" "cs" "fmu3_dll_cs" "${XML_CS_PATH}" "${SHARED_LIBRARY_CS_PATH}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "BouncingBall3" "se" "fmu3_dll_se" "${XML_SE_PATH}" "${SHARED_LIBRARY_SE_PATH}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "BouncingBall3_malformed" "mf" "fmu3_dll_cs" "${XML_MF_PATH}" "${SHARED_LIBRARY_CS_PATH}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "BouncingBall3" "me" "fmu3_dll_me" "${XML_ME_PATH}" "${SHARED_LIBRARY_ME_PATH}" "${FMI3_PLATFORM}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "BouncingBall3" "cs" "fmu3_dll_cs" "${XML_CS_PATH}" "${SHARED_LIBRARY_CS_PATH}" "${FMI3_PLATFORM}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "BouncingBall3" "se" "fmu3_dll_se" "${XML_SE_PATH}" "${SHARED_LIBRARY_SE_PATH}" "${FMI3_PLATFORM}")
compress_fmu("${TEST_OUTPUT_FOLDER}" "BouncingBall3_malformed" "mf" "fmu3_dll_cs" "${XML_MF_PATH}" "${SHARED_LIBRARY_CS_PATH}" "${FMI3_PLATFORM}")

to_native_c_path("${TEST_OUTPUT_FOLDER}/BouncingBall3_me.fmu" FMU3_ME_PATH)
to_native_c_path("${TEST_OUTPUT_FOLDER}/BouncingBall3_cs.fmu" FMU3_CS_PATH)
Expand Down
6 changes: 5 additions & 1 deletion Test/FMI3/fmi3_import_sim_me_test.c
Original file line number Diff line number Diff line change
Expand Up @@ -320,7 +320,11 @@ int main(int argc, char *argv[])

fmi3_import_t* fmu;

FMUPath = FMU3_ME_PATH;
if (argc > 1) {
FMUPath = argv[1]; // Allows testing on any FMU
} else {
FMUPath = FMU3_ME_PATH;
}
tmpPath = FMU_TEMPORARY_TEST_DIR;

callbacks.malloc = malloc;
Expand Down
2 changes: 1 addition & 1 deletion Test/FMI3/fmu_dummy/modelDescription_malformed.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
instantiationToken="123">
<ModelExchange modelIdentifier="BouncingBall3_malformed" />
<TypeDefinitions>
<Float64 name="Modelica.Blocks.Interfaces.RealOutput" />
<Float64Type name="Modelica.Blocks.Interfaces.RealOutput" />
</TypeDefinitions>

<ModelVariables>
Expand Down
2 changes: 1 addition & 1 deletion Test/FMI3/fmu_dummy/modelDescription_me.xml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
instantiationToken="123">
<ModelExchange modelIdentifier="BouncingBall3" />
<TypeDefinitions>
<Float64 name="Modelica.Blocks.Interfaces.RealOutput" />
<Float64Type name="Modelica.Blocks.Interfaces.RealOutput" />
</TypeDefinitions>
<VendorAnnotations>
<Tool name ="JModelica">
Expand Down
8 changes: 4 additions & 4 deletions Test/FMI3/parser_test_xmls/arrays/valid/modelDescription.xml
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@
<CoSimulation modelIdentifier="VariableTypes"/>

<TypeDefinitions>
<Enumeration name="TestEnum">
<EnumerationType name="TestEnum">
<Item name="item1" value="1"/>
<Item name="item2" value="2"/>
<Item name="item3" value="3"/>
</Enumeration>
<Enumeration name="TestEnum2">
</EnumerationType>
<EnumerationType name="TestEnum2">
<Item name="item1" value="55"/>
<Item name="item2" value="-57"/>
</Enumeration>
</EnumerationType>
</TypeDefinitions>

<ModelVariables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
<ModelExchange modelIdentifier="model_identifier"/>

<TypeDefinitions>
<Enumeration name="MyEnum" quantity="TypeQuantity">
<EnumerationType name="MyEnum" quantity="TypeQuantity">
<Item name="item1" value="1"/>
</Enumeration>
</EnumerationType>
</TypeDefinitions>

<ModelVariables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
<ModelExchange modelIdentifier="myModelIdentifier" />

<TypeDefinitions>
<Binary name="td_minimal"/>
<Binary name="td_mimeType" mimeType="mt0"/>
<Binary name="td_allAttr" mimeType="mt0" maxSize="999"/>
<BinaryType name="td_minimal"/>
<BinaryType name="td_mimeType" mimeType="mt0"/>
<BinaryType name="td_allAttr" mimeType="mt0" maxSize="999"/>
</TypeDefinitions>

<ModelVariables>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@
It doesn't make much sense to put intervalVariability on typedefs when they must be
overriden on variables, but the schema files require it.
-->
<Clock name="td_minimal" intervalVariability="constant"/>
<Clock name="td_resolution" intervalVariability="constant" resolution="99"/>
<Clock name="td_allAttr" intervalVariability="countdown" resolution="99"
canBeDeactivated="true" priority="99" intervalDecimal="99.0"
shiftDecimal="99.0" supportsFraction="true" intervalCounter="99"
shiftCounter="99"/>
<ClockType name="td_minimal" intervalVariability="constant"/>
<ClockType name="td_resolution" intervalVariability="constant" resolution="99"/>
<ClockType name="td_allAttr" intervalVariability="countdown" resolution="99"
canBeDeactivated="true" priority="99" intervalDecimal="99.0"
shiftDecimal="99.0" supportsFraction="true" intervalCounter="99"
shiftCounter="99"/>
</TypeDefinitions>

<ModelVariables>
Expand Down
Loading

0 comments on commit 5bd9e46

Please sign in to comment.