xmake.lua 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. package("glpk")
  2. set_homepage("https://www.gnu.org/software/glpk/")
  3. set_description("The GLPK (GNU Linear Programming Kit) package is intended for solving large-scale linear programming (LP), mixed integer programming (MIP), and other related problems.")
  4. set_license("GPL-3.0")
  5. set_urls("https://ftp.gnu.org/gnu/glpk/glpk-$(version).tar.gz")
  6. add_versions("5.0", "4a1013eebb50f728fc601bdd833b0b2870333c3b3e5a816eeba921d95bec6f15")
  7. add_configs("dl", {description = "Eenable shared library support", default = nil, type = "string", values = {"ltdl", "dlfcn"}})
  8. add_configs("gmp", {description = "Enable gmp support", default = false, type = "boolean"})
  9. add_configs("mysql", {description = "enable MathProg MySQL support", default = false, type = "boolean", readonly = true})
  10. add_configs("odbc", {description = "enable MathProg ODBC support", default = false, type = "boolean", readonly = true})
  11. if is_plat("wasm") then
  12. add_configs("shared", {description = "Build shared library.", default = false, type = "boolean", readonly = true})
  13. end
  14. if is_plat("linux") then
  15. add_extsources("apt::libglpk-dev")
  16. end
  17. add_deps("zlib")
  18. on_load(function (package)
  19. if package:config("gmp") then
  20. package:add("deps", "gmp")
  21. end
  22. if package:config("mysql") then
  23. package:add("deps", "mysql")
  24. end
  25. local dl = package:config("dl")
  26. if dl == "ltdl" then
  27. package:add("deps", "libtool", {kind = "library"})
  28. elseif dl == "dlfcn" then
  29. if package:is_plat("linux", "bsd") then
  30. package:add("syslinks", "dl")
  31. end
  32. -- src/env/dlsup.c will use LoadLibrary/GetProcAddress/FreeLibrary
  33. -- if package:is_plat("windows") then
  34. -- package:add("deps", "dlfcn-win32")
  35. -- end
  36. end
  37. end)
  38. on_install(function (package)
  39. io.replace("src/minisat/minisat.h", "typedef int bool;", "#if __STDC_VERSION__ < 202311L\ntypedef int bool;\n#endif", {plain = true})
  40. if package:is_plat("windows") and package:config("shared") then
  41. local def = "glpk.def"
  42. local version = package:version()
  43. local arch_dir = package:is_arch64() and "w64" or "w32"
  44. local basename = format("%s/glpk_%d_%d.def", arch_dir, version:major(), version:minor())
  45. os.vcp(basename, def)
  46. -- glp_netgen_prob is not defined, but should be disabled
  47. -- see: https://www.mail-archive.com/[email protected]/msg01020.html
  48. io.replace(def, "glp_netgen_prob\n", "", {plain = true})
  49. end
  50. local configs = {
  51. dl = package:config("dl"),
  52. gmp = package:config("gmp"),
  53. mysql = package:config("mysql"),
  54. odbc = package:config("odbc"),
  55. }
  56. os.cp(path.join(package:scriptdir(), "port", "xmake.lua"), "xmake.lua")
  57. import("package.tools.xmake").install(package, configs)
  58. end)
  59. on_install("macosx", "linux", function (package)
  60. io.replace("src/minisat/minisat.h", "typedef int bool;", "#if __STDC_VERSION__ < 202311L\ntypedef int bool;\n#endif", {plain = true})
  61. local configs = {}
  62. table.insert(configs, "--enable-shared=" .. (package:config("shared") and "yes" or "no"))
  63. table.insert(configs, "--enable-static=" .. (package:config("shared") and "no" or "yes"))
  64. table.insert(configs, "--enable-mysql=" .. (package:config("mysql") and "yes" or "no"))
  65. table.insert(configs, "--enable-odbc=" .. (package:config("odbc") and "yes" or "no"))
  66. local dl = package:config("dl")
  67. if dl then
  68. table.insert(configs, "--enable-dl=" .. dl)
  69. else
  70. table.insert(configs, "--disable-dl")
  71. end
  72. if package:config("gmp") then
  73. table.insert(configs, "--with-gmp")
  74. else
  75. table.insert(configs, "--without-gmp")
  76. end
  77. import("package.tools.autoconf").install(package, configs)
  78. end)
  79. on_test(function (package)
  80. assert(package:check_cxxsnippets({test = [[
  81. #include <glpk.h>
  82. int main() {
  83. glp_prob* prob = glp_create_prob();
  84. if (prob) {
  85. glp_delete_prob(prob);
  86. }
  87. return 0;
  88. }
  89. ]]}))
  90. end)