Add Fmi4cpp (#1129)
* Add fmi4cpp * Add support for all platforms * Add syslink to windows * Remove mac support and add patch (broken) * Add git repo as url * Add patch to add zlib link on windows * Remove windows sys link * Renable clang_fix.patch and change checksum? * Add macosx support * Add patch for macosx * Do different patch for macosx * Remove macosx support * Remove windows support * Add config for shared/static and debug buildpull/1181/head
parent
4150f7a79d
commit
d4044d3c95
3 changed files with 127 additions and 0 deletions
@ -0,0 +1,26 @@ |
||||
diff --git a/include/fmi4cpp/fmi2/xml/model_variables.hpp b/include/fmi4cpp/fmi2/xml/model_variables.hpp
|
||||
index 8e3b342..cd70e62 100644
|
||||
--- a/include/fmi4cpp/fmi2/xml/model_variables.hpp
|
||||
+++ b/include/fmi4cpp/fmi2/xml/model_variables.hpp
|
||||
@@ -41,8 +41,6 @@ private:
|
||||
const std::vector<scalar_variable> variables_;
|
||||
|
||||
public:
|
||||
- model_variables();
|
||||
-
|
||||
explicit model_variables(std::vector<scalar_variable> variables);
|
||||
|
||||
[[nodiscard]] size_t size() const;
|
||||
diff --git a/src/fmi4cpp/fmi2/xml/model_variables.cpp b/src/fmi4cpp/fmi2/xml/model_variables.cpp
|
||||
index d262aa9..a6643f7 100644
|
||||
--- a/src/fmi4cpp/fmi2/xml/model_variables.cpp
|
||||
+++ b/src/fmi4cpp/fmi2/xml/model_variables.cpp
|
||||
@@ -30,8 +30,6 @@
|
||||
|
||||
using namespace fmi4cpp::fmi2;
|
||||
|
||||
-model_variables::model_variables() = default;
|
||||
-
|
||||
model_variables::model_variables(std::vector<scalar_variable> variables)
|
||||
: variables_(std::move(variables))
|
||||
{}
|
@ -0,0 +1,27 @@ |
||||
diff --git a/CMakeLists.txt b/CMakeLists.txt
|
||||
index 1656d5a..c207351 100644
|
||||
--- a/CMakeLists.txt
|
||||
+++ b/CMakeLists.txt
|
||||
@@ -62,6 +62,9 @@ endif ()
|
||||
|
||||
find_package(Boost 1.65 COMPONENTS ${Boost_COMPONENTS} REQUIRED)
|
||||
find_package(LIBZIP REQUIRED)
|
||||
+if (WIN32)
|
||||
+ find_package(ZLIB REQUIRED)
|
||||
+endif ()
|
||||
|
||||
|
||||
# ==============================================================================
|
||||
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
|
||||
index bf70918..a6474a6 100644
|
||||
--- a/src/CMakeLists.txt
|
||||
+++ b/src/CMakeLists.txt
|
||||
@@ -112,7 +112,7 @@ target_link_libraries(fmi4cpp
|
||||
)
|
||||
|
||||
if(WIN32)
|
||||
- target_link_libraries(fmi4cpp PRIVATE "Bcrypt")
|
||||
+ target_link_libraries(fmi4cpp PRIVATE "Bcrypt" ZLIB::ZLIB)
|
||||
elseif(UNIX)
|
||||
target_link_libraries(fmi4cpp PRIVATE stdc++fs dl)
|
||||
endif()
|
@ -0,0 +1,74 @@ |
||||
package("fmi4cpp") |
||||
set_homepage("https://github.com/NTNU-IHB/FMI4cpp") |
||||
set_description("A cross-platform FMI 2.0 implementation written in modern C++") |
||||
|
||||
add_urls("https://github.com/NTNU-IHB/FMI4cpp/archive/refs/tags/$(version).tar.gz", |
||||
"https://github.com/NTNU-IHB/FMI4cpp.git") |
||||
add_versions("0.8.0", "78616e9c86a23137a8d3a113fe6420207c3f9ea46442e1c75a01215eb2693bb7") |
||||
|
||||
add_patches("0.8.0", path.join(os.scriptdir(), "patches", "0.8.0", "clang_fix.patch"), "dacd893e90298763223b21b0054dad6d6a82c7c36ab0d3d0cc1984a342c01f9f") |
||||
add_patches("0.8.0", path.join(os.scriptdir(), "patches", "0.8.0", "win32_zlib.patch"), "99d14ebf2f1d7b848ab5fc5b659826d50429e59810f13b25953fddfc8f4313b7") |
||||
|
||||
add_deps("cmake", "boost", "libzip") |
||||
|
||||
on_install("linux", function (package) |
||||
local configs = { |
||||
"-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"), |
||||
"-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release") |
||||
} |
||||
import("package.tools.cmake").install(package, configs) |
||||
end) |
||||
|
||||
on_test(function (package) |
||||
assert(package:check_cxxsnippets({test = [[ |
||||
#include <iostream> |
||||
#include <fmi4cpp/fmi4cpp.hpp> |
||||
|
||||
using namespace fmi4cpp; |
||||
|
||||
const double stop = 10.0; |
||||
const double stepSize = 0.0001; |
||||
|
||||
void test(int argc, char** argv) { |
||||
fmi2::fmu fmu("path/to/fmu.fmu"); |
||||
|
||||
auto cs_fmu = fmu.as_cs_fmu(); |
||||
auto me_fmu = fmu.as_me_fmu(); |
||||
|
||||
auto cs_md = cs_fmu->get_model_description(); //smart pointer to a cs_model_description instance |
||||
std::cout << "model_identifier=" << cs_md->model_identifier << std::endl; |
||||
|
||||
auto me_md = me_fmu->get_model_description(); //smart pointer to a me_model_description instance |
||||
std::cout << "model_identifier=" << me_md->model_identifier << std::endl; |
||||
|
||||
auto var = cs_md->get_variable_by_name("my_var").as_real(); |
||||
std::cout << "Name=" << var.name() << ", start=" << var.start().value_or(0) << std::endl; |
||||
|
||||
auto slave = cs_fmu->new_instance(); |
||||
|
||||
slave->setup_experiment(); |
||||
slave->enter_initialization_mode(); |
||||
slave->exit_initialization_mode(); |
||||
|
||||
double t; |
||||
double value; |
||||
auto vr = var.valueReference(); |
||||
while ( (t = slave->get_simulation_time()) <= stop) { |
||||
|
||||
if (!slave->step(stepSize)) { |
||||
std::cerr << "Error! step() returned with status: " << to_string(slave->last_status()) << std::endl; |
||||
break; |
||||
} |
||||
|
||||
if (!slave->read_real(vr, value)) { |
||||
std::cerr << "Error! step() returned with status: " << to_string(slave->last_status()) << std::endl; |
||||
break; |
||||
} |
||||
std::cout << "t=" << t << ", " << var.name() << "=" << value << std::endl; |
||||
|
||||
} |
||||
|
||||
slave->terminate(); |
||||
} |
||||
]]}, {configs = {languages = "cxx17"}})) |
||||
end) |
Loading…
Reference in new issue