diff --git a/CMakeLists.txt b/CMakeLists.txt index 7e817f0a..af80b753 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,11 +15,17 @@ option(LIBCOSIM_BUILD_PRIVATE_APIDOC "Build private API documentation (only used option(LIBCOSIM_STANDALONE_INSTALLATION "Whether to build for a standalone installation (Linux only; sets a relative RPATH)" OFF) option(LIBCOSIM_USING_CONAN "Whether Conan is used for package management" OFF) option(LIBCOSIM_WITH_PROXYFMU "Whether or not to build with proxy-fmu integration" OFF) +option(LIBCOSIM_NO_FMI_LOGGING "Disable FMI logging during simulation" OFF) # ============================================================================== # Global internal configuration # ============================================================================== +# Configure logging in the fmi callback function +if(LIBCOSIM_NO_FMI_LOGGING) + add_compile_definitions(LIBCOSIM_NO_FMI_LOGGING=1) +endif() + # Our custom CMake scripts go in the cmake/ subdirectory. list(INSERT CMAKE_MODULE_PATH 0 "${CMAKE_SOURCE_DIR}/cmake") diff --git a/conanfile.py b/conanfile.py index 41f0fbf5..936aad68 100755 --- a/conanfile.py +++ b/conanfile.py @@ -29,10 +29,12 @@ class LibcosimConan(ConanFile): options = { "shared": [True, False], - "proxyfmu": [True, False]} + "proxyfmu": [True, False], + "no_fmi_logging": [True, False]} default_options = ( "proxyfmu=False", - "shared=True" + "shared=True", + "no_fmi_logging=False" ) def is_tests_enabled(self): @@ -65,6 +67,7 @@ def configure_cmake(self): cmake.definitions["LIBCOSIM_BUILD_APIDOC"] = "OFF" cmake.definitions["LIBCOSIM_BUILD_TESTS"] = self.is_tests_enabled() cmake.definitions["BUILD_SHARED_LIBS"] = self.options.shared + cmake.definitions["LIBCOSIM_NO_FMI_LOGGING"] = self.options.no_fmi_logging if self.options.proxyfmu: cmake.definitions["LIBCOSIM_WITH_PROXYFMU"] = "ON" cmake.configure() diff --git a/src/cosim/fmi/v1/fmu.cpp b/src/cosim/fmi/v1/fmu.cpp index 2ac3d04c..2ebe18db 100644 --- a/src/cosim/fmi/v1/fmu.cpp +++ b/src/cosim/fmi/v1/fmu.cpp @@ -186,12 +186,20 @@ std::mutex g_logMutex; void log_message( fmi1_component_t, +#ifndef LIBCOSIM_NO_FMI_LOGGING fmi1_string_t instanceName, fmi1_status_t status, fmi1_string_t category, fmi1_string_t message, +#else + fmi1_string_t, + fmi1_status_t, + fmi1_string_t, + fmi1_string_t, +#endif ...) { +#ifndef LIBCOSIM_NO_FMI_LOGGING std::va_list args; va_start(args, message); const auto msgLength = std::vsnprintf(nullptr, 0, message, args); @@ -242,6 +250,7 @@ void log_message( g_logRecords[instanceName] = log_record{status, std::string(msgBuffer.data())}; g_logMutex.unlock(); +#endif } log_record last_log_record(const std::string& instanceName) diff --git a/src/cosim/fmi/v2/fmu.cpp b/src/cosim/fmi/v2/fmu.cpp index c51b3dd8..3992a562 100644 --- a/src/cosim/fmi/v2/fmu.cpp +++ b/src/cosim/fmi/v2/fmu.cpp @@ -186,12 +186,20 @@ std::mutex g_logMutex; void log_message( fmi2_component_environment_t, +#ifndef LIBCOSIM_NO_FMI_LOGGING fmi2_string_t instanceName, fmi2_status_t status, fmi2_string_t category, fmi2_string_t message, +#else + fmi2_string_t, + fmi2_status_t, + fmi2_string_t, + fmi2_string_t, +#endif ...) { +#ifndef LIBCOSIM_NO_FMI_LOGGING std::va_list args; va_start(args, message); const auto msgLength = std::vsnprintf(nullptr, 0, message, args); @@ -242,6 +250,7 @@ void log_message( g_logRecords[instanceName] = log_record{status, std::string(msgBuffer.data())}; g_logMutex.unlock(); +#endif } log_record last_log_record(const std::string& instanceName)