xmake.lua 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. package("fmi4cpp")
  2. set_homepage("https://github.com/NTNU-IHB/FMI4cpp")
  3. set_description("A cross-platform FMI 2.0 implementation written in modern C++")
  4. add_urls("https://github.com/NTNU-IHB/FMI4cpp/archive/refs/tags/$(version).tar.gz",
  5. "https://github.com/NTNU-IHB/FMI4cpp.git")
  6. add_versions("0.8.0", "78616e9c86a23137a8d3a113fe6420207c3f9ea46442e1c75a01215eb2693bb7")
  7. add_patches("0.8.0", path.join(os.scriptdir(), "patches", "0.8.0", "clang_fix.patch"), "dacd893e90298763223b21b0054dad6d6a82c7c36ab0d3d0cc1984a342c01f9f")
  8. add_patches("0.8.0", path.join(os.scriptdir(), "patches", "0.8.0", "win32_zlib.patch"), "99d14ebf2f1d7b848ab5fc5b659826d50429e59810f13b25953fddfc8f4313b7")
  9. add_deps("cmake", "boost", "libzip")
  10. on_install("linux", function (package)
  11. local configs = {
  12. "-DBUILD_SHARED_LIBS=" .. (package:config("shared") and "ON" or "OFF"),
  13. "-DCMAKE_BUILD_TYPE=" .. (package:debug() and "Debug" or "Release")
  14. }
  15. import("package.tools.cmake").install(package, configs)
  16. end)
  17. on_test(function (package)
  18. assert(package:check_cxxsnippets({test = [[
  19. #include <iostream>
  20. #include <fmi4cpp/fmi4cpp.hpp>
  21. using namespace fmi4cpp;
  22. const double stop = 10.0;
  23. const double stepSize = 0.0001;
  24. void test(int argc, char** argv) {
  25. fmi2::fmu fmu("path/to/fmu.fmu");
  26. auto cs_fmu = fmu.as_cs_fmu();
  27. auto me_fmu = fmu.as_me_fmu();
  28. auto cs_md = cs_fmu->get_model_description(); //smart pointer to a cs_model_description instance
  29. std::cout << "model_identifier=" << cs_md->model_identifier << std::endl;
  30. auto me_md = me_fmu->get_model_description(); //smart pointer to a me_model_description instance
  31. std::cout << "model_identifier=" << me_md->model_identifier << std::endl;
  32. auto var = cs_md->get_variable_by_name("my_var").as_real();
  33. std::cout << "Name=" << var.name() << ", start=" << var.start().value_or(0) << std::endl;
  34. auto slave = cs_fmu->new_instance();
  35. slave->setup_experiment();
  36. slave->enter_initialization_mode();
  37. slave->exit_initialization_mode();
  38. double t;
  39. double value;
  40. auto vr = var.valueReference();
  41. while ( (t = slave->get_simulation_time()) <= stop) {
  42. if (!slave->step(stepSize)) {
  43. std::cerr << "Error! step() returned with status: " << to_string(slave->last_status()) << std::endl;
  44. break;
  45. }
  46. if (!slave->read_real(vr, value)) {
  47. std::cerr << "Error! step() returned with status: " << to_string(slave->last_status()) << std::endl;
  48. break;
  49. }
  50. std::cout << "t=" << t << ", " << var.name() << "=" << value << std::endl;
  51. }
  52. slave->terminate();
  53. }
  54. ]]}, {configs = {languages = "cxx17"}}))
  55. end)