- 30 August 2012
FMI library is intended as a foundation for applications interfacing FMUs (Functional Mockup Units) that follow FMI Standard. See <http://functional-mockup-interface.org/>
The test codes provided with the library can serve as starting point for the development of custom applications. See Section Automatic tests for details.
Configuring and building
CMake (see <http://www.cmake.org/>) is used to generate the native build scripts for the library. It is recommended to use "cmake-gui" on Windows or "ccmake <FMIL source dir>" to configure the build.
To build from a terminal command line on Linux or Mac with default settings use:
mkdir build-fmil; cd build-fmil
cmake <path to FMI
make install test
To build in MSYS terminal with g++/gcc on Windows:
mkdir build-fmil; cd build-fmil
cmake -G "MSYS Makefiles" <path to FMIL source>
make install test
The primary targets of the library build script are:
The include file to be used in client applications.
- Library files under <prefix>/lib/
Static library is named 'fmilib' and shared library 'fmilib_shared'. The prefix/suffix of the library files differ depending on the platform. Note that if you have configure and built both static and shared library on Windows but want to link with the static library compile time define "FMILIB_BUILDING_LIBRARY" must be set.
- Doxygen generated documentation under <prefix>/doc/. Note that documentation is not generated as part of install target and you need to build the 'doc' target separately, i.e., run 'make doc' or explicitly build the project in Visual Studio.
The following build configuration options are provided:
- FMILIB_INSTALL_PREFIX - prefix prepended to install directories.
This is the main install directory name. Include files will be located in the "include" subdirectory and library files in the "lib" subdirectory. Client applications should only include "fmilib.h"
- FMILIB_THIRDPARTYLIBS - thirdparty libaries are currently shipped with the library.
- FMILIB_FMI_STANDARD_HEADERS - Path to the FMI standard headers directory. Header for specific standards files are expected in subdirectories FMI1, FMI2, etc.
- FMILIB_DEFAULT_BUILD_TYPE_RELEASE - Controls build-type used for Makefile generation.
If this option is on then 'Release' mode compile flags are used. Otherwize, 'Debug' mode flags are generated into the Makefile. The option may be overwritten by explicitly setting CMAKE_BUILD_TYPE.
- FMILIB_BUILD_WITH_STATIC_RTLIB Use static run-time libraries (/MT or /MTd code generation flags).
This is only used when generating Microsoft Visual Studio solutions. If the options is on then the library will be built against static runtime, otherwise - dynamic runtime (/MD or /MDd). Make sure the client code is using matching runtime.
- FMILIB_BUILD_STATIC_LIB Build the library as static.
'fmilib' may be used for static linking.
- FMILIB_BUILD_SHARED_LIB Build the library as shared (dll/so/dylib).
'fmilib_shared' may be used for dynamic linking.
- FMILIB_FMI_PLATFORM - FMI platform defines the subdirectory within FMU where binary is located.
The build system will automatically detect win32, win64, linux32, linux64, darwin32, darwin64.
- FMILIB_BUILD_FOR_SHARED_LIBS The static library 'fmilib' can be linked into shared libraries.
On LINUX position independent code (-fPIC) must be used on all files to be linked into a shared library (.so file). On other systems this is not needed (either is default or relocation is done). Set this option to OFF if you are building an application on Linux and use static library only.
- FMILIB_ENABLE_LOG_LEVEL_DEBUG Enable log level 'debug'.
If the option is OFF then the debug level messages are not compiled in.
- FMILIB_GENERATE_DOXYGEN_DOC Enable doxygen target.
You need Doxygen to be installed on the system for this option to have an effect.
- FMILIB_BUILD_TESTS Enable build of the tests supplied with the library.
RUN_TESTS - target will be provided in Visual Studio. 'make test' will run tests on Makefile based platforms.
- FMILIB_BUILD_BEFORE_TESTS Force build before testing, i.e., building the FMI library becomes the first test.
- FMILIB_LINK_TEST_TO_SHAREDLIB Link the tests to fmilib_shared (if built) instead of static fmilib.
The FMI library comes with a number of automatic tests. Building of the test is controlled by FMILIB_BUILD_TESTS configuration option. The test porgrams are also intended as examples of library usage.
The tests can be run in Visual Studio by building project RUN_TESTS. For Makefile based configurations (MSYS, Linux, Mac OSx) run 'make test'.
Output from the test programs and test logs can be found in the testfolder and Testing folders in the build directory.
The supplied tests are:
Build the library. This test is controlled by FMILIB_BUILD_BEFORE_TESTS configuration option.
Load a basic model exchange FMU and simulate it. Test executable is fmi_import_me_test, main source file is fmi_import_me_test.c.
Load a basic co-simulation FMU and simulate it. Test executable is fmi_import_cs_test, main source file is fmi_import_cs_test.c.
Load a small model description XML file and print out detailed information on it. Test executable is fmi_import_xml_text, main source file is fmi_import_xml_test.cc. This test depends on the success of the ctest_fmi_import_cs_test.
Basic unzip functionality test. Test executable is fmi_zip_unzip_test.
Basic zip functionality test. Test executable is fmi_zip_zip_test.
Low level test of FMI CAPI functionality for co-simulation. Test executable is fmi1_capi_cs_test.
Low level test of FMI CAPI functionality for model exchange. Test executable is fmi1_capi_me_test.
Run logger test generating output fmi1_logger_test_output.txt. Test executable is fmi1_logger_test.
Check that the logger test output generated by ctest_fmi1_logger_test_run is identical with the reference file found in the Test subdirectory.
In the text below we consider an FMU importing application (referenced as an 'application') that uses the FMIL. The library is designed to send log messages to a logger callback function jm_logger_f provided as a part of jm_callbacks structure in the call to fmi_import_allocate_context(). The logging/error reporting functions within FMIL support following modes:
- An importing application relies on default logging functions provided by FMIL and only chooses the log-level
- An application provides a callback for reporting error messages according to jm_callbacks.h (jm_logger_f)
- Only errors from FMIL can be propagated to this callback in a thread-safe manner for FMI1. Imported FMUs may still use the default callback provided by the library. This is since logger function in FMI 1.0 standard is context independent. The non-thread safe implementation on the FMI1 callback can be found in fmi1_import_convenience.h fmi1_log_forwarding().
In FMI 2 we will be able to utilize fmiComponentEnvironment to forward messages from the default fmi2 logger function as provided by the library to the use defined jm_logger_f function. The default implementation can take care of replacing variable names, etc.
- An importing application provides logging function according to the specific FMI standard version.
- An importing application may choose not to use logging function but rely on return codes and jm_get_last_error()
- jm_logger function should be set to NULL
- Errors from a FMI 1.0 fmu1 cannot be handled this way in a thread-safe way (see point 2 above). It will work fine with FMI 2.0.
- (C) 2012 Modelon AB
Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
- Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
- Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
- Neither the name of the Modelon AB nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL MODELON AB BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The FMI Library utilizes contains code from third party tools and packages. The respective copyright information and licenses are listed with URL references to the full texts.