xmake.lua 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. package("coin-or-ipopt")
  2. set_homepage("https://github.com/coin-or/Ipopt")
  3. set_description("Ipopt (Interior Point OPTimizer, pronounced eye-pea-Opt) is a software package for large-scale nonlinear optimization.")
  4. set_license("EGPL-2.0")
  5. add_urls("https://github.com/coin-or/Ipopt/archive/refs/tags/releases/$(version).tar.gz",
  6. "https://github.com/coin-or/Ipopt.git")
  7. add_versions("3.14.16", "cc8c217991240db7eb14189eee0dff88f20a89bac11958b48625fa512fe8d104")
  8. if is_plat("linux") then
  9. add_syslinks("pthread")
  10. end
  11. add_deps("gfortran", "openblas", "mumps", "coin-or-asl", "lapack", "openmp")
  12. if not is_plat("windows") then
  13. add_deps("autoconf", "automake", "libtool", "m4")
  14. end
  15. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  16. add_includedirs("include", "include/coin-or")
  17. on_install("linux", function (package)
  18. io.replace("configure", "ac_name=dsyev", "ac_name=LAPACKE_dsyev", {plain=true})
  19. io.replace("configure", "ac_name=DSYEV", "ac_name=LAPACKE_dsyev", {plain=true})
  20. io.replace("src/LinAlg/IpBlas.cpp", "IPOPT_BLAS_FUNC(s ## name,S ## NAME)", "IPOPT_BLAS_FUNC(s ## name ## _ ,S ## NAME ## _)", {plain=true})
  21. io.replace("src/LinAlg/IpBlas.cpp", "IPOPT_BLAS_FUNC(d ## name,D ## NAME)", "IPOPT_BLAS_FUNC(d ## name ## _,D ## NAME ## _)", {plain=true})
  22. io.replace("src/LinAlg/IpBlas.cpp", "IPOPT_BLAS_FUNC(idamax, IDAMAX)", "IPOPT_BLAS_FUNC(idamax_, IDAMAX_)", {plain=true})
  23. io.replace("src/LinAlg/IpLapack.cpp", "IPOPT_LAPACK_FUNC(s ## name,S ## NAME)", "IPOPT_LAPACK_FUNC(s ## name ## _,S ## NAME ## _)", {plain=true})
  24. io.replace("src/LinAlg/IpLapack.cpp", "IPOPT_LAPACK_FUNC(d ## name,D ## NAME)", "IPOPT_LAPACK_FUNC(d ## name ## _,D ## NAME ## _)", {plain=true})
  25. local fetch_info_mumps = package:dep("mumps"):fetch()
  26. local fetch_info_lapack = package:dep("lapack"):fetch()
  27. local configs = {}
  28. local lapack_flags = [[--with-lapack-lflags=-L]] .. tostring(fetch_info_lapack.linkdirs[1]) .. [[ ]]
  29. for _, link in ipairs(fetch_info_lapack.links) do
  30. lapack_flags = lapack_flags .. "-l" .. tostring(link) .. " "
  31. end
  32. lapack_flags = lapack_flags .. [[-lgfortran -lm -fopenmp]]
  33. table.insert(configs, lapack_flags)
  34. table.insert(configs, [[--with-mumps-cflags="-I]] .. fetch_info_mumps.sysincludedirs[1] .. [["]])
  35. local mumps_lflags = [[--with-mumps-lflags= "]]
  36. for _, link in ipairs(fetch_info_mumps.links) do
  37. mumps_lflags = mumps_lflags .. "-l" .. link .. " "
  38. end
  39. mumps_lflags = mumps_lflags .. [[-lesmumps -lscotch -lscotcherr -lscotcherrexit -lscotchmetisv5 -lscotchmetisv3 -lpthread"]]
  40. table.insert(configs, mumps_lflags)
  41. table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
  42. table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
  43. if package:is_debug() then
  44. table.insert(configs, "--enable-debug")
  45. end
  46. import("package.tools.autoconf").install(package, configs, {packagedeps = {"mumps", "scotch", "lapack"}})
  47. end)
  48. on_test(function (package)
  49. assert(package:check_cxxsnippets({test = [[
  50. #include "IpIpoptApplication.hpp"
  51. #include "IpSolveStatistics.hpp"
  52. #include "IpBlas.hpp"
  53. using namespace Ipopt;
  54. void test() {
  55. IpBlasDot(0, nullptr, 0, nullptr, 0);
  56. SmartPtr<IpoptApplication> app = new IpoptApplication;
  57. ApplicationReturnStatus status;
  58. status = app->Initialize();
  59. }
  60. ]]}, {configs = {languages = "c++11"}, includes = "IpIpoptApplication.hpp"}))
  61. end)