diff --git a/packages/f/fmi4cpp/patches/0.8.0/clang_fix.patch b/packages/f/fmi4cpp/patches/0.8.0/clang_fix.patch new file mode 100644 index 000000000..ce440050f --- /dev/null +++ b/packages/f/fmi4cpp/patches/0.8.0/clang_fix.patch @@ -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 variables_; + + public: +- model_variables(); +- + explicit model_variables(std::vector 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 variables) + : variables_(std::move(variables)) + {} diff --git a/packages/f/fmi4cpp/patches/0.8.0/win32_zlib.patch b/packages/f/fmi4cpp/patches/0.8.0/win32_zlib.patch new file mode 100644 index 000000000..15042d344 --- /dev/null +++ b/packages/f/fmi4cpp/patches/0.8.0/win32_zlib.patch @@ -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() diff --git a/packages/f/fmi4cpp/xmake.lua b/packages/f/fmi4cpp/xmake.lua new file mode 100644 index 000000000..4fea88c12 --- /dev/null +++ b/packages/f/fmi4cpp/xmake.lua @@ -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 + #include + + 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)